diff options
Diffstat (limited to 'gnu/services/base.scm')
-rw-r--r-- | gnu/services/base.scm | 116 |
1 files changed, 83 insertions, 33 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 6539bfd6ce..0e3f600128 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -84,6 +84,7 @@ #:select (mount-flags->bit-mask swap-space->flags-bit-mask)) #:use-module (guix gexp) + #:use-module ((guix packages) #:select (package-version)) #:use-module (guix records) #:use-module (guix modules) #:use-module (guix pki) @@ -154,11 +155,15 @@ udev-configuration udev-configuration? udev-configuration-rules + udev-configuration-hardware udev-service-type udev-service ; deprecated udev-rule + udev-hardware file->udev-rule + file->udev-hardware udev-rules-service + udev-hardware-service login-configuration login-configuration? @@ -2241,11 +2246,13 @@ command that allows you to share pre-built binaries with others over HTTP."))) (udev udev-configuration-udev ;file-like (default eudev)) (rules udev-configuration-rules ;list of file-like - (default '()))) + (default '())) + (hardware udev-configuration-hardware ;list of file-like + (default '()))) -(define (udev-rules-union packages) - "Return the union of the @code{lib/udev/rules.d} directories found in each -item of @var{packages}." +(define (udev-configurations-union subdirectory packages) + "Return the union of the lib/udev/SUBDIRECTORY directories found in each +item of PACKAGES." (define build (with-imported-modules '((guix build union) (guix build utils)) @@ -2256,51 +2263,64 @@ item of @var{packages}." (srfi srfi-26)) (define %standard-locations - '("/lib/udev/rules.d" "/libexec/udev/rules.d")) + '(#$(string-append "/lib/udev/" subdirectory) + #$(string-append "/libexec/udev/" subdirectory))) - (define (rules-sub-directory directory) - ;; Return the sub-directory of DIRECTORY containing udev rules, or - ;; #f if none was found. + (define (configuration-sub-directory directory) + ;; Return the sub-directory of DIRECTORY containing udev + ;; configurations, or #f if none was found. (find directory-exists? (map (cut string-append directory <>) %standard-locations))) (union-build #$output - (filter-map rules-sub-directory '#$packages))))) + (filter-map configuration-sub-directory '#$packages))))) + + (computed-file (string-append "udev-" subdirectory) build)) + +(define (udev-rules-union packages) + "Return the union of the lib/udev/rules.d directories found in each +item of PACKAGES." + (udev-configurations-union "rules.d" packages)) - (computed-file "udev-rules" build)) +(define (udev-configuration-file subdirectory file-name contents) + "Return a directory with a udev configuration file FILE-NAME containing CONTENTS." + (file->udev-configuration-file subdirectory file-name (plain-file file-name contents))) (define (udev-rule file-name contents) "Return a directory with a udev rule file FILE-NAME containing CONTENTS." - (computed-file file-name - (with-imported-modules '((guix build utils)) - #~(begin - (use-modules (guix build utils)) - - (define rules.d - (string-append #$output "/lib/udev/rules.d")) + (udev-configuration-file "rules.d" file-name contents)) - (mkdir-p rules.d) - (call-with-output-file - (string-append rules.d "/" #$file-name) - (lambda (port) - (display #$contents port))))))) +(define (udev-hardware file-name contents) + "Return a directory with a udev hardware file FILE-NAME containing CONTENTS." + (udev-configuration-file "hwdb.d" file-name contents)) -(define (file->udev-rule file-name file) - "Return a directory with a udev rule file FILE-NAME which is a copy of FILE." +(define (file->udev-configuration-file subdirectory file-name file) + "Return a directory with a udev configuration file FILE-NAME which is a copy + of FILE." (computed-file file-name (with-imported-modules '((guix build utils)) #~(begin (use-modules (guix build utils)) - (define rules.d - (string-append #$output "/lib/udev/rules.d")) + (define configuration-directory + (string-append #$output + "/lib/udev/" + #$subdirectory)) (define file-copy-dest - (string-append rules.d "/" #$file-name)) + (string-append configuration-directory "/" #$file-name)) - (mkdir-p rules.d) + (mkdir-p configuration-directory) (copy-file #$file file-copy-dest))))) +(define (file->udev-rule file-name file) + "Return a directory with a udev rule file FILE-NAME which is a copy of FILE." + (file->udev-configuration-file "rules.d" file-name file)) + +(define (file->udev-hardware file-name file) + "Return a directory with a udev hardware file FILE-NAME which is a copy of FILE." + (file->udev-configuration-file "hwdb.d" file-name file)) + (define kvm-udev-rule ;; Return a directory with a udev rule that changes the group of /dev/kvm to ;; "kvm" and makes it #o660. Apparently QEMU-KVM used to ship this rule, @@ -2408,13 +2428,27 @@ item of @var{packages}." (define (udev-etc config) (match-record config <udev-configuration> - (udev rules) + (udev rules hardware) + (let* ((hardware + (udev-configurations-union "hwdb.d" (cons* udev hardware))) + (hwdb.bin + (computed-file + "hwdb.bin" + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + (setenv "UDEV_HWDB_PATH" #$hardware) + (invoke #+(file-append udev "/bin/udevadm") + "hwdb" + "--update" + "-o" #$output)))))) `(("udev" ,(file-union "udev" `(("udev.conf" ,udev.conf) ("rules.d" ,(udev-rules-union (cons* udev kvm-udev-rule - rules))))))))) + rules))) + ("hwdb.bin" ,hwdb.bin)))))))) (define udev-service-type (service-type (name 'udev) @@ -2423,12 +2457,15 @@ item of @var{packages}." udev-shepherd-service) (service-extension etc-service-type udev-etc))) (compose concatenate) ;concatenate the list of rules - (extend (lambda (config rules) + (extend (lambda (config extensions) (let ((initial-rules - (udev-configuration-rules config))) + (udev-configuration-rules config)) + (initial-hardware + (udev-configuration-hardware config))) (udev-configuration (inherit config) - (rules (append initial-rules rules)))))) + (rules (append initial-rules extensions)) + (hardware (append initial-hardware extensions)))))) (default-value (udev-configuration)) (description "Run @command{udev}, which populates the @file{/dev} @@ -2463,6 +2500,19 @@ instance." (description "This service adds udev rules.")))) (service type #f))) +(define (udev-hardware-service name hardware-files) + "Return a service that extends udev-service-type with HARDWARE-FILES, named +NAME-udev-hardware." + (let* ((name (symbol-append name '-udev-hardware)) + (udev-extension (const (list hardware-files))) + (type (service-type + (name name) + (extensions (list + (service-extension + udev-service-type udev-extension))) + (description "This service adds udev hardware files.")))) + (service type #f))) + (define (swap-space->shepherd-service-name space) (let ((target (swap-space-target space))) (symbol-append 'swap- |