CCache: Difference between revisions
imported>Milahu No edit summary |
imported>Fufexan Capitalize, add category |
||
Line 1: | Line 1: | ||
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 <code>/etc/nixos/configuration.nix</code> | |||
< | <syntaxhighlight lang="nix"> | ||
nix.extraOptions = '' | |||
extra-sandbox-paths = /nix/var/cache/ccache | |||
''; | |||
</ | </syntaxhighlight> | ||
TODO: use <code>nix.sandboxPaths</code>? [https://github.com/NixOS/nixpkgs/issues/153343] | |||
Run <code>sudo nixos-rebuild switch</code> | |||
Now <code>/etc/nix/nix.conf</code> should have <code>sandbox-paths = /nix/var/cache/ccache</code> | |||
Ceate the cache folder | |||
<pre> | <pre> | ||
Line 31: | Line 31: | ||
</pre> | </pre> | ||
== | == Derivation CCache == | ||
patch the <code>default.nix</code> file | To enable CCache only for one derivation, patch the <code>default.nix</code> file | ||
< | <syntaxhighlight lang="nix"> | ||
{ stdenv | { stdenv | ||
, ccacheStdenv | , ccacheStdenv | ||
Line 52: | Line 50: | ||
# ... | # ... | ||
</ | </syntaxhighlight> | ||
Add <code>ccacheStdenv</code> to dependencies. | |||
Run <code>nix-build</code>. | |||
== | == System CCache == | ||
todo | todo | ||
== | == Monitor CCache status == | ||
<pre> | <pre> | ||
Line 72: | Line 70: | ||
</pre> | </pre> | ||
== | == Uncacheable == | ||
TODO: why are some compilations "uncacheable" according to <code>ccache --show-stats</code> | |||
== | == See also == | ||
* https://leanprover.github.io/lean4/doc/make/nix.html | * https://leanprover.github.io/lean4/doc/make/nix.html | ||
* [https://nixos.org/manual/nix/stable/command-ref/conf-file.html sandbox-paths in nix.conf] | * [https://nixos.org/manual/nix/stable/command-ref/conf-file.html sandbox-paths in nix.conf] | ||
[[Category: Development]] |
Revision as of 20:18, 9 August 2022
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
Ceate 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