-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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
separateDebugInfo causes impurity (ca-derivations) #151475
Comments
https://www.mail-archive.com/[email protected]/msg00734.html |
Also this is where it's actually added: https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/bintools-wrapper/ld-wrapper.sh#L233-L237. I do think that the rewriting of store paths has to do with this, since they're 'input-addressed' before rewriting, and the linking (thus insertion of build-id) happens before rewriting store paths. Thus the linker takes the input-addressed store path that's embedded (and possibly the folder location too?) and uses that to generate the build-id. Nix then goes on to rewrite the path to be content-addressed, but since the input-addressed path was used as input for the build-id, the 'build path' leaks into the build-id. |
Hmm, I think this is not the build path, but the output path that leaks into the build id (since it's in the rpath of the so, at least). The output path is rewritten after generating the build id. I wonder if setting that ffile-prefix-map option would help here. I'll try it out. I might need to add some more examples of where this is relevant and where it isn't (or try to explain it better). |
Haven't really looked into this much anymore, but would still make ca-derivations a lot more useful. Hopefully we can find something. I remember trying some things (based on suggestions here) and it not leading anywhere. But I didn't document any of it. |
My understanding of the issue: minor changes to .nix expression cause Build ID to change. Example package is Example reproducer:
$ diffoscope ca-default/lib/librt.so.1 ca-tweaked/lib/librt.so.1
--- ca-default/lib/librt.so.1
+++ ca-tweaked/lib/librt.so.1
│┄ File has been modified after NT_GNU_BUILD_ID has been applied.
├── readelf --wide --notes {}
│ @@ -1,12 +1,12 @@
│
│ Displaying notes found in: .note.gnu.property
│ Owner Data size Description
│ GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 Properties: x86 ISA needed: x86-64-baseline
│
│ Displaying notes found in: .note.gnu.build-id
│ Owner Data size Description
│ - GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring) Build ID: 99f5469d20ff97ca606870565f7804f786725ed2
│ + GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring) Build ID: f00a9c4a6154d73e2c955d821a8c573a67156fbf
│
│ Displaying notes found in: .note.ABI-tag
│ Owner Data size Description
│ GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag) OS: Linux, ABI: 2.6.32 If we compare debug info:
Here we see that I think this unexpected
I would say it would be safer to set |
The following hack makes it slightly better (outputs are now almost identical), but Build ID still is not stable (presumably because it gets calculated before $out is overwritten with CA store path). The hack: --- a/pkgs/build-support/setup-hooks/reproducible-builds.sh
+++ b/pkgs/build-support/setup-hooks/reproducible-builds.sh
@@ -5,6 +5,7 @@
NIX_CFLAGS_COMPILE="${NIX_CFLAGS_COMPILE:-} -frandom-seed=$(
outbase="${out##*/}"
randomseed="${outbase:0:10}"
+ randomseed=not-random-at-all
echo $randomseed
)"
export NIX_CFLAGS_COMPILE |
Describe the bug
Note that this bug is specific for content-addressed derivations. When input-addressed, it's a given that introducing env vars that don't do anything will give a different output.
Due to separateDebugInfo inserting a build-id based on the (input-addressed) paths that are used, enabling that option makes a package (that's built using the nixUnstable ca-derivations feature) non-reproducible based on the environment.
E.g. if an environment variable (that isn't used in the build) is set, this causes the build-id to change and thus also the content-addressed package.
A way to resolve this is to not make the build-id based on the contents (+ the path, presumably), but to set it manually to a value (maybe a sha256 of only the contents?). I'm not 100% sure how that should work, but it does not seem too hard to implement.
This is related to NixOS/nix#5220 as well. Hydra is probably doing something it shouldn't, but regardless this should be fixed too.
Steps To Reproduce
Steps to reproduce the behavior:
ca-derivations
experimental feature.nix-shell -p diffoscope --run "diffoscope $(nix-build 1.nix) $(nix-build 2.nix)"
Expected behavior
Build is reproducible and produces the same hash when unrelated environment variables are introduced, even with enableDebugInfo on (in content-addressed mode).
Additional context
Resolving this will improve reproducibility of important derivations, since the ones with enableDebugInfo are typically very low-level core libraries.
Since the Build ID is dependent on the input-addressed path, any change in stdenv / dependencies may cause the build to give a different result, even though the only difference is the Build ID. I think this is undesirable.
Notify maintainers
@regnat -> so you're aware of this issue before rolling out ca-derivations in nixpkgs. Thanks for the great work you've done and are doing!
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.The text was updated successfully, but these errors were encountered: