From patchwork Fri Aug 27 06:58:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Tropin X-Patchwork-Id: 32330 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8968727BBE3; Fri, 27 Aug 2021 08:04:01 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 1952827BBE1 for ; Fri, 27 Aug 2021 08:04:01 +0100 (BST) Received: from localhost ([::1]:48238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJVuC-00045l-1r for patchwork@mira.cbaines.net; Fri, 27 Aug 2021 03:04:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJVqN-0000uV-Gn for guix-patches@gnu.org; Fri, 27 Aug 2021 03:00:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:39610) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mJVqN-00073j-69 for guix-patches@gnu.org; Fri, 27 Aug 2021 03:00:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mJVqN-0004wz-4u for guix-patches@gnu.org; Fri, 27 Aug 2021 03:00:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50208] [PATCH 2/5] home-services: Add helper functions for service configurations. Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 27 Aug 2021 07:00:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50208 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Oleg Pykhalov Cc: 50208@debbugs.gnu.org Received: via spool by 50208-submit@debbugs.gnu.org id=B50208.163004754818916 (code B ref 50208); Fri, 27 Aug 2021 07:00:03 +0000 Received: (at 50208) by debbugs.gnu.org; 27 Aug 2021 06:59:08 +0000 Received: from localhost ([127.0.0.1]:51152 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJVpU-0004v1-Ge for submit@debbugs.gnu.org; Fri, 27 Aug 2021 02:59:08 -0400 Received: from mail-lf1-f54.google.com ([209.85.167.54]:37878) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJVpS-0004uU-VA for 50208@debbugs.gnu.org; Fri, 27 Aug 2021 02:59:07 -0400 Received: by mail-lf1-f54.google.com with SMTP id k5so12373645lfu.4 for <50208@debbugs.gnu.org>; Thu, 26 Aug 2021 23:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=CNoa8R/wqF/C7RwVlyD3UBuiSq8rb3we2L7ipIXqM2Q=; b=YljrfKclsA1JJ31Q6qbcI8/0D4FuJNW3R3H65JgQq/YIHf3BSjtsiKPF9UaoYOFToP j7lN0kNh1ieXnZ/KgBJ3rColtKw6RMbjIouC+ZAAnGTR4ltOy66fZ2SVW/nGgfmB5Kvv u2VvXW6gOl0GSmlNC7MUSnthSfk6gBzjYyfSwNu0gkAXzyqlrvAFXByxseoHK4kcv7RU syAKEYa4CkePXfcTneWKD2eZmABv5v4HuU2D7I7JsqnGE9CkRGSCW6qSm/H9ssuZNrWz mu2en/gPYKtkDnbeOW3iW2Jrj9prrfCqPz4Meosrgp2d2rlW7MLYDaiy2fgns8x7AvTa X/eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=CNoa8R/wqF/C7RwVlyD3UBuiSq8rb3we2L7ipIXqM2Q=; b=U9Hm0uW7vWq+/cI+8uD4Q+JXyUR5/cwousZsvFc1Z28afXXFLGcCDzkHzub3Bgt9f0 gx6uvEFV48yzhS3YHSBl8iEWWkVHYdnSbn4NGwJHREB5ITyr5a2U2QnMsBViYUyDFx5d I+tLjQrbGXDLg3CYErYCP3gAk0K46+kYfEtCzu3jQ5t2b1UVAUR9OEngTxqrRBYqRzTw gteAC5h7Xq+Qch0Sh81p3VnW2f8Lola28EQXYV/cxdZzLxQpchldVJblacTUzU95BkVT cLFVeBjpgVpx5nsN+ZPj2DDCNfTGO1BA8SahJio2E9aYwFWCQRE9bJOCtJxKeTNxBDmQ QVTA== X-Gm-Message-State: AOAM5336w7K2qHvp9zcWyXej4EX9Xc4exbtfxoVj6PLvbYwVzv874UER KayPOgYWUaUbM1uIqo8jUN0ckg== X-Google-Smtp-Source: ABdhPJwK3N0R1yX013BXDalL4fJB6nFyhx+oPjn+ZZAeMdJwQ04cwxYqeU++f63jSAp3tEVkcLPWAQ== X-Received: by 2002:a05:6512:12c8:: with SMTP id p8mr2057763lfg.208.1630047540587; Thu, 26 Aug 2021 23:59:00 -0700 (PDT) Received: from localhost (109-252-93-92.nat.spd-mgts.ru. [109.252.93.92]) by smtp.gmail.com with ESMTPSA id z4sm508790lfu.164.2021.08.26.23.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 23:58:59 -0700 (PDT) From: Andrew Tropin In-Reply-To: <871r6ffklu.fsf@trop.in> References: <87bl5kbsk8.fsf@trop.in> <87r1eg8obm.fsf@gmail.com> <871r6ffklu.fsf@trop.in> Date: Fri, 27 Aug 2021 09:58:56 +0300 Message-ID: <87v93re5lb.fsf@trop.in> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/home-services/configuration.scm (helper functions): New variables. * gnu/local.mk (GNU_SYSTEM_MODULES): Add home-services/configuration.scm. --- gnu/home-services/configuration.scm | 63 +++++++++++++++++++++++++++++ gnu/local.mk | 1 + 2 files changed, 64 insertions(+) create mode 100644 gnu/home-services/configuration.scm diff --git a/gnu/home-services/configuration.scm b/gnu/home-services/configuration.scm new file mode 100644 index 0000000000..b7487fc49f --- /dev/null +++ b/gnu/home-services/configuration.scm @@ -0,0 +1,63 @@ +(define-module (gnu home-services configuration) + #:use-module (gnu services configuration) + #:use-module (guix gexp) + #:use-module (srfi srfi-1) + + #:export (filter-configuration-fields + + interpose + list-of + + list-of-strings? + alist? + string-or-gexp? + serialize-string-or-gexp + text-config? + serialize-text-config)) + +(define* (filter-configuration-fields configuration-fields fields + #:optional negate?) + "Retrieve the fields listed in FIELDS from CONFIGURATION-FIELDS. +If NEGATE? is @code{#t}, retrieve all fields except FIELDS." + (filter (lambda (field) + (let ((member? (member (configuration-field-name field) fields))) + (if (not negate?) member? (not member?)))) + configuration-fields)) + + +(define* (interpose ls #:optional (delimiter "\n") (grammar 'infix)) + "Same as @code{string-join}, but without join and string, returns an +DELIMITER interposed LS. Support 'infix and 'suffix GRAMMAR values." + (when (not (member grammar '(infix suffix))) + (raise + (formatted-message + (G_ "The GRAMMAR value must be 'infix or 'suffix, but ~a provided.") + grammar))) + (fold-right (lambda (e acc) + (cons e + (if (and (null? acc) (eq? grammar 'infix)) + acc + (cons delimiter acc)))) + '() ls)) + +(define (list-of pred?) + "Return a procedure that takes a list and check if all the elements of +the list result in @code{#t} when applying PRED? on them." + (lambda (x) + (if (list? x) + (every pred? x) + #f))) + + +(define list-of-strings? + (list-of string?)) + +(define alist? list?) + +(define (string-or-gexp? sg) (or (string? sg) (gexp? sg))) +(define (serialize-string-or-gexp field-name val) "") + +(define (text-config? config) + (and (list? config) (every string-or-gexp? config))) +(define (serialize-text-config field-name val) + #~(string-append #$@(interpose val "\n" 'suffix))) diff --git a/gnu/local.mk b/gnu/local.mk index e25ff3db53..e24da4716f 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -75,6 +75,7 @@ GNU_SYSTEM_MODULES = \ %D%/home-services.scm \ %D%/home-services/symlink-manager.scm \ %D%/home-services/fontutils.scm \ + %D%/home-services/configuration.scm \ %D%/image.scm \ %D%/packages.scm \ %D%/packages/abduco.scm \