-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
testers.testBuildFailure: fix structuredAttrs support #371337
base: master
Are you sure you want to change the base?
testers.testBuildFailure: fix structuredAttrs support #371337
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ty for the fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do a a real review later.
I forgot to mention it in my first message but your github ticket has a nice description of the issue, please copy it in the commit message. It helps when running |
6852a9a
to
ef30e6d
Compare
I defer the review to the real boss @wolfgangwalther who made such huge contributions to structured attrs (thanks again). Happy with this PR goal. |
Fixes `testers.testBuildFailure` compatibility with `__structuredAttrs`. The two main issues are, when `structuredAttrs` is enabled: - `$__structuredAttrs` is not set - `$outputs` is not set `$__structuredAttrs` not being set is fixed by checking for `$NIX_ATTRS_SH_FILE`, as per pkgs/stdenv/generic/setup.sh `$outputs` not being set is fixed by sourcing `$NIX_ATTRS_SH_FILE`, as-per pkgs/stdenv/generic/default-builder.sh
ef30e6d
to
ac4958b
Compare
@@ -35,7 +35,28 @@ echo "testBuildFailure: Original builder produced exit code: $r" | |||
# ----------------------------------------- | |||
# Write the build log to the default output | |||
# | |||
# # from stdenv setup.sh | |||
# # based on stdenv setup.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say we should just do 2/3 of what default-builder.sh
does at this stage, namely the loading of the attrs.sh file and then sourcing of stdenv/setup. Of course, running genericBuild
doesn't make sense.
I assume this could simplify the logic in here quite a bit.
But, we have this comment further up:
# Requirements:
# This runs before, without and after stdenv. Do not modify the environment;
# especially not before invoking the original builder. For example, use
# "@" substitutions instead of PATH.
# Do not export any variables.
I don't quite understand what "before, without and after stdenv" means. Going through the code, I think it would be fine to source stdenv at this stage, i.e. after the original builder ran.
@roberth, you introduced this file and comment - could you give your input here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not export any variables.
My current impl is definitely violating this. It is at least happening after invoking the original builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could just encapsulate sourcing the vars in a subshell though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question: What exactly will come after the original builder has already been run and we finish the expect-failure.sh
script? Nothing anymore, right? So why would sourcing stdenv/setup hurt at this stage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback and guidance.
I've pushed this as a fixup
commit. I can squash once @roberth has had chance to chime in.
Just source `$stdenv/setup` instead of re-implementing it.
I like the approach now, let's wait for more feedback.
Ideally, I'd add a regression test for this. But I don't see any existing tests to add to; Looking at the stdenv tests, that has a bunch of stuff I don't currently understand relating to Or is there a test file somewhere I missed? |
You could maybe run all tests for |
Turns out I'm blind. I've added some basic tests that piggy-back on existing tests. However the multiOutput test is failing with structuredAttrs...
I haven't had chance to debug yet, but my initial thoughts are: EDIT: yes, with EDIT2: I'm wondering if it'd be best to simply write the states&logs to all outputs, instead of attempting to detect the "default"? EDIT3: reading through the docs, it does seem like the output order is significant. Therefore it seems like an oversight in EDIT4: For now, I've solved this by passing in the "default" output name using |
`$outputs` is unordered when `__structuredAttrs` is enabled, so we pass in the default output name with `replaceVars`
So the problem here seems to be that bash associative arrays are hash-ordered and thus the order is not preserved. attrs.json should have the same information with the right order. Not sure how to best access this, yet. It'd seem possibly useful to have stdenv set a variable to point at the default output, even for structuredAttrs. But I'm not sure whether we can use But you should be able to use it here, I guess. Extract outputs with jq for structuredAttrs, then take the first. Might not actually end up nicer than what you have right now, though :D |
Yeah, I thought about that, but figured it'd be better to inject the head-output from the drv-args, rather than inject
Agreed. This would be the cleanest solution. It seems a bit beyond the scope of this PR, but maybe it'd be worth it... |
I noticed that
testers.testBuildFailure
was not working with__structuredAttrs
.The main issues are, when
structuredAttrs
is enabled:$__structuredAttrs
is not set$outputs
is not set$outputs
defined byNIX_ATTRS_SH_FILE
is an associative arrayAs per:
nixpkgs/pkgs/stdenv/generic/default-builder.sh
Lines 1 to 3 in ecd810c
$outputs
not being set is fixed by sourcing$NIX_ATTRS_SH_FILE
$__structuredAttrs
not being set is fixed by sourcingsetup.sh
$outputs
being unordered is worked-around by passing inhead orig.outputs
usingreplaceVars
Test using:
Original Description
The main issue was that when structuredAttrs is enabled, none of the attr-vars get sourced. Therefore accessing any of them results in "unbound variable" errors.
This is fixed by sourcing
$NIX_ATTRS_SH_FILE
, as-per 8bc5104nixpkgs/pkgs/stdenv/generic/default-builder.sh
Line 1 in ecd810c
However
$__structuredAttrs
itself is still unbound, as it is not declared by that file. To work around this, I injected the value usingreplaceVars
.Once the main issue was resolved, I still had to re-work some implementation details due to differences in the
$outputs
variable in structured & non-structured attrs.Without structuredAttrs,
$outputs
is an array of variable-names, which should be dereferenced to access the actual path. However, with structuredAttrs,$outputs
is an associative array:Tested using:
Closes #355953
Also, uncomments a neovim test that was disabled in #352727 due to this bug
cc @wolfgangwalther @teto
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.