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
};
# For non-LTO kernels
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
];
});
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,12 +6,16 @@
...
}:
let
helpers = callPackage ../helpers.nix { };
inherit (helpers) kernelModuleLLVMOverride;
kernels = lib.filterAttrs (_: lib.isDerivation) (callPackage ./. { inherit inputs; });
in
lib.mapAttrs' (
n: v:
let
packages = (linuxKernel.packagesFor v).extend (
packages = kernelModuleLLVMOverride (
(linuxKernel.packagesFor v).extend (
final: prev:
let
variant = lib.removePrefix "linux-cachyos-" v.cachyosConfigVariant;
@ -21,6 +25,7 @@ lib.mapAttrs' (
inherit inputs variant;
};
}
)
);
in
lib.nameValuePair "linuxPackages-${lib.removePrefix "linux-" n}" packages