services: Use the new maybe/unset API.

* gnu/home/services/ssh.scm (serialize-address-family): Use the public API of
the maybe infrastructure.
* gnu/services/file-sharing.scm (serialize-maybe-string): Use maybe-value.
(serialize-maybe-file-object): Use maybe-value-set?.
* gnu/services/getmail.scm (getmail-retriever-configuration): Don't use
internals in unset field declarations.
(getmail-destination-configuration): Ditto.
* gnu/services/messaging.scm (raw-content?): Use maybe-value-set?.
(prosody-configuration): Use %unset-value.
* gnu/services/telephony.scm (jami-shepherd-services): Use maybe-value-set?.
(archive-name->username): Use maybe-value-set?.
* tests/services/configuration.scm ("maybe type, no default"): Use
%unset-value.

Modified-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
This commit is contained in:
Attila Lendvai 2022-08-24 14:40:41 +02:00 committed by Maxim Cournoyer
parent cc32cd41f7
commit ee08277a70
No known key found for this signature in database
GPG key ID: 1260E46482E63562
8 changed files with 30 additions and 25 deletions

View file

@ -69,17 +69,19 @@ (define (serialize-string field value)
" " value "\n")) " " value "\n"))
(define (address-family? obj) (define (address-family? obj)
(memv obj (list 'unset AF_INET AF_INET6))) (memv obj (list AF_INET AF_INET6)))
(define-maybe address-family)
(define (serialize-address-family field family) (define (serialize-address-family field family)
(if (eq? 'unset family) (if (maybe-value-set? family)
""
(string-append " " (serialize-field-name field) " " (string-append " " (serialize-field-name field) " "
(cond ((= family AF_INET) "inet") (cond ((= family AF_INET) "inet")
((= family AF_INET6) "inet6") ((= family AF_INET6) "inet6")
;; The 'else' branch is unreachable. ;; The 'else' branch is unreachable.
(else (raise (condition (&error))))) (else (raise (condition (&error)))))
"\n"))) "\n")
""))
(define (natural-number? obj) (define (natural-number? obj)
(and (integer? obj) (exact? obj) (> obj 0))) (and (integer? obj) (exact? obj) (> obj 0)))
@ -115,7 +117,7 @@ (define-configuration openssh-host
maybe-string maybe-string
"Host name---e.g., @code{\"foo.example.org\"} or @code{\"192.168.1.2\"}.") "Host name---e.g., @code{\"foo.example.org\"} or @code{\"192.168.1.2\"}.")
(address-family (address-family
address-family maybe-address-family
"Address family to use when connecting to this host: one of "Address family to use when connecting to this host: one of
@code{AF_INET} (for IPv4 only), @code{AF_INET6} (for IPv6 only). @code{AF_INET} (for IPv4 only), @code{AF_INET6} (for IPv6 only).
Additionally, the field can be left unset to allow any address family.") Additionally, the field can be left unset to allow any address family.")

View file

@ -114,10 +114,7 @@ (define-maybe string)
;; name-value pair for the JSON builder. ;; name-value pair for the JSON builder.
(set! serialize-maybe-string (set! serialize-maybe-string
(lambda (field-name val) (lambda (field-name val)
(serialize-string field-name (serialize-string field-name (maybe-value val ""))))
(if (eq? val 'unset)
""
val))))
(define (string-list? val) (define (string-list? val)
(and (list? val) (and (list? val)
@ -180,9 +177,9 @@ (define (serialize-file-object field-name val)
(define-maybe file-object) (define-maybe file-object)
(set! serialize-maybe-file-object (set! serialize-maybe-file-object
(lambda (field-name val) (lambda (field-name val)
(if (eq? val 'unset) (if (maybe-value-set? val)
(serialize-string field-name "") (serialize-file-object field-name val)
(serialize-file-object field-name val)))) (serialize-string field-name ""))))
(define (file-object-list? val) (define (file-object-list? val)
(and (list? val) (and (list? val)

View file

@ -111,10 +111,10 @@ (define-configuration getmail-retriever-configuration
"The type of mail retriever to use. Valid values include "The type of mail retriever to use. Valid values include
@samp{passwd} and @samp{static}.") @samp{passwd} and @samp{static}.")
(server (server
(string 'unset) string
"Name or IP address of the server to retrieve mail from.") "Name or IP address of the server to retrieve mail from.")
(username (username
(string 'unset) string
"Username to login to the mail server with.") "Username to login to the mail server with.")
(port (port
(non-negative-integer #f) (non-negative-integer #f)
@ -143,7 +143,7 @@ (define (serialize-getmail-destination-configuration field-name val)
(define-configuration getmail-destination-configuration (define-configuration getmail-destination-configuration
(type (type
(string 'unset) string
"The type of mail destination. Valid values include @samp{Maildir}, "The type of mail destination. Valid values include @samp{Maildir},
@samp{Mboxrd} and @samp{MDA_external}.") @samp{Mboxrd} and @samp{MDA_external}.")
(path (path

View file

@ -39,6 +39,7 @@ (define-module (gnu services kerberos)
;; TODO Use %unset-value and the define-maybe infrastructure.
(define unset-field (list 'unset-field)) (define unset-field (list 'unset-field))
(define (predicate/unset pred) (define (predicate/unset pred)

View file

@ -90,6 +90,11 @@ (define (make-pred arg)
((new-def ...) ((new-def ...)
(map (lambda (def target) (map (lambda (def target)
(if (eq? 'common (syntax->datum target)) (if (eq? 'common (syntax->datum target))
;; TODO Use the %unset-value variable, or
;; even better just simplify this so that it
;; doesn't interfere with
;; define-configuration and define-maybe
;; internals.
#''unset def)) #''unset def))
#'(def ...) #'(target ...))) #'(def ...) #'(target ...)))
((new-doc ...) ((new-doc ...)
@ -200,7 +205,7 @@ (define (serialize-file-object-list field-name val)
(define-maybe file-object-list) (define-maybe file-object-list)
(define (raw-content? val) (define (raw-content? val)
(not (eq? val 'unset))) (maybe-value-set? val))
(define (serialize-raw-content field-name val) (define (serialize-raw-content field-name val)
val) val)
(define-maybe raw-content) (define-maybe raw-content)
@ -474,12 +479,12 @@ (define-all-configurations prosody-configuration
global) global)
(http-max-content-size (http-max-content-size
(maybe-non-negative-integer 'unset) (maybe-non-negative-integer %unset-value)
"Maximum allowed size of the HTTP body (in bytes)." "Maximum allowed size of the HTTP body (in bytes)."
common) common)
(http-external-url (http-external-url
(maybe-string 'unset) (maybe-string %unset-value)
"Some modules expose their own URL in various ways. This URL is built "Some modules expose their own URL in various ways. This URL is built
from the protocol, host and port used. If Prosody sits behind a proxy, the from the protocol, host and port used. If Prosody sits behind a proxy, the
public URL will be @code{http-external-url} instead. See public URL will be @code{http-external-url} instead. See
@ -556,7 +561,7 @@ (define-all-configurations prosody-configuration
int-component) int-component)
(mod-muc (mod-muc
(maybe-mod-muc-configuration 'unset) (maybe-mod-muc-configuration %unset-value)
"Multi-user chat (MUC) is Prosody's module for allowing you to create "Multi-user chat (MUC) is Prosody's module for allowing you to create
hosted chatrooms/conferences for XMPP users. hosted chatrooms/conferences for XMPP users.
@ -573,7 +578,7 @@ (define-all-configurations prosody-configuration
ext-component) ext-component)
(raw-content (raw-content
(maybe-raw-content 'unset) (maybe-raw-content %unset-value)
"Raw content that will be added to the configuration file." "Raw content that will be added to the configuration file."
common))) common)))

View file

@ -772,7 +772,7 @@ (define-configuration/no-serialization opendht-configuration
network. A specific port value can be provided by appending the @code{:PORT} network. A specific port value can be provided by appending the @code{:PORT}
suffix. By default, it uses the Jami bootstrap nodes, but any host can be suffix. By default, it uses the Jami bootstrap nodes, but any host can be
specified here. It's also possible to disable bootstrapping by explicitly specified here. It's also possible to disable bootstrapping by explicitly
setting this field to the @code{'unset} value.") setting this field to @code{%unset-value}.")
(port (port
(maybe-number 4222) (maybe-number 4222)
"The UDP port to bind to. When left unspecified, an available port is "The UDP port to bind to. When left unspecified, an available port is

View file

@ -307,7 +307,7 @@ (define (jami-shepherd-services config)
(dbus (jami-configuration-dbus config)) (dbus (jami-configuration-dbus config))
(dbus-daemon (file-append dbus "/bin/dbus-daemon")) (dbus-daemon (file-append dbus "/bin/dbus-daemon"))
(accounts (jami-configuration-accounts config)) (accounts (jami-configuration-accounts config))
(declarative-mode? (not (eq? 'unset accounts)))) (declarative-mode? (maybe-value-set? accounts)))
(with-extensions (list guile-packrat ;used by guile-ac-d-bus (with-extensions (list guile-packrat ;used by guile-ac-d-bus
guile-ac-d-bus guile-ac-d-bus
@ -649,7 +649,7 @@ (define (archive-name->username archive)
account-details) account-details)
(let ((username (archive-name->username (let ((username (archive-name->username
archive))) archive)))
(when (not (eq? 'unset allowed-contacts)) (when (not (eq? '#$%unset-value allowed-contacts))
;; Reject calls from unknown contacts. ;; Reject calls from unknown contacts.
(set-account-details (set-account-details
'(("DHT.PublicInCalls" . "false")) username) '(("DHT.PublicInCalls" . "false")) username)
@ -659,7 +659,7 @@ (define (archive-name->username archive)
;; Add allowed ones. ;; Add allowed ones.
(for-each (cut add-contact <> username) (for-each (cut add-contact <> username)
allowed-contacts)) allowed-contacts))
(when (not (eq? 'unset moderators)) (when (not (eq? '#$%unset-value moderators))
;; Disable the 'AllModerators' property. ;; Disable the 'AllModerators' property.
(set-all-moderators #f username) (set-all-moderators #f username)
;; Remove all moderators. ;; Remove all moderators.

View file

@ -169,7 +169,7 @@ (define-configuration config-with-maybe-string/no-serialization
(not (defined? 'serialize-maybe-string))) (not (defined? 'serialize-maybe-string)))
(test-assert "maybe type, no default" (test-assert "maybe type, no default"
(eq? 'unset (eq? %unset-value
(config-with-maybe-string/no-serialization-name (config-with-maybe-string/no-serialization-name
(config-with-maybe-string/no-serialization)))) (config-with-maybe-string/no-serialization))))