Bisect linux kernel without recompiling every time

TL;DR: can I bisect NixOs’s kernel without recompiling it every time?

I just got a regression with my NixOs upgrade, and after reporting the issue, the kernel team asked me to bisect the kernel (to be honest, finding a reliable test to check if the bug is gone might not be easy, but it is another issue)… Bisecting the kernel in NixOs seems to be not too complicated as documented here via:

boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.linux_6_2.override { # (#4)
  argsOverride = rec {
    src = pkgs.fetchFromGitHub {
      owner = "torvalds";
      repo = "linux";
      # (#1) -> put the bisect revision here
      rev = "7484a5bc153e81a1740c06ce037fd55b7638335c";
      # (#2) -> clear the sha; run a build, get the sha, populate the sha
      sha256 = "sha256-nr7CbJO6kQiJHJIh7vypDjmUJ5LA9v9VDz6ayzBh7nI=";
    };
    dontStrip = true;
    # (#3) `head Makefile` from the kernel and put the right version numbers here
    version = "6.2.0";
    modDirVersion = "6.2.0-rc2";
  };
});

but unfortunately, as far as I understand compiling the kernel can take a fair amount of time (from 30mn to up to several hours ?)…

Would it be possible instead to cache the compilation of the kernel so that next compilations only takes a few seconds? I was thinking to try to use nix-shell + run genericBuild (see e.g. this page) with a custom $out in /tmp/mykernel, and then create a custom derivation that just copies /tmp/mykernel verbatim to $out… but seems like a bit tedious and dirty. Is there a cleaner way to proceed?

1 Like

That depends on your machine. A good desktop certainly makes it in less than 30 minutes.

You can use ccache by passing

  stdenv = pkgs.ccacheStdenv;
  buildPackages = pkgs.buildPackages // { stdenv = pkgs.buildPackages.ccacheStdenv; };

to your argsOverride. You need to enable ccache by following CCache - NixOS Wiki, and you probably need to add export CCACHE_SLOPPINESS=random_seed to ccacheWrapper.extraConfig to work around New reproducibility NIX_CFLAGS_COMPILE breaks ccache caching · Issue #109033 · NixOS/nixpkgs · GitHub.

2 Likes

Good to know, thanks, but still not negligible :-\

Oh, first time I hear about ccache, seems like a really great tool, thanks for this! Will try it asap!

1 Like