1
Fork 0
mirror of https://https.git.savannah.gnu.org/git/guix.git/ synced 2025-07-15 11:30:44 +02:00

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>
This commit is contained in:
Maxim Cournoyer 2022-08-24 14:40:38 +02:00
parent 31339f5f5f
commit 1c803e63f9
No known key found for this signature in database
GPG key ID: 1260E46482E63562
2 changed files with 16 additions and 6 deletions

View file

@ -39003,7 +39003,7 @@ to be a string, or left unspecified.
(name (name
;; If set to a string, the `serialize-string' procedure will be used ;; If set to a string, the `serialize-string' procedure will be used
;; to serialize the string. Otherwise this field is not serialized. ;; to serialize the string. Otherwise this field is not serialized.
maybe-string ; equivalent to (maybe-string *unspecified*) maybe-string
"The name of this module.")) "The name of this module."))
@end lisp @end lisp
@ -39034,6 +39034,11 @@ whether its value is set or not.
@end lisp @end lisp
@end deffn @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} @ @deffn {Scheme Procedure} serialize-configuration @var{configuration} @
@var{fields} @var{fields}
Return a G-expression that contains the values corresponding to the Return a G-expression that contains the values corresponding to the

View file

@ -57,6 +57,7 @@
serialize-configuration serialize-configuration
define-maybe define-maybe
define-maybe/no-serialization define-maybe/no-serialization
maybe-value-set?
generate-documentation generate-documentation
configuration->documentation configuration->documentation
empty-serializer empty-serializer
@ -142,7 +143,8 @@ does not have a default value" field kind)))
(id #'stem #'serialize-maybe- #'stem)))) (id #'stem #'serialize-maybe- #'stem))))
#`(begin #`(begin
(define (maybe-stem? val) (define (maybe-stem? val)
(or (eq? val 'unset) (stem? val))) (or (not (maybe-value-set? val))
(stem? val)))
#,@(if serialize? #,@(if serialize?
(list #'(define (serialize-maybe-stem field-name val) (list #'(define (serialize-maybe-stem field-name val)
(if (stem? val) (if (stem? val)
@ -260,11 +262,10 @@ does not have a default value" field kind)))
(default-value-thunk (default-value-thunk
(lambda () (lambda ()
(display '#,(id #'stem #'% #'stem)) (display '#,(id #'stem #'% #'stem))
(if (eq? (syntax->datum field-default) (if (maybe-value-set? (syntax->datum field-default))
'unset) field-default
(configuration-missing-default-value (configuration-missing-default-value
'#,(id #'stem #'% #'stem) 'field) '#,(id #'stem #'% #'stem) 'field))))
field-default)))
(documentation doc)) (documentation doc))
...)))))))) ...))))))))
@ -300,6 +301,10 @@ does not have a default value" field kind)))
(define (empty-serializer field-name val) "") (define (empty-serializer field-name val) "")
(define serialize-package empty-serializer) (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. ;; A little helper to make it easier to document all those fields.
(define (generate-documentation documentation documentation-name) (define (generate-documentation documentation documentation-name)
(define (str x) (object->string x)) (define (str x) (object->string x))