Subject: Re: bug#56799: (gnu services configuration) usage of *unspecified* is problematic

From: Maxim Cournoyer <[email-masked]>
Date: Thu, 25 Aug 2022 00:18:36 -0400

Hi,

Attila Lendvai <[email-masked]> writes:

> * 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.

[...]

> --- a/gnu/services/telephony.scm
> +++ b/gnu/services/telephony.scm
> @@ -307,7 +307,7 @@ (define (jami-shepherd-services config)
>           (dbus (jami-configuration-dbus config))
>           (dbus-daemon (file-append dbus "/bin/dbus-daemon"))
>           (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
>                             guile-ac-d-bus
> @@ -649,7 +649,7 @@ (define (archive-name->username archive)
>                                            account-details)
>                             (let ((username (archive-name->username
>                                              archive)))
> -                             (when (not (eq? 'unset allowed-contacts))
> +                             (when (maybe-value-set? allowed-contacts)
>                                 ;; Reject calls from unknown contacts.
>                                 (set-account-details
>                                  '(("DHT.PublicInCalls" . "false")) username)
> @@ -659,7 +659,7 @@ (define (archive-name->username archive)
>                                 ;; Add allowed ones.
>                                 (for-each (cut add-contact <> username)
>                                           allowed-contacts))
> -                             (when (not (eq? 'unset moderators))
> +                             (when (maybe-value-set? moderators)
>                                 ;; Disable the 'AllModerators' property.
>                                 (set-all-moderators #f username)
>                                 ;; Remove all moderators.

maybe-value-set? cannot be used there, as the code runs on the target,
not on the host, where (gnu services configuration) is not (and cannot)
be in scope.

I've made the simple change below and pushed:

--8<---------------cut here---------------start------------->8---
modified   gnu/services/telephony.scm
@@ -649,7 +649,7 @@ (define (archive-name->username archive)
                                           account-details)
                            (let ((username (archive-name->username
                                             archive)))
-                             (when (maybe-value-set? allowed-contacts)
+                             (when (not (eq? '#$%unset-value allowed-contacts))
                                ;; Reject calls from unknown contacts.
                                (set-account-details
                                 '(("DHT.PublicInCalls" . "false")) username)
@@ -659,7 +659,7 @@ (define (archive-name->username archive)
                                ;; Add allowed ones.
                                (for-each (cut add-contact <> username)
                                          allowed-contacts))
-                             (when (maybe-value-set? moderators)
+                             (when (not (eq? '#$%unset-value moderators))
                                ;; Disable the 'AllModerators' property.
                                (set-all-moderators #f username)
                                ;; Remove all moderators.
--8<---------------cut here---------------end--------------->8---

I've also adjusted a few 'unset mentions in the doc:

--8<---------------cut here---------------start------------->8---
modified   doc/guix.texi
@@ -19846,7 +19846,7 @@ 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 specified here.  It's also possible to disable
 bootstrapping by explicitly setting this field to the
-@code{'unset} value.
+@code{%unset-value} value.
 
 @item @code{port} (default: @code{4222}) (type: maybe-number)
 The UDP port to bind to.  When left unspecified, an available port is
@@ -31362,7 +31362,7 @@ Each parameter definition is preceded by its type; for example,
 @samp{boolean foo} indicates that the @code{foo} parameter should be
 specified as a boolean.  Types starting with @code{maybe-} denote
 parameters that won't show up in TLP config file when their value is
-left unset, or is explicitly set to the @code{'unset} value.
+left unset, or is explicitly set to the @code{%unset-value} value.
 
 @c The following documentation was initially generated by
 @c (generate-tlp-documentation) in (gnu services pm).  Manually maintained
@@ -38983,8 +38983,7 @@ macro which is a shorthand of this.
 Sometimes a field should not be serialized if the user doesn’t specify a
 value.  To achieve this, you can use the @code{define-maybe} macro to
 define a ``maybe type''; if the value of a maybe type is left unset, or
-is set to the @code{'unset} value, then it will not be
-serialized.
+is set to the @code{%unset-value} value, then it will not be serialized.
 
 When defining a ``maybe type'', the corresponding serializer for the
 regular type will be used by default.  For example, a field of type
--8<---------------cut here---------------end--------------->8---

I've made these changes and pushed, as mentioned in a previous email.

Thank you!

Maxim