CCache
ccache is useful for Packaging large packages with Incremental builds
with ccache, recompile time can be reduced from many hours to a few minutes
add ccache to sandbox
add to /etc/nixos/configuration.nix
nix.extraOptions = '' extra-sandbox-paths = /nix/var/cache/ccache '';
todo: use nix.sandboxPaths
? [1]
run sudo nixos-rebuild switch
now /etc/nix/nix.conf
should have sandbox-paths = /nix/var/cache/ccache
create the cache folder
sudo mkdir -m0770 -p /nix/var/cache/ccache # Linux sudo chown --reference=/nix/store /nix/var/cache/ccache # macOS workaround for chown --reference nix-shell -p coreutils --run 'sudo chown --reference=/nix/store /nix/var/cache/ccache'
derivation ccache
to enable ccache only for one derivation
patch the default.nix
file
{ stdenv , ccacheStdenv # ... }: #stdenv.mkDerivation { ccacheStdenv.mkDerivation { preConfigure = '' export CCACHE_DIR=/nix/var/cache/ccache export CCACHE_UMASK=007 '' # ...
add ccacheStdenv
to dependencies
run nix-build
system ccache
todo
monitor ccache status
# watch ccache size sudo watch du -sh /nix/var/cache/ccache # watch ccache stats sudo watch ccache --dir /nix/var/cache/ccache --show-stats --verbose
uncacheable
todo: why are some compilations "uncacheable" according to ccache --show-stats