From de4bf344b26f355b5d92071503f7a8fd18bc7f6b Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Sat, 9 May 2026 16:46:47 -0700 Subject: [PATCH] Keep Makefile patch for a few kmods that want gcc --- README.md | 10 ++++++++++ helpers.nix | 24 ++++++++++++++++++++++++ kernel-cachyos/packages.nix | 25 +++++++++++++++---------- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 709d324..1e52990 100644 --- a/README.md +++ b/README.md @@ -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); } ``` diff --git a/helpers.nix b/helpers.nix index 049f522..a9cc26d 100644 --- a/helpers.nix +++ b/helpers.nix @@ -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 + ); } diff --git a/kernel-cachyos/packages.nix b/kernel-cachyos/packages.nix index 0a3c65b..3e1905e 100644 --- a/kernel-cachyos/packages.nix +++ b/kernel-cachyos/packages.nix @@ -6,21 +6,26 @@ ... }: 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 ( - final: prev: - let - variant = lib.removePrefix "linux-cachyos-" v.cachyosConfigVariant; - in - { - zfs_cachyos = final.callPackage ../zfs-cachyos { - inherit inputs variant; - }; - } + packages = kernelModuleLLVMOverride ( + (linuxKernel.packagesFor v).extend ( + final: prev: + let + variant = lib.removePrefix "linux-cachyos-" v.cachyosConfigVariant; + in + { + zfs_cachyos = final.callPackage ../zfs-cachyos { + inherit inputs variant; + }; + } + ) ); in lib.nameValuePair "linuxPackages-${lib.removePrefix "linux-" n}" packages