Overriding nativeBuildInputs on buildLinux

I need to build an older kernel, namely 5.16.9, on NixOS 22.11 in order to find a bug as mentioned in another thread here: Building kernel 5.16.9 from source fails, how to downgrade dwarves/pahole

However due to some problem with pahole version 1.24 these kernels no longer build on NixOS 22.11. Downgrading to pahole version 1.23 should avoid the issue as mentioned here: pahole v1.24: FAILED: load BTF from vmlinux: Invalid argument

Question How to downgrade pahole in building the Linux kernel short of downgrading NixOS as a whole? Since pahole is in the nativeBuildInputs in this file here nixpkgs/manual-config.nix at fbf79d73ec78596a7e9f0449619412ef13cdcbf8 · NixOS/nixpkgs · GitHub I’d assume that is what I’d have to override.

Hence the more general question: How to override nativeBuildInputs on buildLinux?

(p.s. I decided to make another thread for this here in the development section as it is a rather specific question concerning the build process for the Linux kernel on NixOS. And it might concern others when formulating it this way.)

It looks like pahole isn’t used by anything except the Linux kernel, so you should just be able to git checkout $OLD_REVISION pkgs/development/tools/misc/pahole/ and then nix-build your kernel.

Well yes, but that pahole is passed as a function argument (the whole file is one gigantic function) declared here:

The callPackage ../os-specific/linux/kernel/manual-config.nix {} here is what passes that argument (callPackage is a bit of voodoo wizardry that fills in any missing arguments, using the top-level package set):

So, basically,

  1. You’re unlucky, the kernel-building parts of nixpkgs are… well… a bit tangled. If you’re doing anything out of the ordinary they can be really hard to keep under control. I eventually gave up and wrote my own kernel build expression when I put together ownerboot.

but,

  1. You’re in luck, you can (probably) just roll back the pahole/default.nix expression and everything should just work.
1 Like

@amjoseph

Thanks for the detailed reply!

So since I am building my system from a flake, I’d assume I should just use a package overlay for pahole in the nixpkgs.overlays = [ ]; for my system and override the attribute set to take version 1.23? Then buildLinux will just pick it up. At least I will try that later today.

I’m afraid I have no experience with flakes, but I think you’re on the right track there.

Alright, it appears I can now build and boot kernel 5.16.9 again. :grin:

For anyone who might be interested, my overlay solution is here:

overlay-custom-kernel = final: prev: {
        pahole = prev.pahole.overrideAttrs (oldAttrs: {
          version = "1.23";
          src = prev.fetchgit {
            url = "https://git.kernel.org/pub/scm/devel/pahole/pahole.git";
            rev = "v1.23";
            sha256 = "sha256-Dt3ZcUfjwdtTTv6qRFRgwK5GFWXdpN7fvb9KhpS1O94=";
          };

          buildInputs = [ prev.elfutils prev.zlib final.libbpf-0-7-0 ];
        });

        libbpf-0-7-0 = prev.libbpf.overrideAttrs (oldAttrs: {
          version = "0.7.0";

          src = prev.fetchFromGitHub {
            owner = "libbpf";
            repo = "libbpf";
            rev = "v0.7.0";
            sha256 = "sha256-NFVJ8JquWVzu+QoaaOMzhnu6/IqdP1FPhtJFidXA4L4=";
          };

          buildInputs = [ prev.libelf prev.zlib ];
        });
      };

As you can see, besides downgrading pahole itself, I also needed to downgrade libbpf on which pahole version 1.23 depends. So I created another override for this one and made the pahole override depend on its result.

Later when defining my system in my flake the overlay is used like so:

nixpkgs.overlays = [ overlay-custom-kernel ];
Hosted by Flying Circus.