Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What does this package do? #1

Open
arximboldi opened this issue Oct 14, 2021 · 4 comments
Open

What does this package do? #1

arximboldi opened this issue Oct 14, 2021 · 4 comments

Comments

@arximboldi
Copy link

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?

@milahu
Copy link

milahu commented Jan 5, 2022

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)

@edolstra
Copy link
Owner

edolstra commented Jan 5, 2022

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.

@milahu
Copy link

milahu commented Jan 5, 2022

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?

@arximboldi
Copy link
Author

Ohhh, this is very interesting:
NixOS/nix#13
And also this repository. I will keep following, thank you all for the details!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants