From 1461a8401c9a489429b770e4a2fe455af50a53e4 Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Wed, 21 May 2025 13:44:58 +0200 Subject: [PATCH] udevCheckHook: guard platform It is technically possible to guard all udevCheckHook usages behind `lib.optionals (lib.meta.availableOn stdenv.buildPlatform systemdMinimal)`. However, doing this is hard to read, clunky, and hard to discover. *Not* doing such a guard would mean cross-compilation darwin -> linux breaks. The workaround here is to just accept any udev rules if they can't be properly checked. --- pkgs/by-name/ud/udevCheckHook/hook.sh | 2 +- pkgs/by-name/ud/udevCheckHook/package.nix | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/ud/udevCheckHook/hook.sh b/pkgs/by-name/ud/udevCheckHook/hook.sh index 507e0292b8c89..bdb8e9c1f746f 100644 --- a/pkgs/by-name/ud/udevCheckHook/hook.sh +++ b/pkgs/by-name/ud/udevCheckHook/hook.sh @@ -21,7 +21,7 @@ udevCheckHook() { echo Finished udevCheckPhase } -if [[ -z "${dontUdevCheck-}" ]]; then +if [[ -z "${dontUdevCheck-}" && -n "@udevadm@" ]]; 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 index 61a82530cdd33..261a503595eab 100644 --- a/pkgs/by-name/ud/udevCheckHook/package.nix +++ b/pkgs/by-name/ud/udevCheckHook/package.nix @@ -2,12 +2,20 @@ lib, makeSetupHook, systemdMinimal, + udev, + stdenv, }: - +let + # udev rules can only be checked if systemd (specifically, 'udevadm') can be executed on build platform + # if udev is not available on hostPlatform, there is no point in checking rules + applyHook = + lib.meta.availableOn stdenv.hostPlatform udev + && lib.meta.availableOn stdenv.buildPlatform systemdMinimal; +in makeSetupHook { name = "udev-check-hook"; substitutions = { - udevadm = lib.getExe' systemdMinimal "udevadm"; + udevadm = if applyHook then lib.getExe' systemdMinimal "udevadm" else ""; }; meta = { description = "check validity of udev rules in outputs";