How to install a Linux Kernel patch?

Hello, Nixers!

I want to know how can I maintain various Linux patched kernels (and select among them in Grub bootloader). As direct examples:

There’s the boot.kernelPatches option. But if you want to select different patch sets at boot, you’ll probably want to use nesting.clone option and boot.loader.grub.configurationName to create multiple nearly identical configs with different names.

# configuration.nix
{ pkgs, lib, ... }: {
  # ...

  nesting.clone = [
    {
      boot.loader.grub.configurationName = "xanmod";
      boot.kernelPatches = [{ name = "xanmod"; patch = builtins.fetchurl "...";}];
    }
    {
      boot.loader.grub.configurationName = "liquorix";
      boot.kernelPatches = [{ name = "liquorix"; patch = builtins.fetchurl "...";}];
    }
    {
      boot.loader.grub.configurationName = "con-kolivas";
      boot.kernelPatches = [{ name = "con-kolivas"; patch = builtins.fetchurl "...";}];
    }
  ];
}

This will create multiple boot options in grub that are identical systems in every way except that their kernel patches differ. Note the default will still be an identical system with an unpatched kernel.

Here is the output of failure:

[root@hendrix:~]# nix-channel --update; nixos-rebuild boot
unpacking channels...
building Nix...
building the system configuration...
error: 
Failed assertions:
- The option definition `nesting.clone' in `/etc/nixos/hendrix/nesting-clone.nix' no longer has any effect; please remove it.
Use `specialisation.«name» = { inheritParentConfig = true; configuration = { ... }; }` instead.

(use '--show-trace' to show detailed location information)

Huh. I’m still on 19.09 so I don’t have that change on my system yet. Not entirely sure the right way to adapt

Looks like you just take all the elements from the list in my version and throw them into the configuration option of specialisation.«name» = { inheritParentConfig = true; configuration = { ... }; }, with one <name> for each one instead of a list. Also maybe don’t need the boot.loader.grub.configurationName options? Haven’t tested

For now I tried this:

{ pkgs, config, ... }: {

  specialisation."linux-5.5.18-ck1" = {
    inheritParentConfig = true;
    configuration = {
      boot.loader.grub.configurationName = "linux-5.5.18-ck1";
      boot.kernelPackages = pkgs.linuxPackages_5_5;
      boot.kernelPatches = [
        { name = "con-kolivas-5.5-ck1";
          patch = builtins.fetchurl
                  "http://ck.kolivas.org/patches/5.0/5.5/5.5-ck1/patch-5.5-ck1";
        }
      ];
    };
  };
}

But it shows a new error:

Error: modDirVersion 5.5.18 specified in the Nix expression is wrong, it should be: 5.5.18-ck1

Now, how can I modify modDirVersion?

1 Like