From b3bdbf48063b7971a9a90ec77669b9cbd13a28e3 Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Fri, 16 May 2025 15:37:55 +0200 Subject: [PATCH] udevCheckHook: init Usage: ```nix nativeBuildInputs = [ udevCheckHook ]; doInstallCheck = true; ``` This hook executes `udevadm verify --resolve-names=never --no-style` on all outputs that have `/etc/udev/rules.d`. This us a logical part of #404323 to check packages that supply udev rules. Note this hook introduces a dependency on `systemdMinimal`, meaning this can't check systemdMinimal or its dependencies. --- pkgs/by-name/ud/udevCheckHook/hook.sh | 27 +++++++++++++++++++++++ pkgs/by-name/ud/udevCheckHook/package.nix | 16 ++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 pkgs/by-name/ud/udevCheckHook/hook.sh create mode 100644 pkgs/by-name/ud/udevCheckHook/package.nix diff --git a/pkgs/by-name/ud/udevCheckHook/hook.sh b/pkgs/by-name/ud/udevCheckHook/hook.sh new file mode 100644 index 000000000000..507e0292b8c8 --- /dev/null +++ b/pkgs/by-name/ud/udevCheckHook/hook.sh @@ -0,0 +1,27 @@ +# shellcheck shell=bash + +udevCheckHook() { + runHook preUdevCheck + echo Executing udevCheckPhase + + # as per nixos/modules/services/hardware/udev.nix: + # - both /lib and /etc is valid paths for udev rules + # - udev rules are expected to be part of the $bin output + # However, not all udev rules are actually in $bin (some are in $lib or $out). + # This means we have to actually check all outputs here. + for output in $(getAllOutputNames); do + for path in etc lib ; do + if [ -d "${!output}/$path/udev/rules.d" ]; then + @udevadm@ verify --resolve-names=never --no-style "${!output}/$path/udev/rules.d" + fi + done + done + + runHook postUdevCheck + echo Finished udevCheckPhase +} + +if [[ -z "${dontUdevCheck-}" ]]; then + echo "Using udevCheckHook" + preInstallCheckHooks+=(udevCheckHook) +fi diff --git a/pkgs/by-name/ud/udevCheckHook/package.nix b/pkgs/by-name/ud/udevCheckHook/package.nix new file mode 100644 index 000000000000..61a82530cdd3 --- /dev/null +++ b/pkgs/by-name/ud/udevCheckHook/package.nix @@ -0,0 +1,16 @@ +{ + lib, + makeSetupHook, + systemdMinimal, +}: + +makeSetupHook { + name = "udev-check-hook"; + substitutions = { + udevadm = lib.getExe' systemdMinimal "udevadm"; + }; + meta = { + description = "check validity of udev rules in outputs"; + maintainers = with lib.maintainers; [ grimmauld ]; + }; +} ./hook.sh