From 3e83fe9aa593bc514d948f83becd6e8e270fc774 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 25 Apr 2024 16:33:58 +0200 Subject: [PATCH] kernel: Make lazier (fix infinite recursion) --- pkgs/os-specific/linux/kernel/generic.nix | 10 +++++++--- pkgs/os-specific/linux/kernel/manual-config.nix | 9 ++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pkgs/os-specific/linux/kernel/generic.nix b/pkgs/os-specific/linux/kernel/generic.nix index 579f1cd1f4f3..0e2d85a0971d 100644 --- a/pkgs/os-specific/linux/kernel/generic.nix +++ b/pkgs/os-specific/linux/kernel/generic.nix @@ -213,11 +213,15 @@ let }; # end of configfile derivation kernel = (callPackage ./manual-config.nix { inherit lib stdenv buildPackages; }) (basicArgs // { - inherit kernelPatches randstructSeed extraMakeFlags extraMeta configfile; + inherit kernelPatches randstructSeed extraMakeFlags extraMeta configfile modDirVersion; pos = builtins.unsafeGetAttrPos "version" args; - config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; } // lib.optionalAttrs withRust { CONFIG_RUST = "y"; }; - } // lib.optionalAttrs (modDirVersion != null) { inherit modDirVersion; }); + config = { + CONFIG_MODULES = "y"; + CONFIG_FW_LOADER = "m"; + CONFIG_RUST = lib.mkIf withRust "y"; + }; + }); in kernel.overrideAttrs (finalAttrs: previousAttrs: { diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index 5b222c4b45ef..cab04ad0c7d8 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -26,7 +26,7 @@ in lib.makeOverridable ({ extraMakeFlags ? [], # The name of the kernel module directory # Needs to be X.Y.Z[-extra], so pad with zeros if needed. - modDirVersion ? lib.versions.pad 3 version, + modDirVersion ? null /* derive from version */, # The kernel source (tarball, git checkout, etc.) src, # a list of { name=..., patch=..., extraConfig=...} patches @@ -54,6 +54,13 @@ in lib.makeOverridable ({ }: let + # Provide defaults. Note that we support `null` so that callers don't need to use optionalAttrs, + # which can lead to unnecessary strictness and infinite recursions. + modDirVersion_ = if modDirVersion == null then lib.versions.pad 3 version else modDirVersion; +in +let + # Shadow the un-defaulted parameter; don't want null. + modDirVersion = modDirVersion_; inherit (lib) hasAttr getAttr optional optionals optionalString optionalAttrs maintainers platforms;