nix-community / raspberry-pi-nix

NixOS modules to aid in configuring NixOS for raspberry pi products
MIT License
190 stars 43 forks source link

How to override parts of the kernel package? #81

Closed jwillikers closed 1 hour ago

jwillikers commented 22 hours ago

I'm using raspberry-pi-nix as part of a flake and would like to override the kernel to apply the realtime kernel patches and enable PREEMPT_RT-related config options. I've tried a bunch of different ways of applying overlays to accomplish this, but nothing seems to be working. Here's a snippet of an overlay applied to nixpkgs.

nixpkgs.overlays = [
  (final: prev: {
    rpi-kernels.v6_6_54.bcm2712 = prev.rpi-kernels.v6_6_54.bcm2712.override (prevKernel: {
      structuredExtraConfig = with prev.lib.kernel; {
        SND_HDA_GENERIC = yes;
        SND_HDA_INTEL = yes;
        SND_HDA_PREALLOC_SIZE = 2048;

        # realtime
        # PREEMPT_RT was merged in to kernel 6.12.
        # https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/kernel/linux-rt-6.1.nix
        PREEMPT_RT = yes;
        EXPERT = yes; # PREEMPT_RT depends on it (in kernel/Kconfig.preempt)
        # Fix error: option not set correctly: PREEMPT_VOLUNTARY (wanted 'y', got 'n').
        PREEMPT_VOLUNTARY = prev.lib.mkForce no; # PREEMPT_RT deselects it.
        # Fix error: unused option: RT_GROUP_SCHED.
        RT_GROUP_SCHED = prev.lib.mkForce (option no); # Removed by sched-disable-rt-group-sched-on-rt.patch.
        VIRTUALIZATION = no;
      };
      kernelPatches = let rt-patch = {
        name = "rt";
        patch = prev.fetchurl {
          url = "mirror://kernel/linux/kernel/projects/rt/${prevKernel.branch}/older/patch-${prevKernel.version}.patch.xz";
          sha256 = prev.lib.fakeHash;
        };
      }; in [ rt-patch ] ++ prevKernel.kernelPatches;
    });
  })
];
tstat commented 17 hours ago

Ah, you will be prevented from doing so by this heavy-handed way of pinning the inputs:

https://github.com/nix-community/raspberry-pi-nix/blob/f872d7748f503af66ed577aaf9b621c69235f40c/rpi/default.nix#L293-L312

So, if you disable the pin-inputs option, then I expect your override to work.