summaryrefslogtreecommitdiff
path: root/gnu/services/configuration.scm
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-08-24 14:40:38 +0200
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-08-24 22:34:45 -0400
commit1c803e63f9560b93afeec9f7342f4413ff3cec46 (patch)
tree0482d40b846cdd02303d2cb89b2f1ed5150ce0ae /gnu/services/configuration.scm
parent31339f5f5ffd80f3fca9dbe49990fa3be4234bb5 (diff)
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>
Diffstat (limited to 'gnu/services/configuration.scm')
-rw-r--r--gnu/services/configuration.scm15
1 files changed, 10 insertions, 5 deletions
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))