[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: services: configuration: Add a 'maybe-value-set?'
From: |
guix-commits |
Subject: |
branch master updated: services: configuration: Add a 'maybe-value-set?' procedure. |
Date: |
Wed, 24 Aug 2022 22:35:32 -0400 |
This is an automated email from the git hooks/post-receive script.
apteryx pushed a commit to branch master
in repository guix.
The following commit(s) were added to refs/heads/master by this push:
new 1c803e63f9 services: configuration: Add a 'maybe-value-set?' procedure.
1c803e63f9 is described below
commit 1c803e63f9560b93afeec9f7342f4413ff3cec46
Author: Maxim Cournoyer <maxim.cournoyer@gmail.com>
AuthorDate: Wed Aug 24 14:40:38 2022 +0200
services: configuration: Add a 'maybe-value-set?' procedure.
* gnu/services/configuration.scm (maybe-value-set?): New procedure.
* doc/guix.texi (Complex Configurations): Document it. Remove comment
showing
usage of 'maybe-string' with a default value, which doesn't make sense.
Co-authored-by: Attila Lendvai <attila@lendvai.name>
---
doc/guix.texi | 7 ++++++-
gnu/services/configuration.scm | 15 ++++++++++-----
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index 023b48ae35..c8f18a1482 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -39003,7 +39003,7 @@ to be a string, or left unspecified.
(name
;; If set to a string, the `serialize-string' procedure will be used
;; to serialize the string. Otherwise this field is not serialized.
- maybe-string ; equivalent to (maybe-string *unspecified*)
+ maybe-string
"The name of this module."))
@end lisp
@@ -39034,6 +39034,11 @@ whether its value is set or not.
@end lisp
@end deffn
+@deffn (Scheme Procedure) maybe-value-set? @var{value}
+Predicate to check whether a user explicitly specified the value of a
+maybe field.
+@end deffn
+
@deffn {Scheme Procedure} serialize-configuration @var{configuration} @
@var{fields}
Return a G-expression that contains the values corresponding to the
diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm
index 3007e8de35..e2c4fe9998 100644
--- a/gnu/services/configuration.scm
+++ b/gnu/services/configuration.scm
@@ -57,6 +57,7 @@
serialize-configuration
define-maybe
define-maybe/no-serialization
+ maybe-value-set?
generate-documentation
configuration->documentation
empty-serializer
@@ -142,7 +143,8 @@ does not have a default value" field kind)))
(id #'stem #'serialize-maybe- #'stem))))
#`(begin
(define (maybe-stem? val)
- (or (eq? val 'unset) (stem? val)))
+ (or (not (maybe-value-set? val))
+ (stem? val)))
#,@(if serialize?
(list #'(define (serialize-maybe-stem field-name val)
(if (stem? val)
@@ -260,11 +262,10 @@ does not have a default value" field kind)))
(default-value-thunk
(lambda ()
(display '#,(id #'stem #'% #'stem))
- (if (eq? (syntax->datum field-default)
- 'unset)
+ (if (maybe-value-set? (syntax->datum field-default))
+ field-default
(configuration-missing-default-value
- '#,(id #'stem #'% #'stem) 'field)
- field-default)))
+ '#,(id #'stem #'% #'stem) 'field))))
(documentation doc))
...))))))))
@@ -300,6 +301,10 @@ does not have a default value" field kind)))
(define (empty-serializer field-name val) "")
(define serialize-package empty-serializer)
+(define (maybe-value-set? value)
+ "Predicate to check whether a 'maybe' value was explicitly provided."
+ (not (eq? 'unset value)))
+
;; A little helper to make it easier to document all those fields.
(define (generate-documentation documentation documentation-name)
(define (str x) (object->string x))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: services: configuration: Add a 'maybe-value-set?' procedure.,
guix-commits <=