testers.testBuildFailure: fix structuredAttrs support#371337
testers.testBuildFailure: fix structuredAttrs support#371337wolfgangwalther merged 4 commits intoNixOS:masterfrom
Conversation
wolfgangwalther
left a comment
There was a problem hiding this comment.
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. |
ef30e6d to
ac4958b
Compare
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 |
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... |
d493a97 to
03e40ab
Compare
wolfgangwalther
left a comment
There was a problem hiding this comment.
Just a nit, very nice approach now!
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
If `$stdenv/setup` is sourced by `expect-failure.sh`, then the original builder's hooks could be re-run, potentially leading to unintended side-effects.
03e40ab to
e652e9c
Compare
|
I noticed that
testers.testBuildFailurewas not working with__structuredAttrs.The main issues are, when
structuredAttrsis enabled:$__structuredAttrsis not set$outputsis not set$outputsdefined byNIX_ATTRS_SH_FILEis an associative arrayAs per:
nixpkgs/pkgs/stdenv/generic/default-builder.sh
Lines 1 to 3 in ecd810c
$outputsnot being set is fixed by sourcing$NIX_ATTRS_SH_FILE$__structuredAttrsnot being set is fixed by sourcingsetup.sh$outputsbeing unordered is worked-around by passing inhead orig.outputsusingreplaceVarsTest 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
$__structuredAttrsitself 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
$outputsvariable in structured & non-structured attrs.Without structuredAttrs,
$outputsis an array of variable-names, which should be dereferenced to access the actual path. However, with structuredAttrs,$outputsis 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 = relaxedsandbox = truenix-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.