Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[staging] stdenv: trim random seed to avoid reference cycles #106954

Merged
merged 1 commit into from Jan 2, 2021

Conversation

r-burns
Copy link
Contributor

@r-burns r-burns commented Dec 15, 2020

Using the full store hash as the random seed occasionally caused
reference cycles when the compiler 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.

cc @symphorien: #102251 (comment)

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@r-burns
Copy link
Contributor Author

r-burns commented Dec 23, 2020

cc @andir would appreciate your thoughts on this - hoping to get this fixed soon since it is breaking a good number of cross packages

@@ -1,4 +1,7 @@
# 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.
local outbase="${out##*/}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does local really just span this file? Setup hooks are sourced via stdenv, right?

Copy link
Contributor Author

@r-burns r-burns Dec 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think you are right. How about putting this in a getRandomSeed function? I can't just inline the basename + trimming because bash won't do the nested expansion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I ended up using a command substitution. Looks a little odd but avoids any namespace pollution

pkgs/build-support/setup-hooks/reproducible-builds.sh Outdated Show resolved Hide resolved
@andir
Copy link
Member

andir commented Dec 23, 2020 via email

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.
@r-burns r-burns changed the title stdenv: trim random seed to avoid reference cycles [staging] stdenv: trim random seed to avoid reference cycles Dec 31, 2020
@r-burns
Copy link
Contributor Author

r-burns commented Jan 2, 2021

cc @dezgeg as you are the maintainer for release-cross.nix bootstrapTools

@andir andir merged commit c2884c4 into NixOS:staging Jan 2, 2021
Staging automation moved this from WIP to Done Jan 2, 2021
@r-burns r-burns deleted the randomseed branch January 2, 2021 18:37
@r-burns r-burns mentioned this pull request Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Staging
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants