Skip to content

nixos/testing: fix testScript eval for functions without elipsis#501599

Merged
Mic92 merged 1 commit intoNixOS:masterfrom
Mic92:fix-testscript-containers-arg
Mar 21, 2026
Merged

nixos/testing: fix testScript eval for functions without elipsis#501599
Mic92 merged 1 commit intoNixOS:masterfrom
Mic92:fix-testscript-containers-arg

Conversation

@Mic92
Copy link
Member

@Mic92 Mic92 commented Mar 20, 2026

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")

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

@Mic92 Mic92 changed the title nixos/testing: fix testScript eval for functions without ... nixos/testing: fix testScript eval for functions without elipsis Mar 20, 2026
v:
if lib.isFunction v then
# Only pass args the testScript function expects.
args: v (builtins.intersectAttrs (lib.functionArgs v) args)
Copy link
Member Author

Choose a reason for hiding this comment

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

We could think later about making the old form a warning, but for now we should probably fix evaluation in staging asap.

@Mic92
Copy link
Member Author

Mic92 commented Mar 20, 2026

@kmein @jfly fyi

@Mic92
Copy link
Member Author

Mic92 commented Mar 20, 2026

Mainly tested eval.

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 9.needs: reviewer This PR currently has no reviewers requested and needs attention. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: testing Tooling for automated testing of packages and modules labels Mar 20, 2026
@vcunat
Copy link
Member

vcunat commented Mar 20, 2026

Shouldn't this target nixpkgs master? The commit being fixed by this is in there already.

Copy link
Contributor

@jfly jfly left a comment

Choose a reason for hiding this comment

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

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Member

Choose a reason for hiding this comment

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

Got stuck due to indecision two years ago

Copy link
Member

Choose a reason for hiding this comment

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

What's more likely to happen, testScript = { ... }: '' '' or testScript = args: '' ''?
AFAIU we can't fix both.

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 1 This PR was reviewed and approved by one person. and removed 9.needs: reviewer This PR currently has no reviewers requested and needs attention. labels Mar 20, 2026
Copy link
Member

@Ma27 Ma27 left a comment

Choose a reason for hiding this comment

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

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 }:

@roberth
Copy link
Member

roberth commented Mar 20, 2026

We can't discern { nodes }: from { nodes, ... }:, so a warning is not possible.

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.

Ma27 added a commit to Ma27/nixpkgs that referenced this pull request Mar 21, 2026
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
@Ma27 Ma27 mentioned this pull request Mar 21, 2026
13 tasks
@Mic92 Mic92 changed the base branch from staging-nixos to master March 21, 2026 14:52
@nixpkgs-ci nixpkgs-ci bot closed this Mar 21, 2026
@nixpkgs-ci nixpkgs-ci bot reopened this Mar 21, 2026
github-actions[bot]

This comment was marked as outdated.

@Mic92 Mic92 changed the base branch from master to staging-nixos March 21, 2026 14:53
@nixpkgs-ci nixpkgs-ci bot closed this Mar 21, 2026
@nixpkgs-ci nixpkgs-ci bot reopened this Mar 21, 2026
@github-actions github-actions bot dismissed their stale review March 21, 2026 14:53

Review dismissed automatically

Mic92 pushed a commit to Ma27/nixpkgs that referenced this pull request Mar 21, 2026
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")
@Mic92 Mic92 force-pushed the fix-testscript-containers-arg branch from 95a43fd to 00f5ae0 Compare March 21, 2026 15:06
@Mic92 Mic92 changed the base branch from staging-nixos to master March 21, 2026 15:06
@nixpkgs-ci nixpkgs-ci bot closed this Mar 21, 2026
@nixpkgs-ci nixpkgs-ci bot reopened this Mar 21, 2026
@Mic92 Mic92 enabled auto-merge March 21, 2026 15:07
@Mic92 Mic92 added this pull request to the merge queue Mar 21, 2026
Merged via the queue into NixOS:master with commit 5e3302e Mar 21, 2026
36 of 37 checks passed
@Mic92 Mic92 deleted the fix-testscript-containers-arg branch March 21, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: testing Tooling for automated testing of packages and modules 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants