How to build the kernel with ccache?

Due to a setting I enabled (crash dump kernel) doing a nixos-rebuild sometimes needs to rebuild my kernel from scratch, which I would like to make faster by using ccache.

I found the programs.ccache.packageNames option, which allows setting packages that should be built using ccache.

So I put this into my config:

  programs.ccache = {
    enable = true;
    packageNames = [
      "linux"
    ];
  };

However, this does not actually cause ccache to be used to build the kernel, i.e., CCACHE_DIR="/var/cache/ccache" ccache -s reports an empty/unused cache directory.

What is the correct name to give to programs.ccache.packageNames to enable ccache when my kernel is being built?

(Small extra question: How can I easily test this, i.e., trigger a rebuild of my kernel when it’s not necessary?)

Thanks! :slight_smile:

3 Likes

@gytis-ivaskevicius (or at least someone with the same name) on Matrix reminded me that /var/cache/ccache needs to be in my build sandbox, as I’m on flakes. They also found that this seems to be done by other people as well: https://github.com/search?q=ccache+sandbox+extension%3Anix&type=Code (thanks @gytis-ivaskevicius!)

This would make a lot of sense. Couldn’t test it yet as I don’t know how to rebuild my kernel, any ideas on that?

1 Like

disable whatever kernel change you did → rebuild → enable kernel tweak → see what happens

(2 stage process so sandbox path would get set and on second iteration it should get used)

oh, if you mean that kernel is already built - just change some argument or pass additional env variable

Yeah that’s what I meant. I had boot.crashDump.enable on true, changed it to false and rebuilt one time, then set it back to true, but that didn’t cause a rebuild (which I guess makes sense). I guess I could run gc after setting it to false?

What do you mean by additional env variable?

Just had a system update that included rebuilding the kernel, but it didn’t use ccache (i.e., CCACHE_DIR="/var/cache/ccache" ccache -s still reports an empty cache).

What is the correct package name/would be a way to find the correct package name, as it doesn’t seem to be linux?

The problem here seems to be that the kernel build references buildPackages.stdenv.cc in depsBuildBuild; this needs to be overridden with ccacheStdenv too.

1 Like