about summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-12-14 18:53:01 +0200
committerFlorian Klink <flokli@flokli.de>2023-12-14 19:14:13 +0200
commitfe446f8bb4aca0c63fca176dfa2e7be75c5ae360 (patch)
tree72ecf5157cc99511bb0115bacc391d22a2b7d6bb /nixos/modules
parent8e23dec5ac5ebc36057e980d4e6a3eb6a44da74b (diff)
downloadnixlib-fe446f8bb4aca0c63fca176dfa2e7be75c5ae360.tar
nixlib-fe446f8bb4aca0c63fca176dfa2e7be75c5ae360.tar.gz
nixlib-fe446f8bb4aca0c63fca176dfa2e7be75c5ae360.tar.bz2
nixlib-fe446f8bb4aca0c63fca176dfa2e7be75c5ae360.tar.lz
nixlib-fe446f8bb4aca0c63fca176dfa2e7be75c5ae360.tar.xz
nixlib-fe446f8bb4aca0c63fca176dfa2e7be75c5ae360.tar.zst
nixlib-fe446f8bb4aca0c63fca176dfa2e7be75c5ae360.zip
nixos/udev: allow /bin/sh in udev rules
Using `/bin/sh` in udev rules is fine (as it's guaranteed to point to a
(bash) shell on NixOS), and actually is better than hardcoding absolute
paths, at least in cases where these rules are also added to the
(systemd-based) initrd (via boot.initrd.services.udev.rules).

To allow this, we need to update the check routine that assembles the
list of files needing fixup, to explicitly exclude `/bin/sh` occurences.

To do this, we convert the pattern to a PCRE regex (which requires "/"
to be escaped), and add `(?!/bin/sh\b)` as a negative lookahead.

This subsequently allows udev rules to (start using) `/bin/sh` again, so
they'll work in-initrd.
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/services/hardware/udev.nix3
1 files changed, 2 insertions, 1 deletions
diff --git a/nixos/modules/services/hardware/udev.nix b/nixos/modules/services/hardware/udev.nix
index 311f60795bae..670b9087f110 100644
--- a/nixos/modules/services/hardware/udev.nix
+++ b/nixos/modules/services/hardware/udev.nix
@@ -112,7 +112,8 @@ let
       echo "OK"
 
       filesToFixup="$(for i in "$out"/*; do
-        grep -l '\B\(/usr\)\?/s\?bin' "$i" || :
+        # list all files referring to (/usr)/bin paths, but allow references to /bin/sh.
+        grep -P -l '\B(?!\/bin\/sh\b)(\/usr)?\/bin(?:\/.*)?' "$i" || :
       done)"
 
       if [ -n "$filesToFixup" ]; then