What does this package do?
Hi!
This package has very little documentation, so I am unsure whether it's fit for my purpose...
I am looking for a way to use ccache inside Nix builds, to save CI time when rebuilding big packages of which only small bits change. I guess to do this really, one would need disable the sandbox somehow, since the ccache cache needs to be persisted across builds. Or maybe there is another way that a Nix mastermind like @edolstra has in mind :)
Is this doing this? What is this package achieving instead?
same question ^^
relevant code is nix-ccache in flake.nix and cc-wrapper.sh
but i dont see how cc-wrapper.sh is using ccache. probably this is just an early draft
compare this to ccacheStdenv.mkDerivation with cc = ccache.links
# nixpkgs/pkgs/top-level/all-packages.nix
{
# Wrapper that works as gcc or g++
# It can be used by setting in nixpkgs config like this, for example:
# replaceStdenv = { pkgs }: pkgs.ccacheStdenv;
# But if you build in chroot, you should have that path in chroot
# If instantiated directly, it will use $HOME/.ccache as the cache directory,
# i.e. /homeless-shelter/.ccache using the Nix daemon.
# You should specify a different directory using an override in
# packageOverrides to set extraConfig.
#
# Example using Nix daemon (i.e. multiuser Nix install or on NixOS):
# packageOverrides = pkgs: {
# ccacheWrapper = pkgs.ccacheWrapper.override {
# extraConfig = ''
# export CCACHE_COMPRESS=1
# export CCACHE_DIR=/var/cache/ccache
# export CCACHE_UMASK=007
# '';
# };
# You can use a different directory, but whichever directory you choose
# should be owned by user root, group nixbld with permissions 0770.
ccacheWrapper = makeOverridable ({ extraConfig, cc }:
cc.override {
cc = ccache.links {
inherit extraConfig;
unwrappedCC = cc.cc;
};
}) {
extraConfig = "";
inherit (stdenv) cc;
};
ccacheStdenv = lowPrio (makeOverridable ({ stdenv, ... } @ extraArgs:
overrideCC stdenv (buildPackages.ccacheWrapper.override ({
inherit (stdenv) cc;
} // lib.optionalAttrs (builtins.hasAttr "extraConfig" extraArgs) {
extraConfig = extraArgs.extraConfig;
}))) {
inherit stdenv;
});
related: my failed experiment with static build graph
see also my experiment, to implement ccache/distcc in nix
https://discourse.nixos.org/t/distributed-nix-build-split-large-package-into-many-derivations/15979
- dry-run the buildPhase to get all compile objects
- create one derivation per compile object
- build the derivations. can be distributed across multiple machines -> distcc
- link the compile objects
no need for recursive nix, all derivations are generated in nix (not in bash)
It doesn't use ccache, it's just named after it because it provides similar functionality (caching and distributed builds). It should probably be renamed.
aah, of course
to make this work, i had to add recursive-nix to both experimental-features and system-features
full config example
# /etc/nixos/configuration.nix
{
nix.extraOptions = ''
experimental-features = nix-command flakes recursive-nix
system-features = nixos-test benchmark big-parallel kvm recursive-nix
keep-outputs = true
keep-derivations = true
'';
nix.package = pkgs.nixUnstable;
rename ... nixrecc, the recursive nix compiler? nix-objcache?
Ohhh, this is very interesting: https://github.com/NixOS/nix/issues/13 And also this repository. I will keep following, thank you all for the details!