mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-11 21:59:08 -05:00
services: configuration: Add %unset-value exported variable.
* gnu/services/configuration.scm (%unset-value): New variable. (normalize-field-type+def): Use it. (maybe-value-unset?): Use it. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
This commit is contained in:
parent
0e11067d53
commit
147f8f19f8
1 changed files with 13 additions and 3 deletions
|
@ -57,6 +57,7 @@ (define-module (gnu services configuration)
|
||||||
serialize-configuration
|
serialize-configuration
|
||||||
define-maybe
|
define-maybe
|
||||||
define-maybe/no-serialization
|
define-maybe/no-serialization
|
||||||
|
%unset-value
|
||||||
maybe-value-set?
|
maybe-value-set?
|
||||||
generate-documentation
|
generate-documentation
|
||||||
configuration->documentation
|
configuration->documentation
|
||||||
|
@ -172,10 +173,10 @@ (define (normalize-field-type+def s)
|
||||||
(values #'(field-type def)))
|
(values #'(field-type def)))
|
||||||
((field-type)
|
((field-type)
|
||||||
(identifier? #'field-type)
|
(identifier? #'field-type)
|
||||||
(values #'(field-type 'unset)))
|
(values #'(field-type %unset-value)))
|
||||||
(field-type
|
(field-type
|
||||||
(identifier? #'field-type)
|
(identifier? #'field-type)
|
||||||
(values #'(field-type 'unset)))))
|
(values #'(field-type %unset-value)))))
|
||||||
|
|
||||||
(define (define-configuration-helper serialize? serializer-prefix syn)
|
(define (define-configuration-helper serialize? serializer-prefix syn)
|
||||||
(syntax-case syn ()
|
(syntax-case syn ()
|
||||||
|
@ -301,9 +302,18 @@ (define-configuration stem (field field-type+def
|
||||||
(define (empty-serializer field-name val) "")
|
(define (empty-serializer field-name val) "")
|
||||||
(define serialize-package empty-serializer)
|
(define serialize-package empty-serializer)
|
||||||
|
|
||||||
|
;; Ideally this should be an implementation detail, but we export it
|
||||||
|
;; to provide a simpler API that enables unsetting a configuration
|
||||||
|
;; field that has a maybe type, but also a default value.
|
||||||
|
;;
|
||||||
|
;; An example use-case would be something like a network application
|
||||||
|
;; that uses a default port, but the field can explicitly be unset to
|
||||||
|
;; request a random port at startup.
|
||||||
|
(define %unset-value 'unset)
|
||||||
|
|
||||||
(define (maybe-value-set? value)
|
(define (maybe-value-set? value)
|
||||||
"Predicate to check whether a 'maybe' value was explicitly provided."
|
"Predicate to check whether a 'maybe' value was explicitly provided."
|
||||||
(not (eq? 'unset value)))
|
(not (eq? %unset-value 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)
|
||||||
|
|
Loading…
Reference in a new issue