gnu: eudev: Build with udevrulesdir pointing to /etc/udev/rules.d.

Prior to this change, only the udev rules installed to eudev's prefix were
consulted by tools such as udevadm, leading to problems such as when
configuring network interfaces, or attempting to override its default rules.

While our custom eudev patch adding support for the EUDEV_RULES_DIRECTORY
environment variable could have been refined to take precedence over the
package's configured udevrulesdir, this was not pursued for the following
reasons:

1. Due to eudev's using inotify to detect new rules, the EUDEV_RULES_DIRECTORY
is fixed in Guix System, per commit e9fa17eb98 ("services: udev: Use a fixed
location for the rules directory and config.")

2. Users would have had to set EUDEV_RULES_DIRECTORY to the fixed directory
themselves to have udevadm work as expected, which is inconvenient.

3. This simple solution is already implemented and tested in NixPkgs.

* gnu/packages/linux.scm (eudev) [source]: Remove custom patch.
[arguments] <#:make-flags>: New argument.
<#:phases>: Override install phase to alter installation make flags.
* gnu/services/base.scm (udev-shepherd-service): Do not set
EUDEV_RULES_DIRECTORY environment variable.
* gnu/packages/patches/eudev-rules-directory.patch: Delete file.
* gnu/local.mk (dist_patch_DATA): De-register it.

Fixes: https://issues.guix.gnu.org/63508
Reported-by: Felix Lechner <felix.lechner@lease-up.com>
Change-Id: Ib8698f4b452f6fd0951bcd71831705b1be85e6e0
This commit is contained in:
Maxim Cournoyer 2025-02-06 10:17:20 +09:00 committed by Christopher Baines
parent c17c6b9820
commit dedeb90501
No known key found for this signature in database
GPG key ID: 5E28A33B0B84F577
4 changed files with 23 additions and 47 deletions

View file

@ -1251,7 +1251,6 @@ dist_patch_DATA = \
%D%/packages/patches/erlang-man-path.patch \
%D%/packages/patches/esmini-use-pkgconfig.patch \
%D%/packages/patches/esmtp-add-lesmtp.patch \
%D%/packages/patches/eudev-rules-directory.patch \
%D%/packages/patches/exercism-disable-self-update.patch \
%D%/packages/patches/expat-CVE-2024-45490.patch \
%D%/packages/patches/expat-CVE-2024-45491.patch \

View file

@ -4897,12 +4897,14 @@ to the in-kernel OOM killer.")
(file-name (git-file-name name version))
(sha256
(base32
"1f6lz57igi7iw2ls3fpzgw42bfznam4nf9368h7x8yf1mb737yxz"))
(patches (search-patches "eudev-rules-directory.patch"))
(modules '((guix build utils)))))
"1f6lz57igi7iw2ls3fpzgw42bfznam4nf9368h7x8yf1mb737yxz"))))
(build-system gnu-build-system)
(arguments
(list
;; The binary should be built to look for its rules under
;; /etc/udev/rules.d, which is where the udev-shepherd-service keeps
;; them.
#:make-flags #~(list "udevrulesdir=/etc/udev/rules.d")
#:phases
#~(modify-phases %standard-phases
(add-before 'bootstrap 'patch-file-names
@ -4946,7 +4948,20 @@ to the in-kernel OOM killer.")
;; such that Libtool looks for it in the usual places.
(substitute* (string-append #$output "/lib/libudev.la")
(("old_library=.*")
"old_library=''\n"))))))
"old_library=''\n")))))
(replace 'install
(lambda* (#:key make-flags #:allow-other-keys #:rest args)
;; Although the runtime udevrulesdir is set to
;; /etc/udev/rules.d, the package should provide its default
;; rules under $libdir/udev/rules.d.
(let* ((default-udev-rules.d (string-append #$output
"/lib/udev/rules.d"))
(make-flags (cons (string-append "udevrulesdir="
default-udev-rules.d)
(delete "udevrulesdir=/etc/udev/rules.d"
make-flags))))
(apply (assoc-ref %standard-phases 'install)
`(,@args #:make-flags ,make-flags))))))
#:configure-flags
#~(list "--enable-manpages"
;; By default, autoconf uses $prefix/etc. The udev-service-type

View file

@ -1,37 +0,0 @@
Add $EUDEV_RULES_DIRECTORY to the list of rules directories.
The old udev 182 supported $UDEV_CONFIG_FILE, which in turn allowed
the search path to be customized, but eudev no longer has this, hence
this hack.
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -48,16 +48,11 @@ struct uid_gid {
};
};
-static const char* const rules_dirs[] = {
+static const char* rules_dirs[] = {
UDEV_CONF_DIR "/rules.d",
UDEV_RULES_DIR,
- UDEV_ROOT_RUN "/udev/rules.d",
UDEV_LIBEXEC_DIR "/rules.d",
-#ifdef HAVE_SPLIT_USR
- "/lib/udev/rules.d",
- "/usr/lib/udev/rules.d",
-#endif
- "/usr/local/lib/udev/rules.d",
+ NULL, /* placeholder for $EUDEV_RULES_DIRECTORY */
NULL};
struct udev_rules {
@@ -1718,6 +1713,9 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) {
udev_rules_check_timestamp(rules);
+ /* Allow the user to specify an additional rules directory. */
+ rules_dirs[3] = getenv("EUDEV_RULES_DIRECTORY");
+
r = conf_files_list_strv(&files, ".rules", NULL, rules_dirs);
if (r < 0) {
log_error_errno(r, "failed to enumerate rules files: %m");

View file

@ -2562,7 +2562,6 @@ item of PACKAGES."
(list udevd)
#:environment-variables
(cons*
"EUDEV_RULES_DIRECTORY=/etc/udev/rules.d"
(string-append "LINUX_MODULE_DIRECTORY="
(getenv "LINUX_MODULE_DIRECTORY"))
(default-environment-variables)))))