Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/build-helpers/testers.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ pkgs.testers.runNixOSTest ({ lib, ... }: {

## `nixosTest` {#tester-nixosTest}

:::{.warning}
This function is deprecated in favor of [`runNixOSTest`](#tester-runNixOSTest).
The reason why it's bad is that when you pass it a function, it is invoked via `callPackage`.
This is somewhat incompatible with the module system and running cross-platform:
- The choice of packages is ambiguous when the VM host platform is not Linux.
`nixosTest` could in theory pick either:
- `hostPkgs` for packages to run on the VM host
- or `config.node.pkgs` for packages that run in one of the VMs
- The return value of the passed function should have been a module, but `nixosTest` does not actually allow that.
:::
Run a NixOS VM network test using this evaluation of Nixpkgs.

NOTE: This function is primarily for external use. NixOS itself uses `make-test-python.nix` directly. Packages defined in Nixpkgs [reuse NixOS tests via `nixosTests`, plural](#ssec-nixos-tests-linking).
Expand Down
2 changes: 1 addition & 1 deletion nixos/lib/testing/legacy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ in
config = {
nodes = mkIf options.machine.isDefined (
lib.warn
"In test `${config.name}': The `machine' attribute in NixOS tests (pkgs.nixosTest / make-test-python.nix / testing-python.nix / makeTest) is deprecated. Please set the equivalent `nodes.machine'."
"In test `${config.name}': The `machine' attribute in NixOS tests is deprecated. Please set the equivalent `nodes.machine'."
{ inherit (config) machine; }
);
};
Expand Down
2 changes: 1 addition & 1 deletion nixos/lib/testing/nixos-test-base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ in
key = "no-revision";
# Make the revision metadata constant, in order to avoid needless retesting.
# The human version (e.g. 21.05-pre) is left as is, because it is useful
# for external modules that test with e.g. testers.nixosTest and rely on that
# for external modules that test with e.g. testers.runNixOSTest and rely on that
# version number.
config.system.nixos = {
revision = mkForce "constant-nixos-revision";
Expand Down
8 changes: 7 additions & 1 deletion nixos/tests/nixops/default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
These tests may be run with:

nix-build -A nixosTests.nixops

*/
{ pkgs, ... }:
let
inherit (pkgs) lib;
Expand All @@ -19,7 +25,7 @@ let
passthru.override = args': testsForPackage (args // args');
};

testLegacyNetwork = { nixopsPkg, ... }: pkgs.testers.nixosTest ({
testLegacyNetwork = { nixopsPkg, ... }: pkgs.testers.runNixOSTest ({
name = "nixops-legacy-network";
nodes = {
deployer = { config, lib, nodes, pkgs, ... }: {
Expand Down
10 changes: 7 additions & 3 deletions nixos/tests/nixos-test-driver/lib-extend.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
These tests may be run with:

nix-build -A nixosTests.nixos-test-driver.lib-extend

*/
{ pkgs, ... }:

let
Expand All @@ -22,10 +28,8 @@ let
testScript = "";
};

inherit (patchedPkgs.testers) nixosTest runNixOSTest;
evaluationNixosTest = nixosTest testBody;
inherit (patchedPkgs.testers) runNixOSTest;
evaluationRunNixOSTest = runNixOSTest testBody;
in {
nixosTest = evaluationNixosTest.driver.nodes.machine.system.build.toplevel;
runNixOSTest = evaluationRunNixOSTest.driver.nodes.machine.system.build.toplevel;
}
2 changes: 1 addition & 1 deletion nixos/tests/spark/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let
sparkCluster = testSparkCluster args;
passthru.override = args': testsForPackage (args // args');
};
testSparkCluster = { sparkPackage, ... }: pkgs.testers.nixosTest ({
testSparkCluster = { sparkPackage, ... }: pkgs.testers.runNixOSTest ({
name = "spark";

nodes = {
Expand Down
5 changes: 3 additions & 2 deletions pkgs/build-support/testers/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, pkgsLinux, buildPackages, lib, callPackage, runCommand, stdenv, substituteAll, testers }:
{ config, pkgs, pkgsLinux, buildPackages, lib, callPackage, runCommand, stdenv, substituteAll, testers }:
# Documentation is in doc/builders/testers.chapter.md
{
# See https://nixos.org/manual/nixpkgs/unstable/#tester-testBuildFailure
Expand Down Expand Up @@ -112,7 +112,7 @@

# See doc/builders/testers.chapter.md or
# https://nixos.org/manual/nixpkgs/unstable/#tester-invalidateFetcherByDrvHash
nixosTest =
${if config.allowAliases then "nixosTest" else null} =
let
/* The nixos/lib/testing-python.nix module, preapplied with arguments that
* make sense for this evaluation of Nixpkgs.
Expand All @@ -135,6 +135,7 @@
else test;
calledTest = lib.toFunction loadedTest pkgs;
in
lib.warn "testers.nixosTest is deprecated. Use testers.runNixOSTest instead. See https://nixos.org/manual/nixpkgs/unstable/#tester-runNixOSTest"
nixosTesting.simpleTest calledTest;

hasPkgConfigModule =
Expand Down
4 changes: 2 additions & 2 deletions pkgs/build-support/testers/test/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ testers, lib, pkgs, hello, runCommand, ... }:
{ config, testers, lib, pkgs, hello, runCommand, ... }:
let
pkgs-with-overlay = pkgs.extend(final: prev: {
proof-of-overlay-hello = prev.hello;
Expand Down Expand Up @@ -27,7 +27,7 @@ lib.recurseIntoAttrs {

# Check that the wiring of nixosTest is correct.
# Correct operation of the NixOS test driver should be asserted elsewhere.
nixosTest-example = pkgs-with-overlay.testers.nixosTest ({ lib, ... }: {
${if config.allowAliases then "nixosTest-example" else null} = pkgs-with-overlay.testers.nixosTest ({ lib, ... }: {
name = "nixosTest-test";
nodes.machine = { pkgs, ... }: {
system.nixos = dummyVersioning;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ let
};
});
in
testers.nixosTest {
testers.runNixOSTest {
name = "nixpkgs-trivial-builders";
nodes.machine = { ... }: {
virtualisation.writableStore = true;
Expand Down
4 changes: 0 additions & 4 deletions pkgs/test/nixos-functions/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/*

This file is a test that makes sure that the `pkgs.nixos` and
`pkgs.testers.nixosTest` functions work. It's far from a perfect test suite,
but better than not checking them at all on hydra.

To run this test:

nixpkgs$ nix-build -A tests.nixos-functions
Expand Down