Help using ccache for kernel build

OK yeah so I followed the definition of the kernel packages in nixpkgs and it turns out the buildLinux function accepts a field called stdenv, and if I set that to pkgs.ccacheStdenv, it just gets applied directly to the kernel.

The immediate result is a bit confusing, because that wrapper script that’s embedded in the extraConfig (omitted in my comment) doesn’t behave anything like a C compiler if it doesn’t see /var/cache/ccache, so the kernel build system says “sorry, your C compiler isn’t supported” and you don’t actually get the nice helpful error message.

Anyway, once I created it and set extra-sandbox-paths = /var/cache/ccache in /etc/nix/nix.conf, it started building the kernel. Weirdly, the ccache statistics don’t show much happening:

❯❯  CCACHE_DIR=/var/cache/ccache sudo ccache -s
Local storage:
  Cache size (GiB): 0.0 / 5.0 ( 0.00%)

But I can see files appearing in /var/cache/ccache… so hopefully something is working.

So yeah, some remaining awkwardness, i.e. now my flake won’t compile without setup on the build host, and in that case it prints an extremely unhelpful message. But, it seems like it should be achievable to make the ccache usage optional, and print a more helpful message. In the meantime maybe I have something that Works On My Machine.

Here’s the commit where I think I got things working.

1 Like