21 stdenv.mkDerivation (finalAttrs: {
25 src = fetchFromGitHub {
28 rev = "refs/tags/v${finalAttrs.version}";
29 # `git archive` replaces `$Format:%H %D$` in cmake/CcacheVersion.cmake
30 # we need to replace it with something reproducible
31 # see https://github.com/NixOS/nixpkgs/pull/316524
34 's/version_info "([0-9a-f]{40}) .*(tag: v[^,]+).*"/version_info "\1 \2"/g w match' \
35 $out/cmake/CcacheVersion.cmake
38 else # pattern didn't match
42 hash = "sha256-j7Cjr5R/fN/1C6hR9400Y/hwgG++qjPvo9PYyetzrx0=";
51 # When building for Darwin, test/run uses dwarfdump, whereas on
52 # Linux it uses objdump. We don't have dwarfdump packaged for
53 # Darwin, so this patch updates the test to also use objdump on
55 # Additionally, when cross compiling, the correct target prefix
58 src = ./fix-objdump-path.patch;
59 objdump = "${binutils.bintools}/bin/${binutils.targetPrefix}objdump";
78 cmakeFlags = lib.optional (!finalAttrs.finalPackage.doCheck) "-DENABLE_TESTING=OFF";
83 # test/run requires the compgen function which is available in
84 # bashInteractive, but not bash.
86 ] ++ lib.optional stdenv.hostPlatform.isDarwin xcodebuild;
96 "test.trim_dir" # flaky on hydra (possibly filesystem-specific?)
98 ++ lib.optionals stdenv.hostPlatform.isDarwin [
100 "test.fileclone" # flaky on hydra (possibly filesystem-specific?)
107 export HOME=$(mktemp -d)
108 ctest --output-on-failure -E '^(${lib.concatStringsSep "|" badTests})$'
113 # A derivation that provides gcc and g++ commands, but that
114 # will end up calling ccache for the given cacheDir
116 { unwrappedCC, extraConfig }:
117 stdenv.mkDerivation {
118 pname = "ccache-links";
119 inherit (finalAttrs) version;
121 isClang = unwrappedCC.isClang or false;
122 isGNU = unwrappedCC.isGNU or false;
125 inherit (unwrappedCC) lib;
126 nativeBuildInputs = [ makeWrapper ];
127 # Unwrapped clang does not have a targetPrefix because it is multi-target
128 # target is decided with argv0.
132 if unwrappedCC.isClang or false then
135 (lib.optionalString (
136 unwrappedCC ? targetConfig && unwrappedCC.targetConfig != null && unwrappedCC.targetConfig != ""
137 ) "${unwrappedCC.targetConfig}-");
143 local cname="${targetPrefix}$1"
144 if [ -x "${unwrappedCC}/bin/$cname" ]; then
145 makeWrapper ${finalAttrs.finalPackage}/bin/ccache $out/bin/$cname \
146 --run ${lib.escapeShellArg extraConfig} \
147 --add-flags ${unwrappedCC}/bin/$cname
158 for executable in $(ls ${unwrappedCC}/bin); do
159 if [ ! -x "$out/bin/$executable" ]; then
160 ln -s ${unwrappedCC}/bin/$executable $out/bin/$executable
163 for file in $(ls ${unwrappedCC} | grep -vw bin); do
164 ln -s ${unwrappedCC}/$file $out/$file
169 updateScript = nix-update-script { };
173 description = "Compiler cache for fast recompilation of C/C++ code";
174 homepage = "https://ccache.dev";
175 downloadPage = "https://ccache.dev/download.html";
176 changelog = "https://ccache.dev/releasenotes.html#_ccache_${
177 builtins.replaceStrings [ "." ] [ "_" ] finalAttrs.version
179 license = licenses.gpl3Plus;
180 maintainers = with maintainers; [
184 platforms = platforms.unix;
185 mainProgram = "ccache";