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]]
CCache is useful for [[Packaging]] large packages with [[Incremental builds]].


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.


== add ccache to sandbox ==
== Add CCache to sandbox ==


add to <code>/etc/nixos/configuration.nix</code>
Add to <code>/etc/nixos/configuration.nix</code>


<pre>
<syntaxhighlight lang="nix">
          nix.extraOptions = ''
nix.extraOptions = ''
            extra-sandbox-paths = /nix/var/cache/ccache
  extra-sandbox-paths = /nix/var/cache/ccache
          '';
'';
</pre>
</syntaxhighlight>


todo: use <code>nix.sandboxPaths</code>? [https://github.com/NixOS/nixpkgs/issues/153343]
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-paths = /nix/var/cache/ccache</code>
Now <code>/etc/nix/nix.conf</code> should have <code>sandbox-paths = /nix/var/cache/ccache</code>


create the cache folder
Ceate the cache folder


<pre>
<pre>
Line 31: Line 31:
</pre>
</pre>


== derivation ccache ==
== Derivation CCache ==
 
to enable ccache only for one derivation


patch the <code>default.nix</code> file
To enable CCache only for one derivation, patch the <code>default.nix</code> file


<pre>
<syntaxhighlight lang="nix">
{ stdenv
{ stdenv
, ccacheStdenv
, ccacheStdenv
Line 52: Line 50:


# ...
# ...
</pre>
</syntaxhighlight>


add <code>ccacheStdenv</code> to dependencies
Add <code>ccacheStdenv</code> to dependencies.


run <code>nix-build</code>
Run <code>nix-build</code>.


== system ccache ==
== System CCache ==


todo
todo


== monitor ccache status ==
== Monitor CCache status ==


<pre>
<pre>
Line 72: Line 70:
</pre>
</pre>


== uncacheable ==
== Uncacheable ==


todo: why are some compilations "uncacheable" according to <code>ccache --show-stats</code>
TODO: why are some compilations "uncacheable" according to <code>ccache --show-stats</code>


== see also ==
== 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]]