From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 4PYBHVyU+WEbkgAAgWs5BA (envelope-from ) for ; Tue, 01 Feb 2022 21:13:16 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id EH2pGVyU+WGJ3AAAauVa8A (envelope-from ) for ; Tue, 01 Feb 2022 21:13:16 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9877CE63E for ; Tue, 1 Feb 2022 21:13:15 +0100 (CET) Received: from localhost ([::1]:48876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEzWc-0006mB-Nv for larch@yhetil.org; Tue, 01 Feb 2022 15:13:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nExdL-0000gt-6E for bug-guix@gnu.org; Tue, 01 Feb 2022 13:12:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:51117) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nExdK-0007UZ-Qs for bug-guix@gnu.org; Tue, 01 Feb 2022 13:12:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nExdK-0004Y1-H5 for bug-guix@gnu.org; Tue, 01 Feb 2022 13:12:02 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#47681: [PATCH] services: udev: Use a fixed location for the rules directory and config. References: <87eefjdsge.fsf@gmail.com> In-Reply-To: <87eefjdsge.fsf@gmail.com> Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Tue, 01 Feb 2022 18:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47681 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 47681@debbugs.gnu.org Received: via spool by 47681-submit@debbugs.gnu.org id=B47681.164373907917428 (code B ref 47681); Tue, 01 Feb 2022 18:12:02 +0000 Received: (at 47681) by debbugs.gnu.org; 1 Feb 2022 18:11:19 +0000 Received: from localhost ([127.0.0.1]:44020 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nExca-0004Wx-0y for submit@debbugs.gnu.org; Tue, 01 Feb 2022 13:11:19 -0500 Received: from mail-qk1-f173.google.com ([209.85.222.173]:42984) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nExcU-0004Wc-L3 for 47681@debbugs.gnu.org; Tue, 01 Feb 2022 13:11:14 -0500 Received: by mail-qk1-f173.google.com with SMTP id m25so14929361qka.9 for <47681@debbugs.gnu.org>; Tue, 01 Feb 2022 10:11:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jyKLHfoynUJBuAiojt01ANhaCITymoynaSwhsCwaq5c=; b=YAs18tkv+nWlHIVXY02jUXwzoZitir47/fHijrwjoQWbhbHJEvF8Mev5lt9edgYXCN H5u2fivPsIPz7A71wkp15qddnFi4BUm3BjhZA4hJDR6bCyzyjaHlXtChh+X2MrmUaDim iv4O8YRZRwc6s58uuPc4rfblf7rsV/WrV6qQfyBsmuQRD3jTzGwPMmMxVvYMb19uOMyg TPyfwrDGmkDJBvzyFHrAhlIaiVPwMirEQwLnwGxs3CFY1jnDVj51dVvDhEdGUJH8Zfdx bbzr2xmDVHRKCAQo48SitmhlWD6L1trmx/Ld1yE6zHc26WskALItQHTaCUHhWwzXjMjF 33Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jyKLHfoynUJBuAiojt01ANhaCITymoynaSwhsCwaq5c=; b=1PM71C2t9tRFKxif4lJrDHsg6tsB3erWl3UCCtSW3m1kbB/W1Ck9vhxctM0cPcXbV8 UdVrVGx+gWjSQcc5d9zcEfxLtw5YoR5mPLczrhlvBU5Y+F6ZwUhRs5is2f7owy8gOBQq 196KNLqgvMf2X5ZaMGrvI5absdNH9ECYnVB5VQBh/RG3GTgMrC5dV6PaFUmobXCUjhiI J4qzqC/EHPJc2hkafveOwhKxCOd5Kv7rJVLy7vgEnVq0+mfyO+qDes9o7nKoKwmhl1rJ TFufEosDurvUkWG+VHRX31obajXvyIZP6GXQqrySAuMgvINtDhYTjGF7g8Rl9SculkIj uZ1w== X-Gm-Message-State: AOAM533kByvJEXWmONHyX3wQD0da4jXz5KC0GGZe41tif3UoUYRE6aoX LxtiDMaGNrH9gl2TLdfx1eTQGRSBWhI= X-Google-Smtp-Source: ABdhPJzT+KwOqDHEJJofGdD//3x8O/UyP5+fXisXKjSuigXSWQL7b5wdQFV7ashmgfX1QTclu4XpCA== X-Received: by 2002:a05:620a:24d0:: with SMTP id m16mr5704518qkn.558.1643739064670; Tue, 01 Feb 2022 10:11:04 -0800 (PST) Received: from localhost.localdomain (dsl-149-193.b2b2c.ca. [66.158.149.193]) by smtp.gmail.com with ESMTPSA id s4sm11668142qko.113.2022.02.01.10.11.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 10:11:04 -0800 (PST) From: Maxim Cournoyer Date: Tue, 1 Feb 2022 13:10:33 -0500 Message-Id: <20220201181033.27473-1-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxim Cournoyer Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1643746395; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=jyKLHfoynUJBuAiojt01ANhaCITymoynaSwhsCwaq5c=; b=EQioNfHREgk/3JmZVQCnQLqskkYcRMrb1+JJSXze9TLYQ4PJZsL6UCCeoEyo8zSLxI5Dm3 /xFCGexd0m+hMcn5NXC+4iGg1WSXcSal7mqbwiaykVSPjTDj2YZCpV5Jisbnb2ksXFY08q SUA9f0oNqpG0/y/WUsGvZtjpOwKYzvlcu9j+TSf7UBixuwmY/iz9MAqUVF1ULsrSR4/K4A FJV23SQpppDYnld17tNA9jROI3iRs89sEmMRUx4xJHqYKz2PXVI1HXhkEHipRecks5vpYg Y8cbEFcmk86DPprXMmAHO2G988GKJwyYXix/Tr4jU221Pb5hkUx1y0BweE0P+A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1643746395; a=rsa-sha256; cv=none; b=oICJCzJSo5FUtGv/3IFXR5OV3S2BPxbBdnAyrz5NlC2UdQzeMy4+vOjYxapQlvpxIxod0Z fFlvHCkadOyJjpazRiwvT2AunX0hnCvo7vPWKYkQsjCC6QwiQMQeQ8pliIocc9NKQDTE97 771keJwwB3omeELYYXgqtcFGnvIdApdoSLH5T87C5EPVxCnv6YAdB40S7SP+vDuiC0id1y qljFG2Y8CmH4bp5HrGQcFISdRhvhySgjkIKMMvY/09T90rrVTxjkquT8jhwcUoooNYh5wb YhkEAxk1p0XNlQmZq5aTyWx0cu8kxnEfiNr7Xh8j0apuAxTBd6qDlaRgemkTCg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=YAs18tkv; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.83 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=YAs18tkv; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 9877CE63E X-Spam-Score: -3.83 X-Migadu-Scanner: scn0.migadu.com X-TUID: SehEH6vvOAmR Fixes . This change adjusts the location of the udev configuration file and rules directory to a fixed location. Since udev relies on inotify to discover change to its rules directory (/etc/udev/rules.d), by using a fixed directory layout, new udev rules can be automatically picked up without restarting the service. * gnu/services/base.scm (udev-rules-union): Build rules output directly in #$output. (udev-shepherd-service)[start]: Adjust the UDEV_CONFIG_FILE and EUDEV_RULES_DIRECTORY environment variables. [actions]: Remove field. The 'rules' action is no longer useful. (udev.conf): New variable. (udev-etc): New procedure. (udev-service-type): Extend the etc-service-type with it. --- gnu/services/base.scm | 210 +++++++++++++++++++++--------------------- 1 file changed, 104 insertions(+), 106 deletions(-) diff --git a/gnu/services/base.scm b/gnu/services/base.scm index fbd01e84d6..4c8a840156 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -15,7 +15,7 @@ ;;; Copyright © 2020, 2021 Brice Waegeneire ;;; Copyright © 2021 qblade ;;; Copyright © 2021 Hui Lu -;;; Copyright © 2021 Maxim Cournoyer +;;; Copyright © 2021, 2022 Maxim Cournoyer ;;; Copyright © 2022 Guillaume Le Vaillant ;;; ;;; This file is part of GNU Guix. @@ -1995,8 +1995,7 @@ (define (rules-sub-directory directory) (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") + (union-build #$output (filter-map rules-sub-directory '#$packages))))) (computed-file "udev-rules" build)) @@ -2045,116 +2044,115 @@ (define kvm-udev-rule (define udev-shepherd-service ;; Return a for UDEV with RULES. + (match-lambda + (($ udev) + (list + (shepherd-service + (provision '(udev)) + + ;; Udev needs /dev to be a 'devtmpfs' mount so that new device nodes can + ;; be added: see + ;; . + (requirement '(root-file-system)) + + (documentation "Populate the /dev directory, dynamically.") + (start + (with-imported-modules (source-module-closure + '((gnu build linux-boot))) + #~(lambda () + (define udevd + ;; 'udevd' from eudev. + #$(file-append udev "/sbin/udevd")) + + (define (wait-for-udevd) + ;; Wait until someone's listening on udevd's control + ;; socket. + (let ((sock (socket AF_UNIX SOCK_SEQPACKET 0))) + (let try () + (catch 'system-error + (lambda () + (connect sock PF_UNIX "/run/udev/control") + (close-port sock)) + (lambda args + (format #t "waiting for udevd...~%") + (usleep 500000) + (try)))))) + + ;; Allow udev to find the modules. + (setenv "LINUX_MODULE_DIRECTORY" + "/run/booted-system/kernel/lib/modules") + + (let* ((kernel-release + (utsname:release (uname))) + (linux-module-directory + (getenv "LINUX_MODULE_DIRECTORY")) + (directory + (string-append linux-module-directory "/" + kernel-release)) + (old-umask (umask #o022))) + ;; If we're in a container, DIRECTORY might not exist, + ;; for instance because the host runs a different + ;; kernel. In that case, skip it; we'll just miss a few + ;; nodes like /dev/fuse. + (when (file-exists? directory) + (make-static-device-nodes directory)) + (umask old-umask)) + + (let ((pid (fork+exec-command + (list udevd) + #:environment-variables + (cons* + ;; The first one is for udev, the second one for + ;; eudev. + "UDEV_CONFIG_FILE=/etc/udev/udev.conf" + "EUDEV_RULES_DIRECTORY=/etc/udev/rules.d" + (string-append "LINUX_MODULE_DIRECTORY=" + (getenv "LINUX_MODULE_DIRECTORY")) + (default-environment-variables))))) + ;; Wait until udevd is up and running. This appears to + ;; be needed so that the events triggered below are + ;; actually handled. + (wait-for-udevd) + + ;; Trigger device node creation. + (system* #$(file-append udev "/bin/udevadm") + "trigger" "--action=add") + + ;; Wait for things to settle down. + (system* #$(file-append udev "/bin/udevadm") + "settle") + pid)))) + (stop #~(make-kill-destructor)) + + ;; When halting the system, 'udev' is actually killed by + ;; 'user-processes', i.e., before its own 'stop' method was called. + ;; Thus, make sure it is not respawned. + (respawn? #f) + ;; We need additional modules. + (modules `((gnu build linux-boot) ;'make-static-device-nodes' + ,@%default-modules))))))) + +(define udev.conf + (computed-file "udev.conf" + #~(call-with-output-file #$output + (lambda (port) + (format port "udev_rules=\"/etc/udev/rules.d\"~%"))))) + +(define udev-etc (match-lambda (($ udev rules) - (let* ((rules (udev-rules-union (cons* udev kvm-udev-rule rules))) - (udev.conf (computed-file "udev.conf" - #~(call-with-output-file #$output - (lambda (port) - (format port - "udev_rules=\"~a/lib/udev/rules.d\"\n" - #$rules)))))) - (list - (shepherd-service - (provision '(udev)) - - ;; Udev needs /dev to be a 'devtmpfs' mount so that new device nodes can - ;; be added: see - ;; . - (requirement '(root-file-system)) - - (documentation "Populate the /dev directory, dynamically.") - (start - (with-imported-modules (source-module-closure - '((gnu build linux-boot))) - #~(lambda () - (define udevd - ;; 'udevd' from eudev. - #$(file-append udev "/sbin/udevd")) - - (define (wait-for-udevd) - ;; Wait until someone's listening on udevd's control - ;; socket. - (let ((sock (socket AF_UNIX SOCK_SEQPACKET 0))) - (let try () - (catch 'system-error - (lambda () - (connect sock PF_UNIX "/run/udev/control") - (close-port sock)) - (lambda args - (format #t "waiting for udevd...~%") - (usleep 500000) - (try)))))) - - ;; Allow udev to find the modules. - (setenv "LINUX_MODULE_DIRECTORY" - "/run/booted-system/kernel/lib/modules") - - (let* ((kernel-release - (utsname:release (uname))) - (linux-module-directory - (getenv "LINUX_MODULE_DIRECTORY")) - (directory - (string-append linux-module-directory "/" - kernel-release)) - (old-umask (umask #o022))) - ;; If we're in a container, DIRECTORY might not exist, - ;; for instance because the host runs a different - ;; kernel. In that case, skip it; we'll just miss a few - ;; nodes like /dev/fuse. - (when (file-exists? directory) - (make-static-device-nodes directory)) - (umask old-umask)) - - (let ((pid (fork+exec-command (list udevd) - #:environment-variables - (cons* - ;; The first one is for udev, the second one for - ;; eudev. - (string-append "UDEV_CONFIG_FILE=" #$udev.conf) - (string-append "EUDEV_RULES_DIRECTORY=" - #$(file-append - rules "/lib/udev/rules.d")) - (string-append "LINUX_MODULE_DIRECTORY=" - (getenv "LINUX_MODULE_DIRECTORY")) - (default-environment-variables))))) - ;; Wait until udevd is up and running. This appears to - ;; be needed so that the events triggered below are - ;; actually handled. - (wait-for-udevd) - - ;; Trigger device node creation. - (system* #$(file-append udev "/bin/udevadm") - "trigger" "--action=add") - - ;; Wait for things to settle down. - (system* #$(file-append udev "/bin/udevadm") - "settle") - pid)))) - (stop #~(make-kill-destructor)) - - ;; When halting the system, 'udev' is actually killed by - ;; 'user-processes', i.e., before its own 'stop' method was called. - ;; Thus, make sure it is not respawned. - (respawn? #f) - ;; We need additional modules. - (modules `((gnu build linux-boot) ;'make-static-device-nodes' - ,@%default-modules)) - - (actions (list (shepherd-action - (name 'rules) - (documentation "Display the directory containing -the udev rules in use.") - (procedure #~(lambda (_) - (display #$rules) - (newline)))))))))))) + `(("udev" + ,(file-union + "udev" `(("udev.conf" ,udev.conf) + ("rules.d" ,(udev-rules-union (cons* udev kvm-udev-rule + rules)))))))))) (define udev-service-type (service-type (name 'udev) (extensions (list (service-extension shepherd-root-service-type - udev-shepherd-service))) - + udev-shepherd-service) + (service-extension etc-service-type udev-etc))) (compose concatenate) ;concatenate the list of rules (extend (lambda (config rules) (match config -- 2.34.0