Skip to content

Commit

Permalink
stdenv: trim random seed to avoid reference cycles
Browse files Browse the repository at this point in the history
Using the full store hash as the random seed occasionally caused
reference cycles when the invocation was stored in output artifacts.
For example, cross-compiled gcc was failing due to this:
https://hydra.nixos.org/eval/1631713#tabs-now-fail

Simply truncating the hash is sufficient to avoid this.
  • Loading branch information
r-burns committed Dec 24, 2020
1 parent 85298db commit 61a6d1a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkgs/build-support/setup-hooks/reproducible-builds.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# 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##*/}"
# We also truncate the hash so that it cannot cause reference cycles.
export NIX_CFLAGS_COMPILE+=" -frandom-seed=$(
outbase="${out##*/}"
randomseed="${outbase:0:10}"
echo $randomseed
)"

0 comments on commit 61a6d1a

Please sign in to comment.