diff --git a/pkgs/development/tools/misc/ccache/default.nix b/pkgs/development/tools/misc/ccache/default.nix index 5c83adfe4a8c..2cd00f51d9d4 100644 --- a/pkgs/development/tools/misc/ccache/default.nix +++ b/pkgs/development/tools/misc/ccache/default.nix @@ -1,4 +1,4 @@ -{stdenv, fetchurl, runCommand, gcc}: +{stdenv, fetchurl, runCommand, gcc, zlib}: let ccache = @@ -9,17 +9,19 @@ stdenv.mkDerivation { sha256 = "04ax6ks49b6rn57hx4v9wbvmsfmw6ipn0wyfqwhh4lzw70flv3r7"; }; + buildInputs = [ zlib ]; + passthru = { # A derivation that provides gcc and g++ commands, but that # will end up calling ccache for the given cacheDir - links = cacheDir : (runCommand "ccache-links" + links = extraConfig : (runCommand "ccache-links" { inherit (gcc) langC langCC; } '' mkdir -p $out/bin if [ $langC -eq 1 ]; then cat > $out/bin/gcc << EOF #!/bin/sh - export CCACHE_DIR=${cacheDir} + ${extraConfig} exec ${ccache}/bin/ccache ${gcc.gcc}/bin/gcc "\$@" EOF chmod +x $out/bin/gcc @@ -27,7 +29,7 @@ stdenv.mkDerivation { if [ $langCC -eq 1 ]; then cat > $out/bin/g++ << EOF #!/bin/sh - export CCACHE_DIR=${cacheDir} + ${extraConfig} exec ${ccache}/bin/ccache ${gcc.gcc}/bin/g++ "\$@" EOF chmod +x $out/bin/g++ diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 01cae669fed1..f51000ee6286 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -2895,10 +2895,12 @@ let # Wrapper that works as gcc or g++ # It can be used by setting in nixpkgs config like this, for example: - # replaceStdenv = { pkgs }: (pkgs.ccacheStdenv "/var/ccache"); + # replaceStdenv = { pkgs }: pkgs.ccacheStdenv "exports CCACHE_DIR=/var/ccache"; # But if you build in chroot, you should have that path in chroot - ccacheWrapper = cacheDir: wrapGCC (ccache.links cacheDir); - ccacheStdenv = cacheDir: overrideGCC stdenv (ccacheWrapper cacheDir); + # If instantiated directly, it will use the HOME/.ccache as cache directory. + ccacheWrapper = { extraConfig ? "" }: wrapGCC (ccache.links extraConfig); + ccacheStdenv = extraConfig: overrideGCC stdenv + (ccacheWrapper { inherit extraConfig; } ); complexity = callPackage ../development/tools/misc/complexity { };