stdenv: add -frandom-seed to NIX_CFLAGS_COMPILE for reproducibility

This adds -frandom-seed to each compiler invocation in stdenv. The
object here is to make the compierl invocations produce the same output
every time they are called (for the same derivation). When the
-frandom-seed option is not set the compiler will use a combination of
random numbers (in GCC's case from /dev/urandom) and the durrent time to
produce a "random" input per file. This can (among other things) lead to
different ordering of symbols in the produced object files.

For reason of reproducibility we prefer having the same derivation
produce the exact same outputs. This is not a silver bullet but one way
to tame the compiler.
This commit is contained in:
Andreas Rammhold 2020-10-31 17:29:54 +01:00
parent b7ef4d7dda
commit 83f0bccc89
2 changed files with 5 additions and 0 deletions

View File

@ -0,0 +1,4 @@
# Use the last part of the out path as hash input for the build.
# This should ensure that it is deterministic across rebuilds of the same
# derivation and not easily collide with other builds.
export NIX_CFLAGS_COMPILE+=" -frandom-seed=${out##*/}"

View File

@ -70,6 +70,7 @@ let
../../build-support/setup-hooks/move-sbin.sh
../../build-support/setup-hooks/move-lib64.sh
../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh
../../build-support/setup-hooks/reproducible-builds.sh
# TODO use lib.optional instead
(if hasCC then cc else null)
];