Subject: [PATCH 2/3] services: networking: Add shepherd-requirement for dhcpcd.

From: Sergey Trofimov <[email-masked]>
Date: Fri, 23 May 2025 11:04:33 +0200

* gnu/services/networking.scm (dhcpcd-configuration): Add
shepherd-requirement field.
(dhcpcd-shepherd-service): Use it.
* doc/guix.texi (Networking Setup): Regenerate dhcpcd-configuration
documentation.
(File Systems): Fix typo.

Change-Id: Id347e2bed2569237685a47be82dbf686640db25b
---
 doc/guix.texi               | 17 +++++++++++------
 gnu/services/networking.scm | 31 +++++++++++++++++++------------
 2 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 02f472246a..3ef2e50e57 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -18332,7 +18332,7 @@ File Systems
 might not be sufficient as @code{networking} being marked as started
 does @emph{not} imply the network has already been configured and in
 working order (for example, when using
-@code{dhcpcd-client-service-type}).  For such cases, adding a
+@code{dhcp-client-service-type}).  For such cases, adding a
 requirement on a custom @code{network-online} service may be necessary.
 A sample @code{network-online} one-shot Shepherd service implementation
 is provided below:
@@ -21980,12 +21980,13 @@ Networking Setup
 @item @code{duid} (default: @code{""}) (type: maybe-string)
 DHCPv4 clients require a unique client identifier, this option uses the
 DHCPv6 Unique Identifier as a DHCPv4 client identifier as well.  For
-more information, refer to @uref{https://www.rfc-editor.org/rfc/rfc4361, RFC 4361}
-and @code{dhcpcd.conf(5)}.
+more information, refer to
+@uref{https://www.rfc-editor.org/rfc/rfc4361,RFC 4361} and
+@code{dhcpcd.conf(5)}.
 
 @item @code{persistent?} (default: @code{#t}) (type: boolean)
-When true, automatically de-configure the interface when @command{dhcpcd}
-exits.
+When true, automatically de-configure the interface when
+@command{dhcpcd} exits.
 
 @item @code{option} (default: @code{("rapid_commit" "domain_name_servers" "domain_name" "domain_search" "host_name" "classless_static_routes" "interface_mtu")}) (type: list-of-strings)
 List of options to request from the server.
@@ -22019,9 +22020,13 @@ Networking Setup
 @item @code{extra-content} (type: maybe-string)
 Extra content to append to the configuration as-is.
 
+@item @code{shepherd-requirement} (default: @code{()}) (type: list-of-symbols)
+This is a list of symbols naming Shepherd services that this service
+will depend on.
+
 @end table
-@end deftp
 
+@end deftp
 
 @cindex NetworkManager
 
diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
index 67653e2cbf..4cb7313808 100644
--- a/gnu/services/networking.scm
+++ b/gnu/services/networking.scm
@@ -126,6 +126,7 @@ (define-module (gnu services networking)
             dhcpcd-configuration-vendor-class-id
             dhcpcd-configuration-client-id
             dhcpcd-configuration-extra-content
+            dhcpcd-configuration-shepherd-requirement
 
             ntp-configuration
             ntp-configuration?
@@ -609,6 +610,12 @@ (define-configuration dhcpcd-configuration
     maybe-string
     "Extra content to append to the configuration as-is.")
 
+  (shepherd-requirement
+   (list-of-symbols '())
+   "This is a list of symbols naming Shepherd services that this service
+will depend on."
+   empty-serializer)
+
   (prefix dhcpcd-))
 
 (define (dhcpcd-config-file config)
@@ -628,19 +635,19 @@ (define dhcpcd-account-service
           (shell (file-append shadow "/sbin/nologin")))))
 
 (define (dhcpcd-shepherd-service config)
-  (let* ((config-file (dhcpcd-config-file config))
-         (command-args (dhcpcd-configuration-command-arguments config))
-         (ifaces (dhcpcd-configuration-interfaces config)))
-    (list (shepherd-service
-            (documentation "dhcpcd daemon.")
-            (provision '(networking))
-            (requirement '(user-processes udev))
-            (actions (list (shepherd-configuration-action config-file)))
-            (start
+  (match-record config <dhcpcd-configuration>
+                (command-arguments interfaces shepherd-requirement)
+    (let ((config-file (dhcpcd-config-file config)))
+      (list (shepherd-service
+             (documentation "dhcpcd daemon.")
+             (provision '(networking))
+             (requirement `(user-processes udev ,@shepherd-requirement))
+             (actions (list (shepherd-configuration-action config-file)))
+             (start
               #~(make-forkexec-constructor
-                    (list (string-append #$dhcpcd "/sbin/dhcpcd")
-                          #$@command-args "-B" "-f" #$config-file #$@ifaces)))
-            (stop #~(make-kill-destructor))))))
+                 (list (string-append #$dhcpcd "/sbin/dhcpcd")
+                       #$@command-arguments "-B" "-f" #$config-file #$@interfaces)))
+             (stop #~(make-kill-destructor)))))))
 
 (define dhcpcd-service-type
   (service-type (name 'dhcpcd)
-- 
2.49.0