CachyOS kernel for NixOS
Go to file
2025-12-10 17:51:39 +00:00
.github Add write permission for GitHub Actions workflow 2025-12-09 20:12:20 -08:00
kernel-cachyos Refactor to allow overriding for customizing kernel 2025-12-09 21:08:14 -08:00
zfs-cachyos Add CachyOS-patched ZFS module 2025-12-08 21:43:45 -08:00
.gitignore Add CachyOS-patched ZFS module 2025-12-08 21:43:45 -08:00
default.nix Setup flake-compat 2025-12-08 21:50:54 -08:00
flake.lock Auto update flake 2025-12-10 17:51:39 +00:00
flake.nix Allow building unfree kernel modules 2025-12-09 23:19:13 -08:00
garnix.yaml Do not build aarch64 kernels on Garnix due to weird errors 2025-12-08 19:22:21 -08:00
helpers.nix Refactor to allow overriding for customizing kernel 2025-12-09 21:08:14 -08:00
README.md Refactor to allow overriding for customizing kernel 2025-12-09 21:08:14 -08:00

Nix packages for CachyOS Kernel

built with garnix

This repo contains Linux kernels with both CachyOS patches and CachyOS tunings, as well as CachyOS-patched ZFS module.

Which kernel versions are provided?

This repo provides the latest kernel version and the latest LTS kernel version:

└───packages
    ├───aarch64-linux
        ├───linux-cachyos-latest
        ├───linux-cachyos-latest-lto
        ├───linux-cachyos-lts
        └───linux-cachyos-lts-lto
    └───x86_64-linux
        ├───linux-cachyos-latest
        ├───linux-cachyos-latest-lto
        ├───linux-cachyos-lts
        └───linux-cachyos-lts-lto

The kernel versions are automatically kept in sync with Nixpkgs, so once the latest/LTS kernel is updated in Nixpkgs, CachyOS kernels in this repo will automatically catch up.

Use nix flake show github:xddxdd/nix-cachyos-kernel to see the current effective versions.

The kernels ending in -lto has Clang+ThinLTO enabled.

For each linux kernel entry under packages, we have a corresponding linuxPackages entry under legacyPackages for easier use in your NixOS configuration, e.g.:

  • linux-cachyos-latest -> inputs.nix-cachyos-kernel.legacyPackages.x86_64-linux.linuxPackages-cachyos-latest
  • linux-cachyos-lts-lto -> inputs.nix-cachyos-kernel.legacyPackages.x86_64-linux.linuxPackages-cachyos-lts-lto

How to use kernels

Add this repo to the inputs section of your flake.nix:

{
  inputs = {
    nix-cachyos-kernel.url = "github:xddxdd/nix-cachyos-kernel";
  }
}

Add the repo's overlay in your NixOS configuration, this will expose the packages in this flake as pkgs.cachyosKernels.*.

Then specify pkgs.cachyosKernels.linuxPackages-cachyos-latest (or other variants you'd like) in your boot.kernelPackages option.

Example configuration

{
  nixosConfigurations.example = inputs.nixpkgs.lib.nixosSystem {
    system = "x86_64-linux";
    modules = [
      (
        { pkgs, ... }:
        {
          nixpkgs.overlays = [ self.overlay ];
          boot.kernelPackages = pkgs.cachyosKernels.linuxPackages-cachyos-latest;
          # ... your other configs
        }
      )
    ];
  };
}

How to use ZFS modules

Note: CachyOS-patched ZFS module may fail to compile from time to time. Most compilation failures are caused by incompatibilities between kernel and ZFS. Please check ZFS upstream issues for any compatibility reports, and try switching between zfs_2_3, zfs_unstable and zfs_cachyos.

To use ZFS module with linuxPackages-cachyos-* provided by this flake, point boot.zfs.package to config.boot.kernelPackages.zfs_cachyos.

{
  nixosConfigurations.example = inputs.nixpkgs.lib.nixosSystem {
    system = "x86_64-linux";
    modules = [
      (
        { pkgs, ... }:
        {
          nixpkgs.overlays = [ self.overlay ];
          boot.kernelPackages = pkgs.cachyosKernels.linuxPackages-cachyos-latest;

          # ZFS config
          boot.supportedFilesystems.zfs = true;
          boot.zfs.package = config.boot.kernelPackages.zfs_cachyos;

          # ... your other configs
        }
      )
    ];
  };
}

If you want to construct your own linuxPackages attrset with linuxKernel.packagesFor (path to your kernel), you can directly reference the zfs-cachyos attribute in this flake's packages / legayPackages output, or the cachyosKernels overlay:

{
  nixosConfigurations.example = inputs.nixpkgs.lib.nixosSystem {
    system = "x86_64-linux";
    modules = [
      (
        { pkgs, ... }:
        {
          nixpkgs.overlays = [ self.overlay ];
          boot.kernelPackages = pkgs.linuxKernel.packagesFor pkgs.cachyosKernels.linux-cachyos-latest;

          # ZFS config
          boot.supportedFilesystems.zfs = true;
          boot.zfs.package = pkgs.cachyosKernels.zfs-cachyos.override {
            kernel = config.boot.kernelPackages.kernel;
          };

          # ... your other configs
        }
      )
    ];
  };
}

How to apply CachyOS patches on your own kernel

The kernels provided in this flake can be overridden to use your own kernel source. This is helpful if you want to use a kernel version not available in Nixpkgs.

{
  kernel = pkgs.cachyosKernels.linux-cachyos-latest.override {
    pname = "linux-cachyos-with-custom-source";
    version = "6.12.34";
    src = pkgs.fetchurl {
      # ...
    };
    # Additional args are available. See kernel-cachyos/mkCachyKernel.nix
  };

  # For non-LTO kernels
  kernelPackages = pkgs.linuxKernel.packagesFor kernel;

  # 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" {};

  # For LTO kernels, helpers.kernelModuleLLVMOverride fixes compilation for some
  # out-of-tree modules in nixpkgs.
  kernelPackagesWithLTOFix = helpers.kernelModuleLLVMOverride (pkgs.linuxKernel.packagesFor kernel);
}