Subject: [bug#74508] [PATCH v2 3/3] services: mingetty: Support waiting on shepherd services.

From: Tomas Volf <[email-masked]>
Date: Mon, 25 Nov 2024 17:05:35 +0100

For auto-login on systems with elogind, dbus-system needs to be started.  This
commit adds ability to express that ordering.

* gnu/services/base.scm (<mingetty-configuration>): Add shepherd-requirement
field.
(mingetty-shepherd-service): Use it.
* doc/guix.texi (Base Services)<mingetty-configuration>: Document it.

Change-Id: Iedbdc4375180740379d561aa193d7c63350d2e7b
---
v2: Just slight formatting changes.

 doc/guix.texi         | 20 ++++++++++++++
 gnu/services/base.scm | 62 ++++++++++++++++++++++++-------------------
 2 files changed, 54 insertions(+), 28 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index c5f9481810..9a8daf52d9 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -19375,6 +19375,26 @@ Base Services
 @item @code{chroot} (default: @code{#f})
 When set to a string, call @code{chroot} with that directory.

+@item @code{shepherd-requirement}
+List of shepherd requirements.  Unless you know what you are doing, it
+is recommended to add to the default list instead of replacing.
+
+For example you can use this field when performing auto-login on a
+system with elogind to wait on @code{'dbus-system}.
+
+@lisp
+(modify-services %base-services
+  (mingetty-service-type config =>
+                         (mingetty-configuration
+                          (inherit config)
+                          ;; Automatically log in as "guest".
+                          (auto-login "guest")
+                          (shepherd-requirement
+                           (cons 'dbus-system
+                                 (mingetty-configuration-shepherd-requirement
+                                  config))))))
+@end lisp
+
 @item @code{mingetty} (default: @var{mingetty})
 The Mingetty package to use.

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index e123226da5..ecf0322890 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -193,6 +193,7 @@ (define-module (gnu services base)
             mingetty-configuration-nice
             mingetty-configuration-chdir
             mingetty-configuration-chroot
+            mingetty-configuration-shepherd-requirement
             mingetty-configuration?
             mingetty-service  ; deprecated
             mingetty-service-type
@@ -1246,44 +1247,49 @@ (define-deprecated (agetty-service config)
 (define-record-type* <mingetty-configuration>
   mingetty-configuration make-mingetty-configuration
   mingetty-configuration?
-  (mingetty         mingetty-configuration-mingetty ;file-like
-                    (default mingetty))
-  (tty              mingetty-configuration-tty)       ;string
-  (auto-login       mingetty-configuration-auto-login ;string | #f
-                    (default #f))
-  (login-program    mingetty-configuration-login-program ;gexp
-                    (default #f))
-  (login-pause?     mingetty-configuration-login-pause? ;Boolean
-                    (default #f))
-  (clear-on-logout? mingetty-configuration-clear-on-logout? ;Boolean
-                    (default #t))
-  (delay            mingetty-configuration-delay ;Integer | #f
-                    (default #f))
-  (print-issue      mingetty-configuration-print-issue ;Boolean | Symbol
-                    (default #t))
-  (print-hostname   mingetty-configuration-print-hostname ;Boolean | Symbol
-                    (default #t))
-  (nice             mingetty-configuration-nice ;Integer | #f
-                    (default #f))
-  (chdir            mingetty-configuration-chdir ;String | #f
-                    (default #f))
-  (chroot           mingetty-configuration-chroot ;String | #f
-                    (default #f)))
+  (mingetty             mingetty-configuration-mingetty ;file-like
+                        (default mingetty))
+  (tty                  mingetty-configuration-tty)       ;string
+  (auto-login           mingetty-configuration-auto-login ;string | #f
+                        (default #f))
+  (login-program        mingetty-configuration-login-program ;gexp
+                        (default #f))
+  (login-pause?         mingetty-configuration-login-pause? ;Boolean
+                        (default #f))
+  (clear-on-logout?     mingetty-configuration-clear-on-logout? ;Boolean
+                        (default #t))
+  (delay                mingetty-configuration-delay ;Integer | #f
+                        (default #f))
+  (print-issue          mingetty-configuration-print-issue ;Boolean | Symbol
+                        (default #t))
+  (print-hostname       mingetty-configuration-print-hostname ;Boolean | Symbol
+                        (default #t))
+  (nice                 mingetty-configuration-nice ;Integer | #f
+                        (default #f))
+  (chdir                mingetty-configuration-chdir ;String | #f
+                        (default #f))
+  (chroot               mingetty-configuration-chroot ;String | #f
+                        (default #f))
+  (shepherd-requirement mingetty-configuration-shepherd-requirement
+                        ;; Since the login prompt shows the host name, wait
+                        ;; for the 'host-name' service to be done.  Also wait
+                        ;; for udev essentially so that the tty text is not
+                        ;; lost in the middle of kernel messages (XXX).
+                        (default '( user-processes host-name udev
+                                    virtual-terminal))))

 (define (mingetty-shepherd-service config)
   (match-record config <mingetty-configuration>
                 ( mingetty tty auto-login login-program
                   login-pause? clear-on-logout? delay
-                  print-issue print-hostname nice chdir chroot)
+                  print-issue print-hostname nice chdir chroot
+                  shepherd-requirement)
     (list
      (shepherd-service
       (documentation "Run mingetty on an tty.")
       (provision (list (symbol-append 'term- (string->symbol tty))))

-      ;; Since the login prompt shows the host name, wait for the 'host-name'
-      ;; service to be done.  Also wait for udev essentially so that the tty
-      ;; text is not lost in the middle of kernel messages (XXX).
-      (requirement '(user-processes host-name udev virtual-terminal))
+      (requirement shepherd-requirement)

       (start  #~(make-forkexec-constructor
                  (list #$(file-append mingetty "/sbin/mingetty")
--
2.46.0