Keep Makefile patch for a few kmods that want gcc

This commit is contained in:
Lan Tian 2026-05-09 16:46:47 -07:00
parent eaacd115fa
commit de4bf344b2
No known key found for this signature in database
GPG Key ID: 04E66B6B25A0862B
3 changed files with 49 additions and 10 deletions

View File

@ -365,6 +365,16 @@ Additional arguments are passed through to `buildLinux` from nixpkgs. See [nixpk
# Additional args are available. See kernel-cachyos/mkCachyKernel.nix # Additional args are available. See kernel-cachyos/mkCachyKernel.nix
}; };
# For non-LTO kernels
kernelPackages = pkgs.linuxKernel.packagesFor kernel; kernelPackages = pkgs.linuxKernel.packagesFor kernel;
# For LTO kernels, helpers.kernelModuleLLVMOverride fixes compilation for some
# out-of-tree modules in nixpkgs.
kernelPackagesWithLTOFix = let
# helpers.nix provides a few utilities for building kernel with LTO.
# I haven't figured out a clean way to expose it in flakes.
helpers = pkgs.callPackage "${inputs.nix-cachyos-kernel.outPath}/helpers.nix" {};
in helpers.kernelModuleLLVMOverride (pkgs.linuxKernel.packagesFor kernel);
} }
``` ```

View File

@ -55,4 +55,28 @@ rec {
pkgs.patchelf pkgs.patchelf
]; ];
}); });
kernelModuleLLVMOverride =
kernelPackages_:
kernelPackages_.extend (
_final: prev:
lib.mapAttrs (
n: v:
if
builtins.elem "LLVM=1" kernelPackages_.kernel.commonMakeFlags
&& !(builtins.elem n [ "kernel" ])
&& lib.isDerivation v
&& ((v.overrideAttrs or null) != null)
then
v.overrideAttrs (old: {
postPatch = (if (old.postPatch or null) == null then "" else old.postPatch) + ''
if [ -f Makefile ]; then
substituteInPlace Makefile --replace "gcc" "cc"
fi
'';
})
else
v
) prev
);
} }

View File

@ -6,21 +6,26 @@
... ...
}: }:
let let
helpers = callPackage ../helpers.nix { };
inherit (helpers) kernelModuleLLVMOverride;
kernels = lib.filterAttrs (_: lib.isDerivation) (callPackage ./. { inherit inputs; }); kernels = lib.filterAttrs (_: lib.isDerivation) (callPackage ./. { inherit inputs; });
in in
lib.mapAttrs' ( lib.mapAttrs' (
n: v: n: v:
let let
packages = (linuxKernel.packagesFor v).extend ( packages = kernelModuleLLVMOverride (
final: prev: (linuxKernel.packagesFor v).extend (
let final: prev:
variant = lib.removePrefix "linux-cachyos-" v.cachyosConfigVariant; let
in variant = lib.removePrefix "linux-cachyos-" v.cachyosConfigVariant;
{ in
zfs_cachyos = final.callPackage ../zfs-cachyos { {
inherit inputs variant; zfs_cachyos = final.callPackage ../zfs-cachyos {
}; inherit inputs variant;
} };
}
)
); );
in in
lib.nameValuePair "linuxPackages-${lib.removePrefix "linux-" n}" packages lib.nameValuePair "linuxPackages-${lib.removePrefix "linux-" n}" packages