Skip to content

Tracking: migrate NixOS handleTest -> runTest #386873

Description

@roberth

What

  • Change nixos/all-tests.nix to use runTest instead of handleTest.
  • Change the tests to be modules.

Why

Benefits of runTest and runTestOn:

  • Define values for any test option
  • Use imports to compose tests
  • Access the module arguments like hostPkgs and config.node.pkgs
  • Portable to other VM hosts, specifically Darwin
  • Faster evaluation, using a single pkgs instance
  • Documented for external use too

How

Many tests are trivial to migrate, but here's the complete guide, also available in a comment in all-tests.nix.
Testing the darwin support is optional and largely unnecessary.

Changes required to migrate to runTest:

  • Remove any import ../make-test-python.nix or similar calls, leaving only
    the callback function.

  • Convert the function header to make it a module.
    Packages can be taken from the following. For VM host portability, use

    • config.node.pkgs.<name> or config.nodes.foo.nixpkgs.pkgs.<name> to refer
      to the Nixpkgs used on the VM guest(s).
    • hostPkgs.<name> when invoking commands on the VM host (e.g. in Python
      os.system("foo"))
  • Since the runTest argument is a module instead of a function, arguments
    must be passed as option definitions.
    You may declare explicit options for the test parameter(s), or use the
    less explicit _module.args.<name> to pass arguments to the module.

    Example call with arguments:

    runTest {
      imports = [ ./test.nix ];
      _module.args.getPackage = pkgs: pkgs.foo_1_2;
    }
    
  • If your test requires any definitions in nixpkgs.* options, set
    node.pkgsReadOnly = false in the test configuration.

Test matrix

Pass the runTest function into the test file and use it instead of make-test-python.nix or similar.

Context

Written as a Nixpkgs maintainer, nothing special.

Activity

  1. added
    6.topic: nixos
    3.skill: trivial
    6.topic: darwin
    3.skill: good-first-bug
    6.topic: hygiene
    6.topic: developer experience
    11.by: package-maintainer
    6.topic: portability
    5.scope: tracking
    6.topic: testing
    on Mar 3, 2025
  2. pinned this issue on Mar 4, 2025
  3. 286 remaining items

  4. self-assigned this
    on May 30, 2025
  5. misuzu commented on Jun 6, 2025

    @misuzu
    Contributor

    Closed by accident?

  6. Prince213 commented on Jun 6, 2025

    @Prince213
    Member

    Yeah, you are right.

  7. JohnRTitor commented on Jun 6, 2025

    @JohnRTitor
    Member

    We might need a treewide change to address this once and for all.

    @Prince213 since you have assigned yourself, I assume you want to tackle this?

  8. Prince213 commented on Jun 6, 2025

    @Prince213
    Member

    Yes, as stated earlier in #410569 (comment). I expect to work on this in the coming week.

  9. rnhmjoj commented on Jul 11, 2025

    @rnhmjoj
    Contributor

    Thank you, Prince213.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

11.by: package-maintainer3.skill: good-first-bug3.skill: trivial5.scope: tracking6.topic: darwin6.topic: developer experience6.topic: hygiene6.topic: nixos6.topic: portability6.topic: testing

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions