nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib
2, stdenv
3, nukeReferences
4, langC
5, langCC
6, runtimeShell
7}:
8
9let
10 enableChecksum = (with stdenv; buildPlatform == hostPlatform && hostPlatform == targetPlatform) && langC && langCC && !stdenv.hostPlatform.isDarwin;
11in
12(pkg: pkg.overrideAttrs (previousAttrs: lib.optionalAttrs enableChecksum {
13 outputs = previousAttrs.outputs ++ lib.optionals enableChecksum [ "checksum" ];
14 # This is a separate phase because gcc assembles its phase scripts
15 # in bash instead of nix (we should fix that).
16 preFixupPhases = (previousAttrs.preFixupPhases or []) ++ [ "postInstallSaveChecksumPhase" ];
17 #
18 # gcc uses an auxiliary utility `genchecksum` to md5-hash (most of) its
19 # `.o` and `.a` files prior to linking (in case the linker is
20 # nondeterministic). Since we want to compare across gccs built from two
21 # separate derivations, we wrap `genchecksum` with a `nuke-references`
22 # call. We also stash copies of the inputs to `genchecksum` in
23 # `$checksum/inputs/` -- this is extremely helpful for debugging since
24 # it's hard to get Nix to not delete the $NIX_BUILD_TOP of a successful
25 # build.
26 #
27 postInstallSaveChecksumPhase = ''
28 mv gcc/build/genchecksum gcc/build/.genchecksum-wrapped
29 cat > gcc/build/genchecksum <<\EOF
30 #!${runtimeShell}
31 ${nukeReferences}/bin/nuke-refs $@
32 for INPUT in "$@"; do install -Dt $INPUT $checksum/inputs/; done
33 exec build/.genchecksum-wrapped $@
34 EOF
35 chmod +x gcc/build/genchecksum
36 rm gcc/*-checksum.*
37 make -C gcc cc1-checksum.o cc1plus-checksum.o
38 install -Dt $checksum/checksums/ gcc/cc*-checksum.o
39 '';
40}))