From 74dbae8968f478438a3f1f677eb44db06b26b201 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 25 Apr 2024 16:33:28 +0200 Subject: [PATCH] kernel: Test laziness of certain arguments --- pkgs/os-specific/linux/kernel/generic.nix | 27 +++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/linux/kernel/generic.nix b/pkgs/os-specific/linux/kernel/generic.nix index 77c6ee031956..579f1cd1f4f3 100644 --- a/pkgs/os-specific/linux/kernel/generic.nix +++ b/pkgs/os-specific/linux/kernel/generic.nix @@ -1,5 +1,6 @@ { buildPackages , callPackage +, emptyFile , perl , bison ? null , flex ? null @@ -15,6 +16,7 @@ , nixosTests }@args': +let overridableKernel = lib.makeOverridable ({ # The kernel source tarball. src @@ -241,7 +243,28 @@ kernel.overrideAttrs (finalAttrs: previousAttrs: { + toString (lib.attrNames (lib.toFunction args { })) ) overridableKernel; }; - in [ (nixosTests.kernel-generic.passthru.testsForKernel overridableKernel) ] ++ kernelTests; + versionDoesNotDependOnPatchesEtc = + builtins.seq + (import ./generic.nix args' (args // ( + let explain = attrName: + '' + The ${attrName} attribute must be able to access the kernel.version attribute without an infinite recursion. + That means that the kernel attrset (attrNames) and the kernel.version attribute must not depend on the ${attrName} argument. + The fact that this exception is raised shows that such a dependency does exist. + This is a problem for the configurability of ${attrName} in version-aware logic such as that in NixOS. + Strictness can creep in through optional attributes, or assertions and warnings that run as part of code that shouldn't access what is checked. + ''; + in { + kernelPatches = throw (explain "kernelPatches"); + structuredExtraConfig = throw (explain "structuredExtraConfig"); + modDirVersion = throw (explain "modDirVersion"); + }))).version + emptyFile; + in [ + (nixosTests.kernel-generic.passthru.testsForKernel overridableKernel) + versionDoesNotDependOnPatchesEtc + ] ++ kernelTests; }; -})) +})); +in overridableKernel