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