Caching local compilation results for all compiled packages

Hi !
I use some larger packages that require building locally (like a kernel with custom config, virtualbox with disabled hardening). I was wondering if there is a system-wide way of saying I would like to use ccache for compiling all of the packages that require local compilation ? Something akin to:

  1. if there is a binary version of the package - just download that
  2. if there is not - try to compile
  3. for every local compilation process launched by 2) - use global ccache

Thanks so much !

Hello! You can use ccacheStdenv instead of stdenv for your packages that require local compilation.

There is some documentation here:

1 Like

Thanks so much for that, will try that one out :slight_smile:

Hi :slight_smile:
I tried the suggestion and it seems it does not work anymore, I seem to be hitting a problem as described here - https://github.com/NixOS/nixpkgs/issues/62121 - do you know if there is a way to still achieve caching of all packages built locally ? Thanks :slight_smile:

I think there was an attempt made long ago with https://github.com/edolstra/nix-make to use the nix-store as a repository for per-build-artifact packages, however, it has long since been ditched.

AFAIK, the only level of abstraction for nix is a derivation, so you will need to try and decompose your problem into smaller derivations if you want to get more mileage out of them. For a kernel? I’m not sure how far you’ll get, probably not very.

While developing a derivation, I’ve had luck just setting the CCACHE variables directly and turning sandboxing off. This allowed me to temporarily speed up iterations of builds, then turn it off before submission to Nixpkgs.