From 83f0bccc89b6cd6de576609bb49abcb3f507d58e Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Sat, 31 Oct 2020 17:29:54 +0100 Subject: [PATCH] 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. --- pkgs/build-support/setup-hooks/reproducible-builds.sh | 4 ++++ pkgs/stdenv/generic/default.nix | 1 + 2 files changed, 5 insertions(+) create mode 100644 pkgs/build-support/setup-hooks/reproducible-builds.sh diff --git a/pkgs/build-support/setup-hooks/reproducible-builds.sh b/pkgs/build-support/setup-hooks/reproducible-builds.sh new file mode 100644 index 000000000000..2d8db6ff7d3c --- /dev/null +++ b/pkgs/build-support/setup-hooks/reproducible-builds.sh @@ -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##*/}" diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index eeddb584a3d5..c7c3bb9f3f3f 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -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) ];