CCache: Difference between revisions

imported>Terinjokes
rewrote to use NixOS module and to cleanup non-nixos instructions
Xz (talk | contribs)
Not related to NixOS, read https://ccache.dev/manual/4.8.2.html#_cache_statistics and run ccache -vs
 
(3 intermediate revisions by 3 users not shown)
Line 61: Line 61:
</syntaxhighlight>
</syntaxhighlight>


Note, that if the package is a top-level package, you can also add it to the <code>programs.ccache.packageNames</code> list.
Some packages do not use <code>stdenv</code> directly. You may need to plumb it through other dependencies first.
 
Note, that if the package is a top-level package, you may instead add it to the <code>programs.ccache.packageNames</code> list.


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.ccache.packageNames = [ "ffmpeg" ];
programs.ccache.packageNames = [ "ffmpeg" ];
</syntaxhighlight>
</syntaxhighlight>
Some packages do not use <code>stdenv</code> directly. You may need to plumb it through other dependencies first.


=== System CCache ===
=== System CCache ===
Line 83: Line 83:
== Non-NixOS ==
== Non-NixOS ==


Ceate the cache folder:
Create the cache folder:


<pre>
<pre>
Line 156: Line 156:
</pre>
</pre>


== Uncacheable ==
== Sloppiness ==
 
By default, <code>stdenv</code> inserts <code>-frandom-seed</code> C compiler flag with a value that changes whenever the derivation hash has changed.
Consequently, this behavior completely defeats any usage of <code>ccacheWrapper</code>
To counterpart this behavior, add the following line to the ccache config (typically <code>/var/cache/ccache/ccache.conf</code>):
<pre>
sloppiness = random_seed
</pre>


TODO: why are some compilations "uncacheable" according to <code>ccache --show-stats</code>
Be warned that this configuration option might affect reproducibility of builds, and could lead to cache poisoning.
See [https://github.com/NixOS/nixpkgs/issues/109033 issue 109033] for more details.


== See also ==
== See also ==