Jump to content

CCache: Difference between revisions

623 bytes added ,  6 January 2022
use sandbox-paths
imported>Milahu
m (Milahu moved page Ccache to CCache)
imported>Milahu
(use sandbox-paths)
Line 3: Line 3:
with ccache, recompile time can be reduced from many hours to a few minutes
with ccache, recompile time can be reduced from many hours to a few minutes


== derivation ccache ==
== add ccache to sandbox ==
 
to enable ccache only for one derivation


add to <code>/etc/nixos/configuration.nix</code>
add to <code>/etc/nixos/configuration.nix</code>
Line 11: Line 9:
<pre>
<pre>
           nix.extraOptions = ''
           nix.extraOptions = ''
             sandbox = false
             extra-sandbox-paths = /nix/var/cache/ccache
           '';
           '';
</pre>
</pre>
todo: use <code>nix.sandboxPaths</code>? [https://github.com/NixOS/nixpkgs/issues/153343]


run <code>sudo nixos-rebuild switch</code>
run <code>sudo nixos-rebuild switch</code>


now <code>/etc/nix/nix.conf</code> should have <code>sandbox = false</code>
now <code>/etc/nix/nix.conf</code> should have <code>sandbox-paths = /nix/var/cache/ccache</code>
 
create the cache folder
 
<pre>
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'
</pre>
 
== derivation ccache ==
 
to enable ccache only for one derivation


patch the <code>default.nix</code> file
patch the <code>default.nix</code> file
Line 31: Line 47:


   preConfigure = ''
   preConfigure = ''
     export CCACHE_DIR=/var/cache/ccache
     export CCACHE_DIR=/nix/var/cache/ccache
     export CCACHE_UMASK=007
     export CCACHE_UMASK=007
   ''
   ''
Line 50: Line 66:
<pre>
<pre>
# watch ccache size
# watch ccache size
sudo watch du -sh /var/cache/ccache
sudo watch du -sh /nix/var/cache/ccache


# watch ccache stats
# watch ccache stats
sudo watch ccache --dir /var/cache/ccache --show-stats --verbose
sudo watch ccache --dir /nix/var/cache/ccache --show-stats --verbose
</pre>
</pre>
== see also ==
* 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]
Anonymous user