From 151a2c07aa0537c136e6fe61609957878f0a4c72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Mon, 23 Jun 2014 15:35:03 +0200
Subject: [PATCH] services: Add udev service, and add it to '%base-services'.

* gnu/services/base.scm (udev-service): New procedure.
  (%base-services): Use it.
* gnu/system.scm (%base-packages): Add UDEV.
---
 gnu/services/base.scm | 32 +++++++++++++++++++++++++++++++-
 gnu/system.scm        |  2 +-
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 595cac254b3..35e5d42fa83 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -23,6 +23,8 @@ (define-module (gnu services base)
   #:use-module (gnu system shadow)                ; 'user-account', etc.
   #:use-module (gnu system linux)                 ; 'pam-service', etc.
   #:use-module (gnu packages admin)
+  #:use-module ((gnu packages linux)
+                #:select (udev))
   #:use-module ((gnu packages base)
                 #:select (glibc-final))
   #:use-module (gnu packages package-management)
@@ -35,6 +37,7 @@ (define-module (gnu services base)
             file-system-service
             user-processes-service
             host-name-service
+            udev-service
             mingetty-service
             nscd-service
             syslog-service
@@ -397,6 +400,32 @@ (define activate
                                  (id 30000))))
              (activate activate)))))
 
+(define* (udev-service #:key (udev udev))
+  "Run @var{udev}, which populates the @file{/dev} directory dynamically."
+  (with-monad %store-monad
+    (return (service
+             (provision '(udev))
+             (requirement '(root-file-system))
+             (documentation "Populate the /dev directory.")
+             (start #~(lambda ()
+                        (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"))
+                            (else
+                             ;; Create a bunch of devices.
+                             (system* (string-append #$udev "/bin/udevadm")
+                                      "trigger")
+                             pid)))))
+             (stop #~(make-kill-destructor))))))
+
 (define %base-services
   ;; Convenience variable holding the basic services.
   (let ((motd (text-file "motd" "
@@ -409,6 +438,7 @@ (define %base-services
           (mingetty-service "tty6" #:motd motd)
           (syslog-service)
           (guix-service)
-          (nscd-service))))
+          (nscd-service)
+          (udev-service))))
 
 ;;; base.scm ends here
diff --git a/gnu/system.scm b/gnu/system.scm
index 41ea59b69bc..c2d31de15da 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -218,7 +218,7 @@ (define %base-packages
          guile-final (@ (gnu packages admin) dmd) guix
          util-linux inetutils isc-dhcp
          net-tools                        ; XXX: remove when Inetutils suffices
-         module-init-tools kbd
+         module-init-tools udev kbd
 
          ;; The packages below are also in %FINAL-INPUTS, so take them from
          ;; there to avoid duplication.
-- 
GitLab