guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/02: services: configuration: Add %unset-value exported variable.


From: guix-commits
Subject: 01/02: services: configuration: Add %unset-value exported variable.
Date: Wed, 24 Aug 2022 23:28:47 -0400 (EDT)

apteryx pushed a commit to branch master
in repository guix.

commit 147f8f19f844b8acc602ddcb49b4a1c0b9226c4d
Author: Attila Lendvai <attila@lendvai.name>
AuthorDate: Wed Aug 24 14:40:39 2022 +0200

    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>
---
 gnu/services/configuration.scm | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm
index e2c4fe9998..a9426066b9 100644
--- a/gnu/services/configuration.scm
+++ b/gnu/services/configuration.scm
@@ -57,6 +57,7 @@
             serialize-configuration
             define-maybe
             define-maybe/no-serialization
+            %unset-value
             maybe-value-set?
             generate-documentation
             configuration->documentation
@@ -172,10 +173,10 @@ does not have a default value" field kind)))
      (values #'(field-type def)))
     ((field-type)
      (identifier? #'field-type)
-     (values #'(field-type 'unset)))
+     (values #'(field-type %unset-value)))
     (field-type
      (identifier? #'field-type)
-     (values #'(field-type 'unset)))))
+     (values #'(field-type %unset-value)))))
 
 (define (define-configuration-helper serialize? serializer-prefix syn)
   (syntax-case syn ()
@@ -301,9 +302,18 @@ does not have a default value" field kind)))
 (define (empty-serializer field-name val) "")
 (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)
   "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.
 (define (generate-documentation documentation documentation-name)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]