From: Andrew Tropin <andrew@trop.in>
To: Oleg Pykhalov <go.wigust@gmail.com>
Cc: 50208@debbugs.gnu.org
Subject: [bug#50208] [PATCH 2/5] home-services: Add helper functions for service configurations.
Date: Fri, 27 Aug 2021 09:58:56 +0300 [thread overview]
Message-ID: <87v93re5lb.fsf@trop.in> (raw)
In-Reply-To: <871r6ffklu.fsf@trop.in>
[-- Attachment #1: Type: text/plain, Size: 3129 bytes --]
* 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 \
--
2.33.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 853 bytes --]
next prev parent reply other threads:[~2021-08-27 7:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-26 6:39 [bug#50208] [PATCH] home-services: Add symlink-manager Andrew Tropin
2021-08-26 10:58 ` Oleg Pykhalov
2021-08-27 4:31 ` Andrew Tropin
2021-08-27 6:49 ` [bug#50208] [PATCH 0/5] Add home-environment and related services Andrew Tropin
2021-08-27 6:52 ` [bug#50208] [PATCH 1/5] home-services: Add fontutils Andrew Tropin
2021-08-27 6:58 ` Andrew Tropin [this message]
2021-08-27 7:03 ` [bug#50208] [PATCH 3/5] home-services: Add shells Andrew Tropin
2021-08-27 15:25 ` Andrew Tropin
2021-08-27 7:06 ` [bug#50208] [PATCH 4/5] home-services: Add xdg Andrew Tropin
2021-08-27 7:07 ` [bug#50208] [PATCH 5/5] home: Add home-environment Andrew Tropin
2021-08-28 10:44 ` Xinglu Chen
2021-08-30 9:10 ` Andrew Tropin
2021-08-27 15:28 ` [bug#50208] [PATCH 0/5] Add home-environment and related services Andrew Tropin
2021-08-27 19:15 ` bug#50208: " Oleg Pykhalov
2021-08-30 9:40 ` [bug#50208] [PATCH 0/4] Fixes and improvements for home-services Andrew Tropin
2021-08-30 10:28 ` [bug#50208] [PATCH v2 0/5] " Andrew Tropin
2021-08-30 23:19 ` [bug#50208] [PATCH] home-services: Add symlink-manager Oleg Pykhalov
2021-08-31 7:03 ` Andrew Tropin
2021-08-27 8:55 ` Jelle Licht
2021-08-27 15:24 ` Andrew Tropin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v93re5lb.fsf@trop.in \
--to=andrew@trop.in \
--cc=50208@debbugs.gnu.org \
--cc=go.wigust@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).