From 7e3c66897a1c857dd68844fe7227dd078666fb11 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 21 Feb 2025 10:14:58 +0100 Subject: [PATCH] nixos: Document handleTest deprecation --- nixos/tests/all-tests.nix | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index dcb0f1fe0a27..6b9f5a047c63 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -30,8 +30,47 @@ let # (if it is a function). discoverTests (val { inherit system pkgs; }) else val; + + /** + Evaluate a test and return a derivation that runs the test as its builder. + + This function is deprecated in favor of runTest and runTestOn, which works + by passing a module instead of a specific set of arguments. + 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 + + 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.` or `config.nodes.foo.nixpkgs.pkgs.` to refer + to the Nixpkgs used on the VM guest(s). + - `hostPkgs.` 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.` 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. + */ handleTest = path: args: discoverTests (import path ({ inherit system pkgs; } // args)); + + /** See handleTest */ handleTestOn = systems: path: args: if elem system systems then handleTest path args else {}; @@ -61,7 +100,9 @@ let if elem system systems then runTest arg else {}; }) + /** See https://nixos.org/manual/nixos/unstable/#sec-calling-nixos-tests */ runTest + /** See https://nixos.org/manual/nixos/unstable/#sec-calling-nixos-tests */ runTestOn ;