diff --git a/pkgs/os-specific/linux/kernel/generic.nix b/pkgs/os-specific/linux/kernel/generic.nix index 5a4c2858f95f..dce2ed074a05 100644 --- a/pkgs/os-specific/linux/kernel/generic.nix +++ b/pkgs/os-specific/linux/kernel/generic.nix @@ -29,7 +29,8 @@ structuredExtraConfig ? {} , # The version number used for the module directory - modDirVersion ? version + # If unspecified, this is determined automatically from the version. + modDirVersion ? null , # An attribute set whose attributes express the availability of # certain features in this kernel. E.g. `{iwlwifi = true;}' @@ -195,15 +196,15 @@ let }; # end of configfile derivation kernel = (callPackage ./manual-config.nix { inherit buildPackages; }) (basicArgs // { - inherit modDirVersion kernelPatches randstructSeed lib stdenv extraMakeFlags extraMeta configfile; + inherit kernelPatches randstructSeed lib stdenv extraMakeFlags extraMeta configfile; pos = builtins.unsafeGetAttrPos "version" args; config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; }; - }); + } // lib.optionalAttrs (modDirVersion != null) { inherit modDirVersion; }); passthru = basicArgs // { features = kernelFeatures; - inherit commonStructuredConfig structuredExtraConfig extraMakeFlags isZen isHardened isLibre modDirVersion; + inherit commonStructuredConfig structuredExtraConfig extraMakeFlags isZen isHardened isLibre; isXen = lib.warn "The isXen attribute is deprecated. All Nixpkgs kernels that support it now have Xen enabled." true; passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]); tests = let diff --git a/pkgs/os-specific/linux/kernel/linux-4.14.nix b/pkgs/os-specific/linux/kernel/linux-4.14.nix index 02893f731e3e..777aa852650a 100644 --- a/pkgs/os-specific/linux/kernel/linux-4.14.nix +++ b/pkgs/os-specific/linux/kernel/linux-4.14.nix @@ -6,7 +6,7 @@ buildLinux (args // rec { version = "4.14.302"; # modDirVersion needs to be x.y.z, will automatically add .0 if needed - modDirVersion = if (modDirVersionArg == null) then concatStringsSep "." (take 3 (splitVersion "${version}.0")) else modDirVersionArg; + modDirVersion = versions.pad 3 version; # branchVersion needs to be x.y extraMeta.branch = versions.majorMinor version; @@ -16,3 +16,4 @@ buildLinux (args // rec { sha256 = "102c9h0byr9v4bxzkdh7mnw1grm47ji6lf6l1gjlwah7f46j6ap3"; }; } // (args.argsOverride or {})) + // lib.optionalAttrs (modDirVersionArg != null) { modDirVersion = modDirVersionArg; } # legacy diff --git a/pkgs/os-specific/linux/kernel/linux-4.19.nix b/pkgs/os-specific/linux/kernel/linux-4.19.nix index 44a976ef0c7d..6c5531afd6fd 100644 --- a/pkgs/os-specific/linux/kernel/linux-4.19.nix +++ b/pkgs/os-specific/linux/kernel/linux-4.19.nix @@ -6,7 +6,7 @@ buildLinux (args // rec { version = "4.19.269"; # modDirVersion needs to be x.y.z, will automatically add .0 if needed - modDirVersion = if (modDirVersionArg == null) then concatStringsSep "." (take 3 (splitVersion "${version}.0")) else modDirVersionArg; + modDirVersion = versions.pad 3 version; # branchVersion needs to be x.y extraMeta.branch = versions.majorMinor version; @@ -16,3 +16,4 @@ buildLinux (args // rec { sha256 = "02mjb16xxfj984vibpxvhjl84y5yg0jgzjccjdxnn8db4k9aa2vf"; }; } // (args.argsOverride or {})) + // lib.optionalAttrs (modDirVersionArg != null) { modDirVersion = modDirVersionArg; } # legacy diff --git a/pkgs/os-specific/linux/kernel/linux-5.10.nix b/pkgs/os-specific/linux/kernel/linux-5.10.nix index 5614aeb1cabf..7662f6be96c9 100644 --- a/pkgs/os-specific/linux/kernel/linux-5.10.nix +++ b/pkgs/os-specific/linux/kernel/linux-5.10.nix @@ -6,7 +6,7 @@ buildLinux (args // rec { version = "5.10.159"; # modDirVersion needs to be x.y.z, will automatically add .0 if needed - modDirVersion = if (modDirVersionArg == null) then concatStringsSep "." (take 3 (splitVersion "${version}.0")) else modDirVersionArg; + modDirVersion = versions.pad 3 version; # branchVersion needs to be x.y extraMeta.branch = versions.majorMinor version; @@ -16,3 +16,4 @@ buildLinux (args // rec { sha256 = "19yfi5vknxnw0cb8274q3pb5zjs6ny04n16m8xjdfdmznrbvza8v"; }; } // (args.argsOverride or {})) + // lib.optionalAttrs (modDirVersionArg != null) { modDirVersion = modDirVersionArg; } # legacy diff --git a/pkgs/os-specific/linux/kernel/linux-5.15.nix b/pkgs/os-specific/linux/kernel/linux-5.15.nix index 8e07ff461ef6..f72a304d30c9 100644 --- a/pkgs/os-specific/linux/kernel/linux-5.15.nix +++ b/pkgs/os-specific/linux/kernel/linux-5.15.nix @@ -6,7 +6,7 @@ buildLinux (args // rec { version = "5.15.83"; # modDirVersion needs to be x.y.z, will automatically add .0 if needed - modDirVersion = if (modDirVersionArg == null) then concatStringsSep "." (take 3 (splitVersion "${version}.0")) else modDirVersionArg; + modDirVersion = versions.pad 3 version; # branchVersion needs to be x.y extraMeta.branch = versions.majorMinor version; @@ -16,3 +16,4 @@ buildLinux (args // rec { sha256 = "1wvzfhzqq9dps508wmp2gblfz93ipppnjzqm0n8pi1acq11hhna0"; }; } // (args.argsOverride or { })) + // lib.optionalAttrs (modDirVersionArg != null) { modDirVersion = modDirVersionArg; } # legacy diff --git a/pkgs/os-specific/linux/kernel/linux-5.4.nix b/pkgs/os-specific/linux/kernel/linux-5.4.nix index b45ef4f3b502..b41f18d400a3 100644 --- a/pkgs/os-specific/linux/kernel/linux-5.4.nix +++ b/pkgs/os-specific/linux/kernel/linux-5.4.nix @@ -6,7 +6,7 @@ buildLinux (args // rec { version = "5.4.227"; # modDirVersion needs to be x.y.z, will automatically add .0 if needed - modDirVersion = if (modDirVersionArg == null) then concatStringsSep "." (take 3 (splitVersion "${version}.0")) else modDirVersionArg; + modDirVersion = versions.pad 3 version; # branchVersion needs to be x.y extraMeta.branch = versions.majorMinor version; @@ -16,3 +16,4 @@ buildLinux (args // rec { sha256 = "14q5gy48j78vwnqivrgpdhj778n2jq5l7yiw5na1rwqmfh1wbvsy"; }; } // (args.argsOverride or {})) + // lib.optionalAttrs (modDirVersionArg != null) { modDirVersion = modDirVersionArg; } # legacy diff --git a/pkgs/os-specific/linux/kernel/linux-6.0.nix b/pkgs/os-specific/linux/kernel/linux-6.0.nix index 2bd2a3f07c1d..ea98462bdf40 100644 --- a/pkgs/os-specific/linux/kernel/linux-6.0.nix +++ b/pkgs/os-specific/linux/kernel/linux-6.0.nix @@ -6,7 +6,7 @@ buildLinux (args // rec { version = "6.0.13"; # modDirVersion needs to be x.y.z, will automatically add .0 if needed - modDirVersion = if (modDirVersionArg == null) then concatStringsSep "." (take 3 (splitVersion "${version}.0")) else modDirVersionArg; + modDirVersion = versions.pad 3 version; # branchVersion needs to be x.y extraMeta.branch = versions.majorMinor version; @@ -16,3 +16,4 @@ buildLinux (args // rec { sha256 = "191dlxcmbx8vy6z2k04jq2kr6hwnaknsnsyycvqnjmvmdf6i3lq8"; }; } // (args.argsOverride or { })) + // lib.optionalAttrs (modDirVersionArg != null) { modDirVersion = modDirVersionArg; } # legacy diff --git a/pkgs/os-specific/linux/kernel/linux-6.1.nix b/pkgs/os-specific/linux/kernel/linux-6.1.nix index 64ed1a717caf..aab12f77786a 100644 --- a/pkgs/os-specific/linux/kernel/linux-6.1.nix +++ b/pkgs/os-specific/linux/kernel/linux-6.1.nix @@ -6,7 +6,7 @@ buildLinux (args // rec { version = "6.1"; # modDirVersion needs to be x.y.z, will automatically add .0 if needed - modDirVersion = if (modDirVersionArg == null) then concatStringsSep "." (take 3 (splitVersion "${version}.0")) else modDirVersionArg; + modDirVersion = versions.pad 3 version; # branchVersion needs to be x.y extraMeta.branch = versions.majorMinor version; @@ -16,3 +16,4 @@ buildLinux (args // rec { sha256 = "sha256-LKHxcFGkMPb+0RluSVJxdQcXGs/ZfZZXchJQJwOyXes="; }; } // (args.argsOverride or { })) + // lib.optionalAttrs (modDirVersionArg != null) { modDirVersion = modDirVersionArg; } # legacy diff --git a/pkgs/os-specific/linux/kernel/linux-rt-5.10.nix b/pkgs/os-specific/linux/kernel/linux-rt-5.10.nix index 103b142054af..a97b1acb5aad 100644 --- a/pkgs/os-specific/linux/kernel/linux-rt-5.10.nix +++ b/pkgs/os-specific/linux/kernel/linux-rt-5.10.nix @@ -13,8 +13,7 @@ in buildLinux (args // { inherit version; # modDirVersion needs a patch number, change X.Y-rtZ to X.Y.0-rtZ. - modDirVersion = if (builtins.match "[^.]*[.][^.]*-.*" version) == null then version - else lib.replaceStrings ["-"] [".0-"] version; + modDirVersion = lib.versions.pad 3 version; src = fetchurl { url = "mirror://kernel/linux/kernel/v5.x/linux-${kversion}.tar.xz"; diff --git a/pkgs/os-specific/linux/kernel/linux-testing.nix b/pkgs/os-specific/linux/kernel/linux-testing.nix index 76db1b11bbd2..859df2c53e6c 100644 --- a/pkgs/os-specific/linux/kernel/linux-testing.nix +++ b/pkgs/os-specific/linux/kernel/linux-testing.nix @@ -7,7 +7,7 @@ buildLinux (args // rec { extraMeta.branch = lib.versions.majorMinor version; # modDirVersion needs to be x.y.z, will always add .0 - modDirVersion = if (modDirVersionArg == null) then builtins.replaceStrings ["-"] [".0-"] version else modDirVersionArg; + modDirVersion = versions.pad 3 version; src = fetchurl { url = "https://git.kernel.org/torvalds/t/linux-${version}.tar.gz"; @@ -18,3 +18,4 @@ buildLinux (args // rec { extraMeta.hydraPlatforms = []; } // (args.argsOverride or {})) + // lib.optionalAttrs (modDirVersionArg != null) { modDirVersion = modDirVersionArg; } # legacy diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index edfd1f7dbc28..1ba5495fc90e 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -22,8 +22,9 @@ in { pos ? null, # Additional kernel make flags extraMakeFlags ? [], - # The version of the kernel module directory - modDirVersion ? version, + # 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, # The kernel source (tarball, git checkout, etc.) src, # a list of { name=..., patch=..., extraConfig=...} patches @@ -36,7 +37,7 @@ in { # Custom seed used for CONFIG_GCC_PLUGIN_RANDSTRUCT if enabled. This is # automatically extended with extra per-version and per-config values. randstructSeed ? "", - # Use defaultMeta // extraMeta + # Extra meta attributes extraMeta ? {}, # for module compatibility diff --git a/pkgs/os-specific/linux/kernel/xanmod-kernels.nix b/pkgs/os-specific/linux/kernel/xanmod-kernels.nix index cd1c82778072..42997b5302ec 100644 --- a/pkgs/os-specific/linux/kernel/xanmod-kernels.nix +++ b/pkgs/os-specific/linux/kernel/xanmod-kernels.nix @@ -16,7 +16,7 @@ let xanmodKernelFor = { version, suffix ? "xanmod1", hash, variant }: buildLinux (args // rec { inherit version; - modDirVersion = "${version}-${suffix}"; + modDirVersion = lib.versions.pad 3 "${version}-${suffix}"; src = fetchFromGitHub { owner = "xanmod"; diff --git a/pkgs/os-specific/linux/kernel/zen-kernels.nix b/pkgs/os-specific/linux/kernel/zen-kernels.nix index a58782828478..08671e83ffc5 100644 --- a/pkgs/os-specific/linux/kernel/zen-kernels.nix +++ b/pkgs/os-specific/linux/kernel/zen-kernels.nix @@ -18,7 +18,7 @@ let }; zenKernelsFor = { version, suffix, sha256, isLqx }: buildLinux (args // { inherit version; - modDirVersion = "${lib.concatStringsSep "." (lib.take 3 (lib.splitVersion version ++ [ "0" "0" ]))}-${suffix}"; + modDirVersion = lib.versions.pad 3 "${version}-${suffix}"; isZen = true; src = fetchFromGitHub { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index bff0e2f7591c..53f4f77a0cbf 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -25470,7 +25470,7 @@ with pkgs; linuxPackages_custom_tinyconfig_kernel = let base = linuxPackages.kernel; tinyLinuxPackages = linuxKernel.customPackage { - inherit (base) version src; + inherit (base) version modDirVersion src; allowImportFromDerivation = false; configfile = linuxConfig { makeTarget = "tinyconfig"; diff --git a/pkgs/top-level/linux-kernels.nix b/pkgs/top-level/linux-kernels.nix index ac0511a649bf..da4270896f67 100644 --- a/pkgs/top-level/linux-kernels.nix +++ b/pkgs/top-level/linux-kernels.nix @@ -40,6 +40,7 @@ let }; argsOverride = { inherit version; + modDirVersion = modDirVersion' + kernelPatches.hardened.${kernel.meta.branch}.extra; src = fetchurl { url = "mirror://kernel/linux/kernel/v${major}.x/linux-${version}.tar.xz"; inherit sha256; @@ -48,7 +49,6 @@ let kernelPatches = kernel.kernelPatches ++ [ kernelPatches.hardened.${kernel.meta.branch} ]; - modDirVersionArg = modDirVersion' + (kernelPatches.hardened.${kernel.meta.branch}).extra; isHardened = true; }; in { @@ -595,9 +595,9 @@ in { manualConfig = makeOverridable (callPackage ../os-specific/linux/kernel/manual-config.nix {}); - customPackage = { version, src, configfile, allowImportFromDerivation ? true }: + customPackage = { version, src, modDirVersion ? lib.versions.pad 3 version, configfile, allowImportFromDerivation ? true }: recurseIntoAttrs (packagesFor (manualConfig { - inherit version src configfile lib stdenv allowImportFromDerivation; + inherit version src modDirVersion configfile lib stdenv allowImportFromDerivation; })); # Derive one of the default .config files