nixos/testing: fix testScript eval for functions without elipsis#501599
nixos/testing: fix testScript eval for functions without elipsis#501599Mic92 merged 1 commit intoNixOS:masterfrom
Conversation
...| v: | ||
| if lib.isFunction v then | ||
| # Only pass args the testScript function expects. | ||
| args: v (builtins.intersectAttrs (lib.functionArgs v) args) |
There was a problem hiding this comment.
We could think later about making the old form a warning, but for now we should probably fix evaluation in staging asap.
|
Mainly tested eval. |
|
Shouldn't this target nixpkgs master? The commit being fixed by this is in there already. |
jfly
left a comment
There was a problem hiding this comment.
Thanks for the quickfix! One nit inline that hopefully doesn't matter IRL (I haven't checked).
| v: | ||
| if lib.isFunction v then | ||
| # Only pass args the testScript function expects. | ||
| args: v (builtins.intersectAttrs (lib.functionArgs v) args) |
There was a problem hiding this comment.
Non blocking: This wouldn't work for functions that only take a positional parameter:
nix-repl> lib.functionArgs (args: 42)
{ }
nix-repl> lib.functionArgs ({}: 42)
{ }
Does nix provide some mechanism to detect such a difference?
There was a problem hiding this comment.
Got stuck due to indecision two years ago
There was a problem hiding this comment.
What's more likely to happen, testScript = { ... }: '' '' or testScript = args: '' ''?
AFAIU we can't fix both.
Ma27
left a comment
There was a problem hiding this comment.
If we do this, I'd much prefer an eval warning for deprecation and a fix in-tree for all affected tests, it's not that many after all:
nixos/tests/spire.nix
61: testScript =
62: { nodes }:
nixos/tests/nixops/default.nix
59: testScript =
60: { nodes }:
nixos/tests/drbd.nix
57: testScript =
58: { nodes }:
nixos/tests/rspamd-trainer.nix
139: testScript =
140: { nodes }:
nixos/tests/parsedmarc/default.nix
93: testScript =
94: { nodes }:
204: testScript =
205: { nodes }:
nixos/tests/munge.nix
14: testScript =
15: { nodes }:
nixos/tests/discourse.nix
167: testScript =
168: { nodes }:
nixos/tests/web-apps/snipe-it.nix
46: testScript =
47: { nodes }:
nixos/tests/web-apps/peering-manager.nix
20: testScript =
21: { nodes }:
|
We can't discern Fixing 9 tests and letting out of tree users fix it for themselves without any hint whatsoever is the only other option, it seems. I don't think that's preferable. |
The addition of the nspawn backend introduced a second argument passed to the attribute-set passed to `testScript`, i.e. containers[1]. Note: this is by no means intended to replace the compat fix from NixOS#501599, I believe we shouldn't have deprecated invocations in-tree at all, hence the change on this end. This is intended to only fix address the fallout from NixOS#478109, `nixosTests.parsedmarc` fails due to some postfix module changes to evaluate and the test of `peering-manasger` still seems broken. [1] NixOS#478109
The addition of the nspawn backend introduced a second argument passed to the attribute-set passed to `testScript`, i.e. containers[1]. Note: this is by no means intended to replace the compat fix from NixOS#501599, I believe we shouldn't have deprecated invocations in-tree at all, hence the change on this end. This is intended to only fix address the fallout from NixOS#478109, `nixosTests.parsedmarc` fails due to some postfix module changes to evaluate and the test of `peering-manasger` still seems broken. [1] NixOS#478109
The nspawn container support (23f1e63) added a `containers` argument to the testScript caller. This breaks tests whose testScript uses strict pattern matching without ellipsis, e.g. `{ nodes }:`, since Nix rejects unexpected arguments. Use `builtins.intersectAttrs` to only pass arguments the function actually expects, making the caller forward-compatible with future argument additions. Fixes: 23f1e63 ("nixos/test-driver: add support for nspawn containers")
95a43fd to
00f5ae0
Compare
The nspawn container support (23f1e63) added a
containersargument to the testScript caller. This breaks tests whose testScript uses strict pattern matching without ellipsis, e.g.{ nodes }:, since Nix rejects unexpected arguments.Use
builtins.intersectAttrsto only pass arguments the function actually expects, making the caller forward-compatible with future argument additions.Fixes: 23f1e63 ("nixos/test-driver: add support for nspawn containers")
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.