Skip to content

NixOS test framework: add overriding methods#421480

Merged
roberth merged 2 commits intoNixOS:masterfrom
roberth:nixos-test-overriding-simple
Jul 6, 2025
Merged

NixOS test framework: add overriding methods#421480
roberth merged 2 commits intoNixOS:masterfrom
roberth:nixos-test-overriding-simple

Conversation

@roberth
Copy link
Member

@roberth roberth commented Jul 1, 2025

This is the first part of #299542, adding the test framework overriding machinery only, without the opinionated setPackage module.
These are useful primitives, regardless of how we'll end up using them in this repo.

The remainder of #299542 does not touch these additions.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other contributing documentation in corresponding paths.

Add a 👍 reaction to pull requests you find important.

@roberth roberth changed the title Nixos test overriding simple NixOS test framework: add overriding methods Jul 1, 2025
@roberth roberth mentioned this pull request Jul 1, 2025
13 tasks
@roberth roberth requested a review from wolfgangwalther July 1, 2025 12:25
@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. 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 8.has: documentation This PR adds or changes documentation labels Jul 1, 2025
@roberth roberth force-pushed the nixos-test-overriding-simple branch 2 times, most recently from 16fadf7 to a71b1d1 Compare July 4, 2025 14:14
Copy link
Contributor

@wolfgangwalther wolfgangwalther left a comment

Choose a reason for hiding this comment

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

Reading through it, this LGTM.

I did not actually run the tests or try to use it, but #299542 had done so already, so confidence is still high.

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jul 4, 2025
@roberth roberth force-pushed the nixos-test-overriding-simple branch from a71b1d1 to f2b3aeb Compare July 6, 2025 11:39
@roberth roberth merged commit 7845abc into NixOS:master Jul 6, 2025
16 of 17 checks passed
@trofi
Copy link
Contributor

trofi commented Jul 7, 2025

Bisect says 63e2606 nixos.runTest: Add extend, overrideTestDerivation introduced attributes that fail to eval with error that can't be caught. For example:

$ nix eval --impure --expr 'with import ./. {}; bind.tests.kubernetes-dns-multi-node.extend'
error:
       … while evaluating a branch condition
         at nixos/tests/all-tests.nix:23:5:
           22|     val:
           23|     if isAttrs val then
             |     ^
           24|       if hasAttr "test" val then

       … while calling the 'isAttrs' builtin
         at nixos/tests/all-tests.nix:23:8:
           22|     val:
           23|     if isAttrs val then
             |        ^
           24|       if hasAttr "test" val then

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: function 'extend' called without required argument 'modules'
       at nixos/lib/testing/call-test.nix:31:7:
           30|     passthru.extend =
           31|       args@{
             |       ^
           32|         modules,

@wolfgangwalther
Copy link
Contributor

Hm. .extend is a function, but is not expected to be "called" via command line like this. bind.tests.kubernetes-dns-multi-node is a derivation right? Why do you recurse into its attributes / where does that happen?

@trofi
Copy link
Contributor

trofi commented Jul 7, 2025

It happens as part of an evaluatability test of reachable attributes in nixpkgs I run time to time locally: https://trofi.github.io/posts/309-listing-all-nixpkgs-packages.html

I don't think extend is a valid function here. It does not get called via eval here either: it only gets evaluated (as a lambda) and fails.

$ nix repl -f .

nix-repl> builtins.isFunction bind.tests.kubernetes-dns-multi-node.extend
error:
       … while calling the 'isFunction' builtin
         at «string»:1:1:
            1| builtins.isFunction bind.tests.kubernetes-dns-multi-node.extend
             | ^

       … while evaluating a branch condition
         at nixos/tests/all-tests.nix:23:5:
           22|     val:
           23|     if isAttrs val then
             |     ^
           24|       if hasAttr "test" val then

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: function 'extend' called without required argument 'modules'
       at nixos/lib/testing/call-test.nix:31:7:
           30|     passthru.extend =
           31|       args@{
             |       ^
           32|         modules,

@wolfgangwalther
Copy link
Contributor

I see. This seems to happen, because discoverTests tries to call that function. This will affect all "old style" (handleTest / handleTestOn etc.) tests.

@roberth
Copy link
Member Author

roberth commented Jul 7, 2025

discoverTests and callTest. This is at least the third time they come up after a seemingly innocuous change.
When the runTest migration is complete we'll finally get rid of that, but for now I'll try and find a workaround again.

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 8.has: documentation This PR adds or changes documentation 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.

3 participants