[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/06: services: base: Add file->udev-rule function.

From: Ludovic Courtès
Subject: 01/06: services: base: Add file->udev-rule function.
Date: Mon, 23 Oct 2017 01:09:10 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 6e644cfdb38b74a83bfc133807b5f503b54e8c73
Author: Maxim Cournoyer <address@hidden>
Date:   Wed Sep 27 21:33:25 2017 -0400

    services: base: Add file->udev-rule function.
    This function allows passing a file-like object to the udev service.
    * gnu/services/base.scm (file->udev-rule): New function.
    * doc/guix.texi (Base Services): Document it.
    Signed-off-by: Ludovic Courtès <address@hidden>
 doc/guix.texi         | 113 ++++++++++++++++++++++++++++++++++++++++++--------
 gnu/services/base.scm |  17 ++++++++
 2 files changed, 112 insertions(+), 18 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 7d7d556..2ccba98 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -9790,35 +9790,112 @@ Return a service that runs the Guix build daemon 
according to
 @end deffn
address@hidden udev-service
address@hidden udev-rule
address@hidden {Scheme Procedure} udev-service [#:udev @var{udev}] [#:rules 
address@hidden {Scheme Procedure} udev-service [#:udev @var{eudev} #:rules 
 Run @var{udev}, which populates the @file{/dev} directory dynamically.
-Additional udev rules can be provided as a list of files through the
address@hidden variable.  The procedure @var{udev-rule} simplifies the
-creation of these rule files.
+udev rules can be provided as a list of files through the @var{rules}
+variable.  The procedures @var{udev-rule} and @var{file->udev-rule} from
address@hidden(gnu services base)} simplify the creation of such rule files.
address@hidden {Scheme Procedure} udev-rule address@hidden @var{contents}]
+Return a udev-rule file named @var{file-name} containing the rules
+defined by the @var{contents} literal.
 In the following example, a rule for a USB device is defined to be
-stored in the file @file{90-usb-thing.rules}, and the default
address@hidden is extended with it.  The rule runs a script upon
-detecting a USB device with a given product identifier.
+stored in the file @file{90-usb-thing.rules}.  The rule runs a script
+upon detecting a USB device with a given product identifier.
 (define %example-udev-rule
-  (udev-rule "90-usb-thing.rules"
-             "ACTION==\"add\", SUBSYSTEM==\"usb\", 
address@hidden@}==\"Example\", RUN+=\"/path/to/script\""))
+  (udev-rule
+    "90-usb-thing.rules"
+    (string-append "ACTION==\"add\", SUBSYSTEM==\"usb\", "
+                   "address@hidden@}==\"Example\", "
+                   "RUN+=\"/path/to/script\"")))
address@hidden example
address@hidden deffn
+Here we show how the default @var{udev-service} can be extended with it.
+ ;; @dots{}
+ (services
+ (modify-services %desktop-services
+   (udev-service-type config =>
+     (udev-configuration (inherit config)
+      (rules (append (udev-configuration-rules config)
+                     (list %example-udev-rule))))))))
address@hidden example
address@hidden {Scheme Procedure} file->udev-rule address@hidden @var{file}]
+Return a udev file named @var{file-name} containing the rules defined
+within @var{file}, a file-like object.
+The following example showcases how we can use an existing rule file.
+(use-modules (guix download)     ;for url-fetch
+             (guix packages)     ;for origin
+             ;; @dots{})
+(define %android-udev-rules
+  (file->udev-rule
+    "51-android-udev.rules"
+    (let ((version "20170910"))
+      (origin
+       (method url-fetch)
+       (uri (string-append "";
+                           "android-udev-rules/" version "/51-android.rules"))
+       (sha256
+        (base32 "0lmmagpyb6xsq6zcr2w1cyx9qmjqmajkvrdbhjx32gqf1d9is003"))))))
address@hidden example
address@hidden deffn
+Additionally, Guix package definitions can be included in @var{rules} in
+order to extend the udev rules with the definitions found under their
address@hidden/udev/rules.d} sub-directory.  In lieu of the previous
address@hidden>udev-rule} example, we could have used the
address@hidden package which exists in Guix in the @code{(gnu
+packages android)} module.
+The following example shows how to use the @var{android-udev-rules}
+package so that the Android tool @command{adb} can detect devices
+without root privileges.  It also details how to create the
address@hidden group, which is required for the proper functioning of
+the rules defined within the @var{android-udev-rules} package.  To
+create such a group, we must define it both as part of the
address@hidden of our @var{user-account} declaration, as
+well as in the @var{groups} field of the @var{operating-system} record.
+(use-modules (gnu packages android)  ;for android-udev-rules
+             (gnu system shadow)     ;for user-group
+             ;; @dots{})
   ;; @dots{}
-  (services (modify-services %desktop-services
-              (udev-service-type config =>
-                (udev-configuration (inherit config)
-                  (rules (append (udev-configuration-rules config)
-                                 (list %example-udev-rule))))))))
+  (users (cons (user-acount
+                ;; @dots{}
+                (supplementary-groups
+                 '("adbusers"   ;for adb
+                   "wheel" "netdev" "audio" "video"))
+                ;; @dots{})))
+  (groups (cons (user-group (system? #t) (name "adbusers"))
+                %base-groups))
+  ;; @dots{}
+  (services
+    (modify-services %desktop-services
+      (udev-service-type config =>
+       (udev-configuration (inherit config)
+       (rules (cons* android-udev-rules
+              (udev-configuration-rules config))))))))
 @end example
 @end deffn
address@hidden {Scheme Procedure} urandom-seed-service @var{#f}
address@hidden {Scheme Procedure} urandom-seed-service
 Save some entropy in @var{%random-seed-file} to seed @file{/dev/urandom}
 when rebooting.
 @end deffn
@@ -9930,7 +10007,7 @@ to add @var{device} to the kernel's entropy pool.  The 
service will fail if
 @cindex session limits
 @cindex ulimit
 @cindex priority
address@hidden {Scheme Procedure} pam-limits-service [#:limits @var{limits}]
address@hidden {Scheme Procedure} pam-limits-service [#:limits @code{'()}]
 Return a service that installs a configuration file for the
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 541ca76..b605614 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -71,6 +71,7 @@
+            file->udev-rule
@@ -1630,6 +1631,22 @@ item of @var{packages}."
                          (lambda (port)
                            (display #$contents port)))))))
+(define (file->udev-rule file-name file)
+  "Return a directory with a udev rule 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 file-copy-dest
+                         (string-append rules.d "/" #$file-name))
+                       (mkdir-p rules.d)
+                       (copy-file #$file file-copy-dest)))))
 (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,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]