From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxxhv-0007l1-DH for guix-patches@gnu.org; Fri, 29 Sep 2017 12:00:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxxhq-0004EC-Vv for guix-patches@gnu.org; Fri, 29 Sep 2017 12:00:07 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:58978) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dxxhq-0004Dz-R4 for guix-patches@gnu.org; Fri, 29 Sep 2017 12:00:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dxxhq-0001Pg-KY for guix-patches@gnu.org; Fri, 29 Sep 2017 12:00:02 -0400 Subject: [bug#28647] [PATCH] services: base: Add file->udev-rule function. Resent-Message-ID: Received: from eggs.gnu.org ([2001:4830:134:3::10]:32927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxxgv-000771-He for guix-patches@gnu.org; Fri, 29 Sep 2017 11:59:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxxgr-0003a0-Kj for guix-patches@gnu.org; Fri, 29 Sep 2017 11:59:05 -0400 Received: from mail-it0-x22c.google.com ([2607:f8b0:4001:c0b::22c]:50247) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dxxgr-0003ZX-B3 for guix-patches@gnu.org; Fri, 29 Sep 2017 11:59:01 -0400 Received: by mail-it0-x22c.google.com with SMTP id y138so259358itc.5 for ; Fri, 29 Sep 2017 08:59:01 -0700 (PDT) Received: from apteryx (104-222-112-128.cpe.teksavvy.com. [104.222.112.128]) by smtp.gmail.com with ESMTPSA id i131sm1477658itf.18.2017.09.29.08.58.59 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 Sep 2017 08:58:59 -0700 (PDT) From: Maxim Cournoyer Date: Fri, 29 Sep 2017 11:58:58 -0400 Message-ID: <87lgkxxzr1.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 28647@debbugs.gnu.org --=-=-= Content-Type: text/plain Hello, While experimenting with udev rules, I found a need to be able to pass file-like objects containing udev rules to the udev-service. This patch implements a `file->udev-rule' method that does just that. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-services-base-Add-file-udev-rule-function.patch >From 050e96b3325f851f3118de0c881d25796d76049b Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Wed, 27 Sep 2017 21:33:25 -0400 Subject: [PATCH] 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. --- doc/guix.texi | 15 ++++++++++++--- gnu/services/base.scm | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index fff3fbd5f..a073dccb5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -9707,11 +9707,20 @@ Return a service that runs the Guix build daemon according to @var{config}. @end deffn -@deffn {Scheme Procedure} udev-service [#:udev udev] +@deffn {Scheme Procedure} udev-service [#:udev @var{eudev} #:rules @code{'()}] Run @var{udev}, which populates the @file{/dev} directory dynamically. +Packages can be included in the @var{rules} list in order to extend the +udev rules with the definitions found under their +@file{lib/udev/rules.d} sub-directory. + +The functions @code{udev-rules} and @code{file->udev-rules} from +@code{(gnu services base)} can be used to create rule objects based on a +string or a file-like object, respectively. Those rule objects can be +passed to udev-service just like packages. + @end deffn -@deffn {Scheme Procedure} urandom-seed-service @var{#f} +@deffn {Scheme Procedure} urandom-seed-service Save some entropy in @var{%random-seed-file} to seed @file{/dev/urandom} when rebooting. @end deffn @@ -9823,7 +9832,7 @@ to add @var{device} to the kernel's entropy pool. The service will fail if @cindex session limits @cindex ulimit @cindex priority -@deffn {Scheme Procedure} pam-limits-service [#:limits @var{limits}] +@deffn {Scheme Procedure} pam-limits-service [#:limits @code{'()}] Return a service that installs a configuration file for the @uref{http://linux-pam.org/Linux-PAM-html/sag-pam_limits.html, diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 64620a9b0..711167a2f 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -71,6 +71,7 @@ udev-service-type udev-service udev-rule + file->udev-rule login-configuration login-configuration? @@ -1628,6 +1629,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, -- 2.14.1 --=-=-= Content-Type: text/plain Below is an operating-system declaration that makes use of it. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=config.scm Content-Description: Sample config using the new method. ;; This is an operating system configuration template ;; for a "desktop" setup without full-blown desktop ;; environments. (use-modules (gnu) (gnu system nss) (gnu services) (gnu system shadow) ;for user-group (guix download) ;for url-fetch (guix gexp) ;for file-append (guix packages) ;for origin (guix store) ;for %default-substitute-urls (srfi srfi-1)) ;for the remove function (use-service-modules base ;for nscd-service-type desktop networking ;for wicd-service-type ssh) ;for lsh-service (use-package-modules admin ;for wpa-supplicant ratpoison certs) (define 51-android-udev.rules (let ((version "20170910")) (origin (method url-fetch) (uri (string-append "https://raw.githubusercontent.com/M0Rf30/" "android-udev-rules/" version "/51-android.rules")) (sha256 (base32 "0lmmagpyb6xsq6zcr2w1cyx9qmjqmajkvrdbhjx32gqf1d9is003"))))) (operating-system (host-name "apteryx") (timezone "America/Montreal") ;America/Los_Angeles, Asia/Tokyo (locale "en_US.UTF-8") ;; Assuming /dev/sdX is the target hard disk, and "my-root" ;; is the label of the target root file system. (bootloader (bootloader-configuration (bootloader grub-bootloader) (target "/dev/sda"))) (file-systems (cons (file-system (device "my-root") (title 'label) (mount-point "/") (type "ext4")) %base-file-systems)) (users (cons (user-account (name "maxim") (comment "Maxim Cournoyer") (group "users") (supplementary-groups '("lp" ;for bluetooth "adbusers" ;for adb "wheel" "netdev" "audio" "video")) (home-directory "/home/maxim")) %base-user-accounts)) ;; Add plugdev to %base-groups (groups (cons (user-group (system? #t) (name "adbusers")) %base-groups)) ;; Add a bunch of window managers; we can choose one at ;; the log-in screen with F1. (packages (cons* ratpoison nss-certs ;for HTTPS access %base-packages)) ;; Use the "desktop" services, which include the X11 ;; log-in service and more. (services (cons* (bluetooth-service #:auto-enable? #t) (modify-services %desktop-services ;; Add a couple extra substitute servers. (guix-service-type config => (guix-configuration (inherit config) (substitute-urls (cons* "https://bayfront.guixsd.org" "https://berlin.guixsd.org" %default-substitute-urls)))) ;; Enable using adb as a simple user with a multitude of devices. (udev-service-type config => (udev-configuration (inherit config) (rules (cons* (file->udev-rule "51-android-udev.rules" 51-android-udev.rules) (udev-configuration-rules config)))))))) ;; Allow resolution of '.local' host names with mDNS. (name-service-switch %mdns-host-lookup-nss)) --=-=-= Content-Type: text/plain Thanks, Maxim --=-=-=--