From fe446f8bb4aca0c63fca176dfa2e7be75c5ae360 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 14 Dec 2023 18:53:01 +0200 Subject: [PATCH 1/2] 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. --- nixos/modules/services/hardware/udev.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From 74461420f9412c02dff402b7701e303ba852c4cf Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 14 Dec 2023 19:09:57 +0200 Subject: [PATCH 2/2] bcache-tools: don't patch path to /bin/sh This will make these udev rules not work in the systemd-based initrd, which only has /bin/sh. --- pkgs/tools/filesystems/bcache-tools/default.nix | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkgs/tools/filesystems/bcache-tools/default.nix b/pkgs/tools/filesystems/bcache-tools/default.nix index f6dfdd84d8c4..58f6a05992e9 100644 --- a/pkgs/tools/filesystems/bcache-tools/default.nix +++ b/pkgs/tools/filesystems/bcache-tools/default.nix @@ -35,10 +35,6 @@ stdenv.mkDerivation rec { "UDEVLIBDIR=${placeholder "out"}/lib/udev/" ]; - preBuild = '' - sed -e "s|/bin/sh|${bash}/bin/sh|" -i *.rules - ''; - preInstall = '' mkdir -p "$out/sbin" "$out/lib/udev/rules.d" "$out/share/man/man8" '';