aboutsummaryrefslogtreecommitdiff
path: root/gnu/services/base.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-09-11 22:13:37 +0200
committerLudovic Courtès <ludo@gnu.org>2014-09-12 00:14:52 +0200
commitecd06ca9faa7b87fb7be770f563c8a0760a64709 (patch)
tree60b94b321441928ece2ac5b05303756f00a2a289 /gnu/services/base.scm
parentc65e1834032d7f6e1bc4ebbc8157389a922f1e99 (diff)
downloadguix-ecd06ca9faa7b87fb7be770f563c8a0760a64709.tar
guix-ecd06ca9faa7b87fb7be770f563c8a0760a64709.tar.gz
services: udev: Allow for additional udev rules.
* gnu/services/base.scm (udev-rules-union): New procedure. (udev-service): Add #:rules parameter. Call 'udev-rules-union' and create udev.conf. Set $UDEV_CONFIG_FILE before spawning udevd.
Diffstat (limited to 'gnu/services/base.scm')
-rw-r--r--gnu/services/base.scm47
1 files changed, 42 insertions, 5 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index b5b49d1a01..bf5af8369e 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -25,7 +25,7 @@
#:use-module (gnu system linux) ; 'pam-service', etc.
#:use-module (gnu packages admin)
#:use-module ((gnu packages linux)
- #:select (udev kbd e2fsprogs))
+ #:select (udev kbd e2fsprogs lvm2))
#:use-module ((gnu packages base)
#:select (canonical-package glibc))
#:use-module (gnu packages package-management)
@@ -479,9 +479,41 @@ passed to @command{guix-daemon}."
(id 30000))))
(activate activate)))))
-(define* (udev-service #:key (udev udev))
- "Run @var{udev}, which populates the @file{/dev} directory dynamically."
- (with-monad %store-monad
+(define (udev-rules-union packages)
+ "Return the union of the @code{lib/udev/rules.d} directories found in each
+item of @var{packages}."
+ (define build
+ #~(begin
+ (use-modules (guix build union)
+ (guix build utils)
+ (srfi srfi-1)
+ (srfi srfi-26))
+
+ (define %standard-locations
+ '("/lib/udev/rules.d" "/libexec/udev/rules.d"))
+
+ (define (rules-sub-directory directory)
+ ;; Return the sub-directory of DIRECTORY containing udev rules, or
+ ;; #f if none was found.
+ (find directory-exists?
+ (map (cut string-append directory <>) %standard-locations)))
+
+ (mkdir-p (string-append #$output "/lib/udev"))
+ (union-build (string-append #$output "/lib/udev/rules.d")
+ (filter-map rules-sub-directory '#$packages))))
+
+ (gexp->derivation "udev-rules" build
+ #:modules '((guix build union)
+ (guix build utils))
+ #:local-build? #t))
+
+(define* (udev-service #:key (udev udev) (rules '()))
+ "Run @var{udev}, which populates the @file{/dev} directory dynamically. Get
+extra rules from the packages listed in @var{rules}."
+ (mlet* %store-monad ((rules (udev-rules-union (cons udev rules)))
+ (udev.conf (text-file* "udev.conf"
+ "udev_rules=\"" rules
+ "/lib/udev/rules.d\"\n")))
(return (service
(provision '(udev))
@@ -513,6 +545,8 @@ passed to @command{guix-daemon}."
(setenv "LINUX_MODULE_DIRECTORY"
"/run/booted-system/kernel/lib/modules")
+ (setenv "UDEV_CONFIG_FILE" #$udev.conf)
+
(let ((pid (primitive-fork)))
(case pid
((0)
@@ -555,6 +589,9 @@ This is the GNU operating system, welcome!\n\n")))
(syslog-service)
(guix-service)
(nscd-service)
- (udev-service))))
+
+ ;; By default, enable the udev rules of LVM2. They are needed as
+ ;; soon as LVM2 or the device-mapper is used.
+ (udev-service #:rules (list lvm2)))))
;;; base.scm ends here