diff options
author | Robert Hensing <robert@roberthensing.nl> | 2018-09-27 17:03:23 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2018-11-13 10:43:05 +0100 |
commit | cdca66d7e8af90daa03fab564fa358df16b7421c (patch) | |
tree | 82e385f788319eb2ee53bf6e36b326eb97849132 | |
parent | 9871fe3564ee6f4a5b4a77adaae62589dbcf60c2 (diff) | |
download | nixlib-cdca66d7e8af90daa03fab564fa358df16b7421c.tar nixlib-cdca66d7e8af90daa03fab564fa358df16b7421c.tar.gz nixlib-cdca66d7e8af90daa03fab564fa358df16b7421c.tar.bz2 nixlib-cdca66d7e8af90daa03fab564fa358df16b7421c.tar.lz nixlib-cdca66d7e8af90daa03fab564fa358df16b7421c.tar.xz nixlib-cdca66d7e8af90daa03fab564fa358df16b7421c.tar.zst nixlib-cdca66d7e8af90daa03fab564fa358df16b7421c.zip |
Add pkgs.nixosTest
-rw-r--r-- | nixos/lib/build-vms.nix | 14 | ||||
-rw-r--r-- | nixos/lib/testing.nix | 13 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 51 |
3 files changed, 73 insertions, 5 deletions
diff --git a/nixos/lib/build-vms.nix b/nixos/lib/build-vms.nix index 933f81392491..024f4414ebeb 100644 --- a/nixos/lib/build-vms.nix +++ b/nixos/lib/build-vms.nix @@ -1,4 +1,13 @@ -{ system, pkgs, minimal ? false, config ? {} }: +{ system +, # Use a minimal kernel? + minimal ? false +, # Ignored + config ? null + # Nixpkgs, for qemu, lib and more +, pkgs +, # NixOS configuration to add to the VMs + extraConfigurations ? [] +}: with pkgs.lib; with import ../lib/qemu-flags.nix { inherit pkgs; }; @@ -28,7 +37,8 @@ rec { ../modules/testing/test-instrumentation.nix # !!! should only get added for automated test runs { key = "no-manual"; documentation.nixos.enable = false; } { key = "qemu"; system.build.qemu = qemu; } - ] ++ optional minimal ../modules/testing/minimal-kernel.nix; + ] ++ optional minimal ../modules/testing/minimal-kernel.nix + ++ extraConfigurations; extraArgs = { inherit nodes; }; }; diff --git a/nixos/lib/testing.nix b/nixos/lib/testing.nix index f90fc9f7df0e..690f7dfd5fac 100644 --- a/nixos/lib/testing.nix +++ b/nixos/lib/testing.nix @@ -1,6 +1,13 @@ -{ system, pkgs, minimal ? false, config ? {} }: - -with import ./build-vms.nix { inherit system pkgs minimal config; }; +{ system +, pkgs + # Use a minimal kernel? +, minimal ? false + # Ignored +, config ? null + # Modules to add to each VM +, extraConfigurations ? [] }: + +with import ./build-vms.nix { inherit system pkgs minimal extraConfigurations; }; with pkgs; let diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ad68a42f3f29..0a86c8ba5169 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -22243,6 +22243,57 @@ with pkgs; ); }).config.system.build; + + /* + * Run a NixOS VM network test. + * + * This is equivalent to import ./make-test.nix from the NixOS manual + * For details see https://nixos.org/nixos/manual/index.html#sec-nixos-tests + * + * Parameter: + * A NixOS VM test network, or path to it. Example: + * + * { lib, ... }: + * { name = "my-test"; + * nodes = { + * machine-1 = someNixOSConfiguration; + * machine-2 = ...; + * } + * } + * + * Result: + * A derivation that runs the VM test. + * + * For the interaction between Nixpkgs and NixOS configuration + * consult the pkgs.nixos function documentation. + */ + nixosTest = + let + /* The nixos/lib/testing.nix module, preapplied with arguments that + * make sense for this evaluation of Nixpkgs. + */ + nixosTesting = + (import ../../nixos/lib/testing.nix { + inherit (pkgs.stdenv.hostPlatform) system; + inherit pkgs; + extraConfigurations = [( + { lib, ... }: { + config.nixpkgs.pkgs = lib.mkDefault pkgs; + } + )]; + }); + in + test: + let + loadedTest = if builtins.typeOf test == "path" + then import test + else test; + calledTest = if pkgs.lib.isFunction loadedTest + then callPackage loadedTest {} + else loadedTest; + in + nixosTesting.makeTest calledTest; + nixui = callPackage ../tools/package-management/nixui { node_webkit = nwjs_0_12; }; nixdoc = callPackage ../tools/nix/nixdoc {}; |