summary refs log tree commit diff
path: root/gnu/services/base.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/services/base.scm')
-rw-r--r--gnu/services/base.scm104
1 files changed, 62 insertions, 42 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index bab07aa4b7..eb7c9dce04 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -20,6 +20,7 @@
   #:use-module ((guix store)
                 #:select (%store-prefix))
   #:use-module (gnu services)
+  #:use-module (gnu services networking)
   #:use-module (gnu system shadow)                ; 'user-account', etc.
   #:use-module (gnu system linux)                 ; 'pam-service', etc.
   #:use-module (gnu packages admin)
@@ -189,7 +190,7 @@ stopped before 'kill' is called."
              (respawn? #f)))))
 
 (define (host-name-service name)
-  "Return a service that sets the host name to NAME."
+  "Return a service that sets the host name to @var{name}."
   (with-monad %store-monad
     (return (service
              (documentation "Initialize the machine's host name.")
@@ -204,6 +205,10 @@ stopped before 'kill' is called."
                            auto-login
                            login-program
                            login-pause?
+
+                           ;; Allow empty passwords by default so that
+                           ;; first-time users can log in when the 'root'
+                           ;; account has just been created.
                            (allow-empty-passwords? #t))
   "Return a service to run mingetty on @var{tty}.
 
@@ -218,7 +223,7 @@ of the log-in program (the default is the @code{login} program from the Shadow
 tool suite.)
 
 @var{motd} is a monadic value containing a text file to use as
-the \"message of the day\"."
+the ``message of the day''."
   (mlet %store-monad ((motd motd)
                       (login-program (cond ((gexp? login-program)
                                             (return login-program))
@@ -236,17 +241,17 @@ the \"message of the day\"."
       (requirement '(user-processes host-name))
 
       (start  #~(make-forkexec-constructor
-                 (string-append #$mingetty "/sbin/mingetty")
-                 "--noclear" #$tty
-                 #$@(if auto-login
-                        #~("--autologin" #$auto-login)
-                        #~())
-                 #$@(if login-program
-                        #~("--loginprog" #$login-program)
-                        #~())
-                 #$@(if login-pause?
-                        #~("--loginpause")
-                        #~())))
+                 (list (string-append #$mingetty "/sbin/mingetty")
+                       "--noclear" #$tty
+                       #$@(if auto-login
+                              #~("--autologin" #$auto-login)
+                              #~())
+                       #$@(if login-program
+                              #~("--loginprog" #$login-program)
+                              #~())
+                       #$@(if login-pause?
+                              #~("--loginpause")
+                              #~()))))
       (stop   #~(make-kill-destructor))
 
       (pam-services
@@ -269,16 +274,15 @@ the \"message of the day\"."
                            (use-modules (guix build utils))
                            (mkdir-p "/var/run/nscd")))
 
-             (start
-              #~(make-forkexec-constructor (string-append #$glibc "/sbin/nscd")
-                                           "-f" "/dev/null"
-                                           "--foreground"))
+             (start #~(make-forkexec-constructor
+                       (list (string-append #$glibc "/sbin/nscd")
+                             "-f" "/dev/null" "--foreground")))
              (stop #~(make-kill-destructor))
 
              (respawn? #f)))))
 
 (define (syslog-service)
-  "Return a service that runs 'syslogd' with reasonable default settings."
+  "Return a service that runs @code{syslogd} with reasonable default settings."
 
   ;; Snippet adapted from the GNU inetutils manual.
   (define contents "
@@ -310,10 +314,9 @@ the \"message of the day\"."
       (provision '(syslogd))
       (requirement '(user-processes))
       (start
-       #~(make-forkexec-constructor (string-append #$inetutils
-                                                   "/libexec/syslogd")
-                                    "--no-detach"
-                                    "--rcfile" #$syslog.conf))
+       #~(make-forkexec-constructor
+          (list (string-append #$inetutils "/libexec/syslogd")
+                "--no-detach" "--rcfile" #$syslog.conf)))
       (stop #~(make-kill-destructor))))))
 
 (define* (guix-build-accounts count #:key
@@ -366,12 +369,12 @@ failed to register hydra.gnu.org public key: ~a~%" status))))))))
 
 (define* (guix-service #:key (guix guix) (builder-group "guixbuild")
                        (build-accounts 10) authorize-hydra-key?)
-  "Return a service that runs the build daemon from GUIX, and has
-BUILD-ACCOUNTS user accounts available under BUILD-USER-GID.
+  "Return a service that runs the build daemon from @var{guix}, and has
+@var{build-accounts} user accounts available under @var{builder-group}.
 
-When AUTHORIZE-HYDRA-KEY? is true, the hydra.gnu.org public key provided by
-GUIX is authorized upon activation, meaning that substitutes from
-hydra.gnu.org are used by default."
+When @var{authorize-hydra-key?} is true, the @code{hydra.gnu.org} public key
+provided by @var{guix} is authorized upon activation, meaning that substitutes
+from @code{hydra.gnu.org} are used by default."
   (define activate
     ;; Assume that the store has BUILDER-GROUP as its group.  We could
     ;; otherwise call 'chown' here, but the problem is that on a COW unionfs,
@@ -387,10 +390,9 @@ hydra.gnu.org are used by default."
              (provision '(guix-daemon))
              (requirement '(user-processes))
              (start
-              #~(make-forkexec-constructor (string-append #$guix
-                                                          "/bin/guix-daemon")
-                                           "--build-users-group"
-                                           #$builder-group))
+              #~(make-forkexec-constructor
+                 (list (string-append #$guix "/bin/guix-daemon")
+                       "--build-users-group" #$builder-group)))
              (stop #~(make-kill-destructor))
              (user-accounts accounts)
              (user-groups (list (user-group
@@ -409,6 +411,23 @@ hydra.gnu.org are used by default."
              (requirement '(root-file-system))
              (documentation "Populate the /dev directory.")
              (start #~(lambda ()
+                        (define udevd
+                          (string-append #$udev "/libexec/udev/udevd"))
+
+                        (define (wait-for-udevd)
+                          ;; Wait until someone's listening on udevd's control
+                          ;; socket.
+                          (let ((sock (socket AF_UNIX SOCK_SEQPACKET 0)))
+                            (let try ()
+                              (catch 'system-error
+                                (lambda ()
+                                  (connect sock PF_UNIX "/run/udev/control")
+                                  (close-port sock))
+                                (lambda args
+                                  (format #t "waiting for udevd...~%")
+                                  (usleep 500000)
+                                  (try))))))
+
                         ;; Allow udev to find the modules.
                         (setenv "LINUX_MODULE_DIRECTORY"
                                 "/run/booted-system/kernel/lib/modules")
@@ -416,21 +435,20 @@ hydra.gnu.org are used by default."
                         (let ((pid (primitive-fork)))
                           (case pid
                             ((0)
-                             ;; In dmd 0.1, file descriptor 0 is closed, thus
-                             ;; is gets reused when open(2) is called, and it
-                             ;; turns out that EPOLL_CTL_ADD of 0 returns
-                             ;; EPERM for some reason.  So make sure 0 is
-                             ;; open.
-                             ;; FIXME: Close the other descriptors.
-                             (execl (string-append #$udev "/libexec/udev/udevd")
-                                    "udevd"))
+                             (exec-command (list udevd)))
                             (else
+                             ;; Wait until udevd is up and running.  This
+                             ;; appears to be needed so that the events
+                             ;; triggered below are actually handled.
+                             (wait-for-udevd)
+
+                             ;; Trigger device node creation.
+                             (system* (string-append #$udev "/bin/udevadm")
+                                      "trigger" "--action=add")
+
                              ;; Wait for things to settle down.
                              (system* (string-append #$udev "/bin/udevadm")
                                       "settle")
-                             ;; Create a bunch of devices.
-                             (system* (string-append #$udev "/bin/udevadm")
-                                      "trigger")
                              pid)))))
              (stop #~(make-kill-destructor))))))
 
@@ -444,6 +462,8 @@ This is the GNU operating system, welcome!\n\n")))
           (mingetty-service "tty4" #:motd motd)
           (mingetty-service "tty5" #:motd motd)
           (mingetty-service "tty6" #:motd motd)
+          (static-networking-service "lo" "127.0.0.1"
+                                     #:provision '(loopback))
           (syslog-service)
           (guix-service)
           (nscd-service)