Subject: Re: bug#58223: [PATCH 0/1] dhclient record configuration

From: Ludovic Courtès <[email-masked]>
Date: Thu, 06 Oct 2022 00:04:53 +0200

Hi,

Alexey Abramov <[email-masked]> skribis:

> * gnu/services/networking.scm (dhcp-client-configuration): New record
> configuration.
> (dhcp-client-shepherd-service): Implement a shepher service. Provide a
> deprication message for legacy configurations.
> (dhcp-client-service-type): Use dhcp-client-shepherd-service.
> * doc/guix.texi: Update documentation

[...]

> +  ;; Empty list (means any) or a list of valid interfaces
> +  (interfaces   dhcp-client-configuration-interfaces
> +                (default '())))

[...]

> +                         (define ifaces
> +                           (filter valid? (or '#$interfaces
> +                                              (all-network-interface-names))))

This isn’t quite right since '() is always true.

For this and for aesthetic reasons, I changed ‘interfaces’ such that it
must be either 'all or a list.

Applied with the changes below, thanks!

Ludo’.

diff --git a/doc/guix.texi b/doc/guix.texi
index afc18239d4..6691ae5844 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -19234,17 +19234,19 @@ Protocol (DHCP) client.
 @end defvr
 
 @deftp {Data Type} dhcp-client-configuration
-Data type representing the configuration of dhcp client network service.
+Data type representing the configuration of the DHCP client service.
 
 @table @asis
 @item @code{package} (default: @code{isc-dhcp})
 DHCP client package to use.
 
-@item @code{interfaces} (default: @code{'()})
-List of strings of interface names that dhcp client should listen on. By
-default dhcp client will listen on all available non-loopback interfaces
-that can be activated (meaning, to set them up). (default: @code{'()})
+@item @code{interfaces} (default: @code{'all})
+Either @code{'all} or the list of interface names that the DHCP client
+should listen on---e.g., @code{'("eno1")}.
 
+When set to @code{'all}, the DHCP client listens on all the available
+non-loopback interfaces that can be activated.  Otherwise the DHCP
+client listens only on the specified interfaces.
 @end table
 @end deftp
 
diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
index 1185f7e57d..19aba8c266 100644
--- a/gnu/services/networking.scm
+++ b/gnu/services/networking.scm
@@ -66,6 +66,9 @@ (define-module (gnu services networking)
   #:use-module (guix modules)
   #:use-module (guix packages)
   #:use-module (guix deprecation)
+  #:use-module (guix diagnostics)
+  #:autoload   (guix ui) (display-hint)
+  #:use-module (guix i18n)
   #:use-module (rnrs enums)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9)
@@ -269,9 +272,8 @@ (define-record-type* <dhcp-client-configuration>
   dhcp-client-configuration?
   (package      dhcp-client-configuration-package ;file-like
                 (default isc-dhcp))
-  ;; Empty list (means any) or a list of valid interfaces
   (interfaces   dhcp-client-configuration-interfaces
-                (default '())))
+                (default 'all)))                  ;'all | list of strings
 
 (define dhcp-client-shepherd-service
   (match-lambda
@@ -305,8 +307,12 @@ (define valid?
                                   (false-if-exception
                                    (set-network-interface-up interface)))))
                          (define ifaces
-                           (filter valid? (or '#$interfaces
-                                              (all-network-interface-names))))
+                           (filter valid?
+                                   #$(match interfaces
+                                       ('all
+                                        #~(all-network-interface-names))
+                                       (_
+                                        #~'#$interfaces))))
 
                          (false-if-exception (delete-file #$pid-file))
                          (let ((pid (fork+exec-command
@@ -315,18 +321,21 @@ (define ifaces
                            (and (zero? (cdr (waitpid pid)))
                                 (read-pid-file #$pid-file)))))
               (stop #~(make-kill-destructor))))))
-    (anything
-     (format (current-error-port) "warning: Defining dhcp-client service with
-a single argument value being a client package to use, is deprecated.  Please
-use <dhcp-client-configuration> record instead.\n")
+    (package
+     (warning (G_ "'dhcp-client' service now expects a \
+'dhcp-client-configuration' record~%"))
+     (display-hint (G_ "The value associated with instances of
+@code{dhcp-client-service-type} must now be a @code{dhcp-client-configuration}
+record instead of a package.  Please adjust your configuration accordingly."))
      (dhcp-client-shepherd-service
       (dhcp-client-configuration
-       (package anything))))))
+       (package package))))))
 
 (define dhcp-client-service-type
   (service-type (name 'dhcp-client)
                 (extensions
-                 (list (service-extension shepherd-root-service-type dhcp-client-shepherd-service)))
+                 (list (service-extension shepherd-root-service-type
+                                          dhcp-client-shepherd-service)))
                 (default-value (dhcp-client-configuration))
                 (description "Run @command{dhcp}, a Dynamic Host Configuration
 Protocol (DHCP) client, on all the non-loopback network interfaces.")))
diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in
index 4050a4c7ae..ed3fdb6be0 100644
--- a/po/guix/POTFILES.in
+++ b/po/guix/POTFILES.in
@@ -5,6 +5,7 @@ gnu/packages.scm
 gnu/services.scm
 gnu/system.scm
 gnu/services/configuration.scm
+gnu/services/networking.scm
 gnu/services/shepherd.scm
 gnu/services/samba.scm
 gnu/home/services.scm