[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
18/21: home-services: configuration: Add generic-serialize-alist.
From: |
guix-commits |
Subject: |
18/21: home-services: configuration: Add generic-serialize-alist. |
Date: |
Thu, 9 Sep 2021 13:33:38 -0400 (EDT) |
wigust pushed a commit to branch wip-guix-home
in repository guix.
commit 3087a5cfa05b682564c78a0f79a0d49ef6f9b31a
Author: Andrew Tropin <andrew@trop.in>
AuthorDate: Tue Aug 31 15:40:07 2021 +0300
home-services: configuration: Add generic-serialize-alist.
* gnu/home-services/configuration.scm (generic-serialize-alist,
generic-serialize-alist-entry): New functions.
Signed-off-by: Oleg Pykhalov <go.wigust@gmail.com>
---
gnu/home-services/configuration.scm | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/gnu/home-services/configuration.scm
b/gnu/home-services/configuration.scm
index 039877b..3698006 100644
--- a/gnu/home-services/configuration.scm
+++ b/gnu/home-services/configuration.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021 Andrew Tropin <andrew@trop.in>
+;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -20,6 +21,8 @@
#:use-module (gnu services configuration)
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
+ #:use-module (ice-9 curried-definitions)
+ #:use-module (ice-9 match)
#:export (filter-configuration-fields
@@ -31,7 +34,9 @@
string-or-gexp?
serialize-string-or-gexp
text-config?
- serialize-text-config))
+ serialize-text-config
+ generic-serialize-alist-entry
+ generic-serialize-alist))
(define* (filter-configuration-fields configuration-fields fields
#:optional negate?)
@@ -79,3 +84,24 @@ the list result in @code{#t} when applying PRED? on them."
(and (list? config) (every string-or-gexp? config)))
(define (serialize-text-config field-name val)
#~(string-append #$@(interpose val "\n" 'suffix)))
+
+(define ((generic-serialize-alist-entry serialize-field) entry)
+ "Apply the SERIALIZE-FIELD procedure on the field and value of ENTRY."
+ (match entry
+ ((field . val) (serialize-field field val))))
+
+(define (generic-serialize-alist combine serialize-field fields)
+ "Generate a configuration from an association list FIELDS.
+
+SERIALIZE-FIELD is a procedure that takes two arguments, it will be
+applied on the fields and values of FIELDS using the
+@code{generic-serialize-alist-entry} procedure.
+
+COMBINE is a procedure that takes one or more arguments and combines
+all the alist entries into one value, @code{string-append} or
+@code{append} are usually good candidates for this.
+
+See the @code{serialize-alist} procedure in `@code{(gnu home-services
+version-control}' for an example usage.)}"
+ (apply combine
+ (map (generic-serialize-alist-entry serialize-field) fields)))
- 17/21: scripts: home: Add import subcommand., (continued)
- 17/21: scripts: home: Add import subcommand., guix-commits, 2021/09/09
- 07/21: home-services: Add helper functions for service configurations., guix-commits, 2021/09/09
- 16/21: scripts: Add 'guix home'., guix-commits, 2021/09/09
- 08/21: home-services: Add shells., guix-commits, 2021/09/09
- 19/21: home-services: run-on-change: Handle first generation case., guix-commits, 2021/09/09
- 13/21: home-services: activation: Add support for multiline env vars., guix-commits, 2021/09/09
- 05/21: home-services: Add symlink-manager., guix-commits, 2021/09/09
- 09/21: home-services: Add xdg., guix-commits, 2021/09/09
- 11/21: home-services: Add utils module., guix-commits, 2021/09/09
- 12/21: home-services: symlink-manager: Properly handle 1st generation case., guix-commits, 2021/09/09
- 18/21: home-services: configuration: Add generic-serialize-alist.,
guix-commits <=
- 10/21: home: Add home-environment., guix-commits, 2021/09/09
- 15/21: gnu: local.mk: Tabify., guix-commits, 2021/09/09
- 03/21: home-services: Add home-provenance-service-type., guix-commits, 2021/09/09
- 20/21: doc: Add Guix Home documentation., guix-commits, 2021/09/09
- 21/21: home-services: Add Shepherd., guix-commits, 2021/09/09