diff --git a/lib/default.nix b/lib/default.nix index cb9a9b0bd4d08..61995b48b8c25 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -32,6 +32,7 @@ let # domain-specific sandbox = import ./sandbox.nix; fetchers = import ./fetchers.nix; + testing = import ./testing {}; in { inherit trivial @@ -40,7 +41,7 @@ in modules options types licenses platforms systems debug misc - sandbox fetchers; + sandbox fetchers testing; } # !!! don't include everything at top-level; perhaps only the most # commonly used functions. diff --git a/lib/testing/default.nix b/lib/testing/default.nix new file mode 100644 index 0000000000000..04aefd2d89abe --- /dev/null +++ b/lib/testing/default.nix @@ -0,0 +1,75 @@ +{ supportedSystems ? [ builtins.currentSystem ] }: + +with { + inherit (builtins) getAttr; + inherit (import ../attrsets.nix) mapAttrs genAttrs isDerivation; + inherit (import ../customisation.nix) hydraJob; + inherit (import ../trivial.nix) id; +}; + +rec { + + /* Call a test file + + The called test file should contain a function that returns: + - a single test set + - a set of tests sets + - a test derivation, eg runInMachine + + Examples: + + a. Call a test: + callTest ./nixos/tests/simple.nix {}; + + b. Call a test for only x86_64-linux: + callTest ./nixos/tests/simple.nix { systems = [ "x86_64-linux" ]; }; + + c. Call a test with custom parameters: + callTest ./nixos/tests/nfs.nix { version = 3; }; + + d. Call a test from the command line with nix-build: + $ nix-build -E 'with import {}; callTest ./nixos/tests/simple.nix {}' + + */ + + callTest = file: { systems ? supportedSystems, interactive ? false, ... } @ args: + let + # raw test function + testFn = import file; + # pkgs needed to dummy evaluate the test, not used in the final test + pkgs = import ../.. { system = "x86_64-linux"; }; + # basic arguments + testArgs = rec { inherit pkgs; inherit (pkgs) lib; } // args; + # test applied with basic arguments + dummyTest = testFn testArgs; + # check if the test is a derivation like in runInMachine + drvTest = isDerivation dummyTest; + # to check if it is a single test or multiple tests + singleTest = dummyTest ? "testScript"; + # generate the tests with makeTest function + mkTest = { system ? builtins.currentSystem, ... } @ args: + let testLib = import ./testing.nix { inherit system; }; + # pkgs coming from testing.nix for the system tested + pkgsSet = { inherit testLib pkgs; }; + test = testFn (args // pkgsSet); + in if drvTest then test + else if singleTest + then testLib.makeTest test + else mapAttrs (k: v: testLib.makeTest v) test; + # function to prepare the test + prepTestFn = if interactive + then (getAttr "driver") + else hydraJob; + # check unsupported cases + runCheck = f: if (drvTest && interactive) + then builtins.abort "Derivation tests cannot be run interactively" + else f; + # generate test jobs for systems + testForSys = f: genAttrs systems (system: prepTestFn( f( mkTest({ inherit system; } // testArgs)) ) ); + # fully prepared test + test = if (drvTest || singleTest) + then testForSys id + else mapAttrs (k: _: testForSys (getAttr k)) dummyTest; + in runCheck test; + +} diff --git a/nixos/lib/test-driver/Logger.pm b/lib/testing/test-driver/Logger.pm similarity index 100% rename from nixos/lib/test-driver/Logger.pm rename to lib/testing/test-driver/Logger.pm diff --git a/nixos/lib/test-driver/Machine.pm b/lib/testing/test-driver/Machine.pm similarity index 100% rename from nixos/lib/test-driver/Machine.pm rename to lib/testing/test-driver/Machine.pm diff --git a/nixos/lib/test-driver/log2html.xsl b/lib/testing/test-driver/log2html.xsl similarity index 100% rename from nixos/lib/test-driver/log2html.xsl rename to lib/testing/test-driver/log2html.xsl diff --git a/nixos/lib/test-driver/logfile.css b/lib/testing/test-driver/logfile.css similarity index 100% rename from nixos/lib/test-driver/logfile.css rename to lib/testing/test-driver/logfile.css diff --git a/nixos/lib/test-driver/test-driver.pl b/lib/testing/test-driver/test-driver.pl similarity index 100% rename from nixos/lib/test-driver/test-driver.pl rename to lib/testing/test-driver/test-driver.pl diff --git a/nixos/lib/test-driver/treebits.js b/lib/testing/test-driver/treebits.js similarity index 100% rename from nixos/lib/test-driver/treebits.js rename to lib/testing/test-driver/treebits.js diff --git a/nixos/lib/testing.nix b/lib/testing/testing.nix similarity index 98% rename from nixos/lib/testing.nix rename to lib/testing/testing.nix index 7fad5cbc3cd95..4b94234095d95 100644 --- a/nixos/lib/testing.nix +++ b/lib/testing/testing.nix @@ -1,6 +1,6 @@ { system, minimal ? false, config ? {} }: -with import ./build-vms.nix { inherit system minimal config; }; +with import ../../nixos/lib/build-vms.nix { inherit system minimal config; }; with pkgs; rec { diff --git a/nixos/doc/manual/development/meta-attributes.xml b/nixos/doc/manual/development/meta-attributes.xml index de0870314dcb3..5d5da2f42a7b5 100644 --- a/nixos/doc/manual/development/meta-attributes.xml +++ b/nixos/doc/manual/development/meta-attributes.xml @@ -14,8 +14,8 @@ meta is a top level attribute like options and config. Available - meta-attributes are maintainers and - doc. + meta-attributes are maintainers, + doc and tests. Each of the meta-attributes must be defined at most once per module file. @@ -35,6 +35,10 @@ maintainers = with lib.maintainers; [ ericsagnes ]; doc = ./default.xml; + tests = { + containers-ipv4 = ./tests/containers-ipv4.nix; + containers-ipv6 = ./tests/containers-ipv6.nix; + }; }; } @@ -57,6 +61,19 @@ $ nix-build nixos/release.nix -A manual + + + tests is a set of which keys are test names and values + point to a test file. All the tests declared via this attribute are + automatically included in + release.nix's + tests.module set. + It is important to check that newly added and modified test are not + breaking by running them: + + $ nix-build nixos/release.nix -A tests.module.TEST_NAME + + diff --git a/nixos/doc/manual/development/running-nixos-tests-interactively.xml b/nixos/doc/manual/development/running-nixos-tests-interactively.xml index e474907778155..6bb67e4d1c8a2 100644 --- a/nixos/doc/manual/development/running-nixos-tests-interactively.xml +++ b/nixos/doc/manual/development/running-nixos-tests-interactively.xml @@ -9,7 +9,7 @@ particularly useful when developing or debugging a test: -$ nix-build nixos/tests/login.nix -A driver +$ nix-run-test --interactive nixos/tests/login.nix $ ./result/bin/nixos-test-driver starting VDE switch for network 1 > @@ -31,7 +31,7 @@ test (e.g. to debug the test script). To just start and experiment with the VMs, run: -$ nix-build nixos/tests/login.nix -A driver +$ nix-run-test --interactive nixos/tests/login.nix $ ./result/bin/nixos-run-vms diff --git a/nixos/doc/manual/development/running-nixos-tests.xml b/nixos/doc/manual/development/running-nixos-tests.xml index 908c0a66a32de..20e2e5596ad2c 100644 --- a/nixos/doc/manual/development/running-nixos-tests.xml +++ b/nixos/doc/manual/development/running-nixos-tests.xml @@ -6,20 +6,21 @@ Running Tests -You can run tests using nix-build. For -example, to run the test You can run tests using nix-run-test. +nix-run-test is available in nixpkgs. +For example, to run the test login.nix, you just do: -$ nix-build '<nixpkgs/nixos/tests/login.nix>' +$ nix-run-test '<nixpkgs/nixos/tests/login.nix>' or, if you don’t want to rely on NIX_PATH: $ cd /my/nixpkgs/nixos/tests -$ nix-build login.nix +$ nix-run-test login.nix … running the VM test script machine: QEMU running (pid 8841) diff --git a/nixos/doc/manual/development/writing-nixos-tests.xml b/nixos/doc/manual/development/writing-nixos-tests.xml index b9da712b86f03..ad5c73a996984 100644 --- a/nixos/doc/manual/development/writing-nixos-tests.xml +++ b/nixos/doc/manual/development/writing-nixos-tests.xml @@ -9,7 +9,8 @@ A NixOS test is a Nix expression that has the following structure: -import ./make-test.nix { +{ pkgs, ... }: +{ # Either the configuration of a single machine: machine = @@ -266,4 +267,4 @@ startAll; - \ No newline at end of file + diff --git a/nixos/modules/installer/tools/nixos-build-vms/build-vms.nix b/nixos/modules/installer/tools/nixos-build-vms/build-vms.nix index 4372d196261e9..8a652e6f3b3ab 100644 --- a/nixos/modules/installer/tools/nixos-build-vms/build-vms.nix +++ b/nixos/modules/installer/tools/nixos-build-vms/build-vms.nix @@ -4,6 +4,6 @@ let nodes = import networkExpr; in -with import ../../../../lib/testing.nix { inherit system; }; +with import ../../../../../lib/testing/testing.nix { inherit system; }; (makeTest { inherit nodes; testScript = ""; }).driver diff --git a/nixos/modules/misc/meta.nix b/nixos/modules/misc/meta.nix index 6a5738e47ff35..46baa62b1edfd 100644 --- a/nixos/modules/misc/meta.nix +++ b/nixos/modules/misc/meta.nix @@ -22,9 +22,9 @@ let [{ inherit (def) file; value = def'; }]) def.value) defs)); }; - docFile = types.path // { + file = types.path // { # Returns tuples of - # { file = "module location"; value = ; } + # { file = "module location"; value = ; } merge = loc: defs: defs; }; in @@ -45,7 +45,7 @@ in }; doc = mkOption { - type = docFile; + type = file; internal = true; example = "./meta.xml"; description = '' @@ -54,6 +54,16 @@ in ''; }; + tests = mkOption { + type = with types; attrsOf file; + internal = true; + example = literalExample "./test.nix"; + description = '' + Tests for the module. Tests get added to the tests attribute of release.nix with the test name prepended by "module-". + This option should be defined at most once per module. + ''; + }; + }; }; diff --git a/nixos/modules/security/grsecurity.nix b/nixos/modules/security/grsecurity.nix index 7ba25f866f242..ef1797ffe7954 100644 --- a/nixos/modules/security/grsecurity.nix +++ b/nixos/modules/security/grsecurity.nix @@ -23,6 +23,9 @@ in meta = { maintainers = with maintainers; [ joachifm ]; doc = ./grsecurity.xml; + tests = { + grsecurity = ./tests/grsecurity.nix; + }; }; options.security.grsecurity = { diff --git a/nixos/tests/grsecurity.nix b/nixos/modules/security/tests/grsecurity.nix similarity index 97% rename from nixos/tests/grsecurity.nix rename to nixos/modules/security/tests/grsecurity.nix index e585a7402d348..6e8c763710503 100644 --- a/nixos/tests/grsecurity.nix +++ b/nixos/modules/security/tests/grsecurity.nix @@ -1,6 +1,6 @@ # Basic test to make sure grsecurity works -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "grsecurity"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ copumpkin joachifm ]; @@ -43,4 +43,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->succeed("[ -c /dev/grsec ]"); }; ''; -}) +} diff --git a/nixos/modules/services/amqp/rabbitmq.nix b/nixos/modules/services/amqp/rabbitmq.nix index 61545a5acba86..c47987d7359be 100644 --- a/nixos/modules/services/amqp/rabbitmq.nix +++ b/nixos/modules/services/amqp/rabbitmq.nix @@ -135,4 +135,8 @@ in { }; + meta.tests = { + rabbitmq = ./tests/rabbitmq.nix; + }; + } diff --git a/nixos/tests/rabbitmq.nix b/nixos/modules/services/amqp/tests/rabbitmq.nix similarity index 91% rename from nixos/tests/rabbitmq.nix rename to nixos/modules/services/amqp/tests/rabbitmq.nix index 23a7e2ed538f2..896d227b877ef 100644 --- a/nixos/tests/rabbitmq.nix +++ b/nixos/modules/services/amqp/tests/rabbitmq.nix @@ -1,6 +1,6 @@ # This test runs rabbitmq and checks if rabbitmq is up and running. -import ./make-test.nix ({ pkgs, ... }: { +{ pkgs, ... }: { name = "rabbitmq"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow offline ]; @@ -18,4 +18,4 @@ import ./make-test.nix ({ pkgs, ... }: { $one->waitForUnit("rabbitmq.service"); $one->waitUntilSucceeds("su -s ${pkgs.stdenv.shell} rabbitmq -c \"rabbitmqctl status\""); ''; -}) +} diff --git a/nixos/modules/services/cluster/fleet.nix b/nixos/modules/services/cluster/fleet.nix index 78d4ea93c491a..53f2d174511da 100644 --- a/nixos/modules/services/cluster/fleet.nix +++ b/nixos/modules/services/cluster/fleet.nix @@ -147,4 +147,8 @@ in { environment.systemPackages = [ pkgs.fleet ]; users.extraGroups.fleet.gid = config.ids.gids.fleet; }; + + meta.tests = { + fleet = ./tests/fleet.nix; + }; } diff --git a/nixos/modules/services/cluster/kubernetes.nix b/nixos/modules/services/cluster/kubernetes.nix index 4bdd7f95f7745..e923d025a9ea9 100644 --- a/nixos/modules/services/cluster/kubernetes.nix +++ b/nixos/modules/services/cluster/kubernetes.nix @@ -632,4 +632,8 @@ in { }) ]; + + meta.tests = { + kubernetes = ./tests/kubernetes.nix; + }; } diff --git a/nixos/modules/services/cluster/panamax.nix b/nixos/modules/services/cluster/panamax.nix index b47ff744fc27b..360c2283f3a5e 100644 --- a/nixos/modules/services/cluster/panamax.nix +++ b/nixos/modules/services/cluster/panamax.nix @@ -153,4 +153,8 @@ in { environment.systemPackages = [ panamax_api panamax_ui ]; users.extraGroups.panamax.gid = config.ids.gids.panamax; }; + + meta.tests = { + panamax = ./tests/panamax.nix; + }; } diff --git a/nixos/tests/fleet.nix b/nixos/modules/services/cluster/tests/fleet.nix similarity index 97% rename from nixos/tests/fleet.nix rename to nixos/modules/services/cluster/tests/fleet.nix index 67c95446526f8..fb8ef43b114e7 100644 --- a/nixos/tests/fleet.nix +++ b/nixos/modules/services/cluster/tests/fleet.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : rec { +{ pkgs, ...} : rec { name = "simple"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ offline ]; @@ -73,4 +73,4 @@ import ./make-test.nix ({ pkgs, ...} : rec { $node1->succeed("fleetctl stop hello.service"); $node1->succeed("fleetctl destroy hello.service"); ''; -}) +} diff --git a/nixos/tests/kubernetes.nix b/nixos/modules/services/cluster/tests/kubernetes.nix similarity index 99% rename from nixos/tests/kubernetes.nix rename to nixos/modules/services/cluster/tests/kubernetes.nix index b19ea67b0baf5..a30c4ddeeb69e 100644 --- a/nixos/tests/kubernetes.nix +++ b/nixos/modules/services/cluster/tests/kubernetes.nix @@ -1,6 +1,6 @@ # This test runs two node kubernetes cluster and checks if simple redis pod works -import ./make-test.nix ({ pkgs, ...} : rec { +{ pkgs, ...} : rec { name = "kubernetes"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ offline ]; @@ -179,4 +179,4 @@ import ./make-test.nix ({ pkgs, ...} : rec { } ''; -}) +} diff --git a/nixos/tests/panamax.nix b/nixos/modules/services/cluster/tests/panamax.nix similarity index 92% rename from nixos/tests/panamax.nix rename to nixos/modules/services/cluster/tests/panamax.nix index 088aa79f8c615..5783970a0d5d0 100644 --- a/nixos/tests/panamax.nix +++ b/nixos/modules/services/cluster/tests/panamax.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "panamax"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ offline ]; @@ -18,4 +18,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->succeed("curl --fail http://localhost:8888/ > /dev/null"); $machine->shutdown; ''; -}) +} diff --git a/nixos/modules/services/computing/slurm/slurm.nix b/nixos/modules/services/computing/slurm/slurm.nix index ee38a42199ee1..47f3376a4d173 100644 --- a/nixos/modules/services/computing/slurm/slurm.nix +++ b/nixos/modules/services/computing/slurm/slurm.nix @@ -168,4 +168,8 @@ in }; + meta.tests = { + slurm = ./test.nix; + }; + } diff --git a/nixos/tests/slurm.nix b/nixos/modules/services/computing/slurm/test.nix similarity index 98% rename from nixos/tests/slurm.nix rename to nixos/modules/services/computing/slurm/test.nix index 0dd00dfb04c26..b7e1ffb2bc1b8 100644 --- a/nixos/tests/slurm.nix +++ b/nixos/modules/services/computing/slurm/test.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: +{ pkgs, ... }: let mungekey = "mungeverryweakkeybuteasytointegratoinatest"; slurmconfig = { client.enable = true; @@ -77,4 +77,4 @@ in { $control->succeed("srun -N 3 hostname | sort | uniq | wc -l | xargs test 3 -eq"); }; ''; -}) +} diff --git a/nixos/modules/services/continuous-integration/gocd-agent/default.nix b/nixos/modules/services/continuous-integration/gocd-agent/default.nix index d60b55e83d11b..5d19cf4a73f2c 100644 --- a/nixos/modules/services/continuous-integration/gocd-agent/default.nix +++ b/nixos/modules/services/continuous-integration/gocd-agent/default.nix @@ -202,4 +202,8 @@ in { }; }; }; + + meta.tests = { + gocd-agent = ./test.nix; + }; } diff --git a/nixos/tests/gocd-agent.nix b/nixos/modules/services/continuous-integration/gocd-agent/test.nix similarity index 96% rename from nixos/tests/gocd-agent.nix rename to nixos/modules/services/continuous-integration/gocd-agent/test.nix index 5cadff0899504..31d697fff1bed 100644 --- a/nixos/tests/gocd-agent.nix +++ b/nixos/modules/services/continuous-integration/gocd-agent/test.nix @@ -9,7 +9,7 @@ let header = "Accept: application/vnd.go.cd.v2+json"; in -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "gocd-agent"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ grahamc swarren83 ]; @@ -37,4 +37,4 @@ import ./make-test.nix ({ pkgs, ...} : { $gocd_agent->waitUntilSucceeds("curl ${serverUrl} -H '${header}' | ${pkgs.jq}/bin/jq -e ._embedded.agents[0].uuid"); $gocd_agent->succeed("curl ${serverUrl} -H '${header}' | ${pkgs.jq}/bin/jq -e ._embedded.agents[0].agent_state | grep -q Idle"); ''; -}) +} diff --git a/nixos/modules/services/continuous-integration/gocd-server/default.nix b/nixos/modules/services/continuous-integration/gocd-server/default.nix index 4bb792055d254..61bc09f14afb9 100644 --- a/nixos/modules/services/continuous-integration/gocd-server/default.nix +++ b/nixos/modules/services/continuous-integration/gocd-server/default.nix @@ -190,4 +190,8 @@ in { }; }; }; + + meta.tests = { + gocd-server = ./test.nix; + }; } diff --git a/nixos/tests/gocd-server.nix b/nixos/modules/services/continuous-integration/gocd-server/test.nix similarity index 92% rename from nixos/tests/gocd-server.nix rename to nixos/modules/services/continuous-integration/gocd-server/test.nix index b473d4ad61c79..10b680aa4bfd6 100644 --- a/nixos/tests/gocd-server.nix +++ b/nixos/modules/services/continuous-integration/gocd-server/test.nix @@ -2,7 +2,7 @@ # 1. GoCD server starts # 2. GoCD server responds -import ./make-test.nix ({ pkgs, ...} : +{ pkgs, ...} : { name = "gocd-server"; @@ -25,4 +25,4 @@ nodes = { $gocd_server->waitForOpenPort("8153"); $gocd_server->waitUntilSucceeds("curl -s -f localhost:8153/go"); ''; -}) +} diff --git a/nixos/modules/services/continuous-integration/jenkins/default.nix b/nixos/modules/services/continuous-integration/jenkins/default.nix index 4edbbf59a42c5..b4da782f29c3a 100644 --- a/nixos/modules/services/continuous-integration/jenkins/default.nix +++ b/nixos/modules/services/continuous-integration/jenkins/default.nix @@ -171,4 +171,8 @@ in { }; }; }; + + meta.tests = { + jenkins = ./test.nix; + }; } diff --git a/nixos/tests/jenkins.nix b/nixos/modules/services/continuous-integration/jenkins/test.nix similarity index 96% rename from nixos/tests/jenkins.nix rename to nixos/modules/services/continuous-integration/jenkins/test.nix index a9833058f3786..ef2d913900832 100644 --- a/nixos/tests/jenkins.nix +++ b/nixos/modules/services/continuous-integration/jenkins/test.nix @@ -3,7 +3,7 @@ # 2. jenkins user can be extended on both master and slave # 3. jenkins service not started on slave node -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "jenkins"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ bjornfor coconnor domenkozar eelco chaoflow ]; @@ -44,4 +44,4 @@ import ./make-test.nix ({ pkgs, ...} : { $slave->mustFail("systemctl is-enabled jenkins.service"); ''; -}) \ No newline at end of file +} diff --git a/nixos/modules/services/databases/cassandra.nix b/nixos/modules/services/databases/cassandra.nix index b43b448ed7e1e..ef1d381ad9e42 100644 --- a/nixos/modules/services/databases/cassandra.nix +++ b/nixos/modules/services/databases/cassandra.nix @@ -446,4 +446,8 @@ in { }; }; }; + + meta.tests = { + cassandra = ./tests/cassandra.nix; + }; } diff --git a/nixos/modules/services/databases/influxdb.nix b/nixos/modules/services/databases/influxdb.nix index dd88624f406cb..da6bf1d9ff8c5 100644 --- a/nixos/modules/services/databases/influxdb.nix +++ b/nixos/modules/services/databases/influxdb.nix @@ -190,4 +190,8 @@ in }; }; + meta.tests = { + influxdb = ./tests/influxdb.nix; + }; + } diff --git a/nixos/modules/services/databases/mongodb.nix b/nixos/modules/services/databases/mongodb.nix index 38e46a0c6ef93..2d65a18c70360 100644 --- a/nixos/modules/services/databases/mongodb.nix +++ b/nixos/modules/services/databases/mongodb.nix @@ -131,4 +131,8 @@ in }; + meta.tests = { + mongodb = ./tests/mongodb.nix; + }; + } diff --git a/nixos/modules/services/databases/mysql.nix b/nixos/modules/services/databases/mysql.nix index 1180531248f9b..3a35473ae6e7a 100644 --- a/nixos/modules/services/databases/mysql.nix +++ b/nixos/modules/services/databases/mysql.nix @@ -294,4 +294,8 @@ in }; + meta.tests = { + mysql = ./tests/mysql.nix; + mysqlReplication = ./tests/mysql-replication.nix; + }; } diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix index 24ef4637ec98f..7a8a398871c8d 100644 --- a/nixos/modules/services/databases/postgresql.nix +++ b/nixos/modules/services/databases/postgresql.nix @@ -255,6 +255,12 @@ in }; - meta.doc = ./postgresql.xml; + meta = { + doc = ./postgresql.xml; + tests = { + postgresql = ./tests/postgresql.nix; + postgis = ./tests/postgis.nix; + }; + }; } diff --git a/nixos/modules/services/databases/riak.nix b/nixos/modules/services/databases/riak.nix index 4477904f78c6e..ae96062d14370 100644 --- a/nixos/modules/services/databases/riak.nix +++ b/nixos/modules/services/databases/riak.nix @@ -146,4 +146,8 @@ in }; + meta.tests = { + riak = ./tests/riak.nix; + }; + } diff --git a/nixos/tests/cassandra.nix b/nixos/modules/services/databases/tests/cassandra.nix similarity index 98% rename from nixos/tests/cassandra.nix rename to nixos/modules/services/databases/tests/cassandra.nix index b729e6b158bcb..f7d9ed55eedbc 100644 --- a/nixos/tests/cassandra.nix +++ b/nixos/modules/services/databases/tests/cassandra.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...}: +{ pkgs, ...}: let user = "cassandra"; nodeCfg = nodes: selfIP: cassandraOpts: @@ -65,4 +65,4 @@ in $cass0->waitUntilSucceeds("nodetool status | grep UN | grep 192.168.1.3"); }; ''; -}) +} diff --git a/nixos/tests/influxdb.nix b/nixos/modules/services/databases/tests/influxdb.nix similarity index 95% rename from nixos/tests/influxdb.nix rename to nixos/modules/services/databases/tests/influxdb.nix index ee126091667a9..caecbb5b04d44 100644 --- a/nixos/tests/influxdb.nix +++ b/nixos/modules/services/databases/tests/influxdb.nix @@ -1,6 +1,6 @@ # This test runs influxdb and checks if influxdb is up and running -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "influxdb"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ chaoflow offline ]; @@ -30,4 +30,4 @@ import ./make-test.nix ({ pkgs, ...} : { curl -GET 'http://localhost:8086/query' --data-urlencode "db=test" --data-urlencode "q=SELECT \"value\" FROM \"cpu_load_short\" WHERE \"region\"='us-west'" | grep "0\.64" ~); ''; -}) +} diff --git a/nixos/tests/mongodb.nix b/nixos/modules/services/databases/tests/mongodb.nix similarity index 94% rename from nixos/tests/mongodb.nix rename to nixos/modules/services/databases/tests/mongodb.nix index 18535f51af9b3..438564dee0825 100644 --- a/nixos/tests/mongodb.nix +++ b/nixos/modules/services/databases/tests/mongodb.nix @@ -1,6 +1,6 @@ # This test start mongodb, runs a query using mongo shell -import ./make-test.nix ({ pkgs, ...} : let +{ pkgs, ...} : let testQuery = pkgs.writeScript "nixtest.js" '' db.greetings.insert({ "greeting": "hello" }); print(db.greetings.findOne().greeting); @@ -31,4 +31,4 @@ in { $one->waitForUnit("mongodb.service"); $one->succeed("mongo nixtest ${testQuery}") =~ /hello/ or die; ''; -}) +} diff --git a/nixos/tests/mysql-replication.nix b/nixos/modules/services/databases/tests/mysql-replication.nix similarity index 97% rename from nixos/tests/mysql-replication.nix rename to nixos/modules/services/databases/tests/mysql-replication.nix index b20bce8edce6b..cd4c34d6d9461 100644 --- a/nixos/tests/mysql-replication.nix +++ b/nixos/modules/services/databases/tests/mysql-replication.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : +{ pkgs, ...} : let replicateUser = "replicate"; @@ -63,4 +63,4 @@ in $slave2->sleep(100); # Hopefully this is long enough!! $slave2->succeed("echo 'use testdb; select * from tests' | mysql -u root -N | grep 4"); ''; -}) +} diff --git a/nixos/tests/mysql.nix b/nixos/modules/services/databases/tests/mysql.nix similarity index 93% rename from nixos/tests/mysql.nix rename to nixos/modules/services/databases/tests/mysql.nix index baaebf9f10db2..b99278ddb7046 100644 --- a/nixos/tests/mysql.nix +++ b/nixos/modules/services/databases/tests/mysql.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "mysql"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow shlevy ]; @@ -22,4 +22,4 @@ import ./make-test.nix ({ pkgs, ...} : { $master->sleep(10); # Hopefully this is long enough!! $master->succeed("echo 'use testdb; select * from tests' | mysql -u root -N | grep 4"); ''; -}) +} diff --git a/nixos/tests/postgis.nix b/nixos/modules/services/databases/tests/postgis.nix similarity index 94% rename from nixos/tests/postgis.nix rename to nixos/modules/services/databases/tests/postgis.nix index 1dba5c363c09d..0645088e12cd9 100644 --- a/nixos/tests/postgis.nix +++ b/nixos/modules/services/databases/tests/postgis.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "postgis"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ lsix ]; @@ -27,4 +27,4 @@ import ./make-test.nix ({ pkgs, ...} : { $master->sleep(10); # Hopefully this is long enough!! $master->succeed("sudo -u postgres psql -c 'CREATE EXTENSION postgis;'"); ''; -}) +} diff --git a/nixos/tests/postgresql.nix b/nixos/modules/services/databases/tests/postgresql.nix similarity index 93% rename from nixos/tests/postgresql.nix rename to nixos/modules/services/databases/tests/postgresql.nix index f17384b44ba60..4bd27cab1f28b 100644 --- a/nixos/tests/postgresql.nix +++ b/nixos/modules/services/databases/tests/postgresql.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "postgresql"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ zagy ]; @@ -23,4 +23,4 @@ import ./make-test.nix ({ pkgs, ...} : { $master->sleep(10); # Hopefully this is long enough!! $master->succeed("echo 'select 1' | sudo -u postgres psql"); ''; -}) +} diff --git a/nixos/tests/riak.nix b/nixos/modules/services/databases/tests/riak.nix similarity index 93% rename from nixos/tests/riak.nix rename to nixos/modules/services/databases/tests/riak.nix index 18d028232ac24..f4f3fe63b95e4 100644 --- a/nixos/tests/riak.nix +++ b/nixos/modules/services/databases/tests/riak.nix @@ -1,4 +1,4 @@ -import ./make-test.nix { +{ pkgs, ... }: { name = "riak"; nodes = { diff --git a/nixos/tests/testdb.sql b/nixos/modules/services/databases/tests/testdb.sql similarity index 100% rename from nixos/tests/testdb.sql rename to nixos/modules/services/databases/tests/testdb.sql diff --git a/nixos/modules/services/editors/emacs.nix b/nixos/modules/services/editors/emacs.nix index 08fa6de6374c2..5ab5b040b5927 100644 --- a/nixos/modules/services/editors/emacs.nix +++ b/nixos/modules/services/editors/emacs.nix @@ -88,5 +88,10 @@ in { } else {}); }; - meta.doc = ./emacs.xml; + meta = { + doc = ./emacs.xml; + tests = { + emacs-daemon = ./tests/emacs-daemon.nix; + }; + }; } diff --git a/nixos/tests/emacs-daemon.nix b/nixos/modules/services/editors/tests/emacs-daemon.nix similarity index 93% rename from nixos/tests/emacs-daemon.nix rename to nixos/modules/services/editors/tests/emacs-daemon.nix index a4d63bdb7e41f..a996b63a68fe6 100644 --- a/nixos/tests/emacs-daemon.nix +++ b/nixos/modules/services/editors/tests/emacs-daemon.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "emacs-daemon"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ DamienCassou ]; @@ -9,7 +9,7 @@ import ./make-test.nix ({ pkgs, ...} : { machine = { config, pkgs, ... }: - { imports = [ ./common/x11.nix ]; + { imports = [ ]; services.emacs = { enable = true; defaultEditor = true; @@ -42,4 +42,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->screenshot("emacsclient"); ''; -}) +} diff --git a/nixos/tests/udisks2.nix b/nixos/modules/services/hardware/tests/udisks2.nix similarity index 95% rename from nixos/tests/udisks2.nix rename to nixos/modules/services/hardware/tests/udisks2.nix index 72d51c0051c07..c52234c90799c 100644 --- a/nixos/tests/udisks2.nix +++ b/nixos/modules/services/hardware/tests/udisks2.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: +{ pkgs, ... }: let @@ -18,7 +18,7 @@ in machine = { config, pkgs, ... }: { services.udisks2.enable = true; - imports = [ ./common/user-account.nix ]; + imports = [ ]; security.polkit.extraConfig = '' @@ -57,4 +57,4 @@ in $machine->fail("[ -e /dev/sda ]"); ''; -}) +} diff --git a/nixos/modules/services/hardware/udisks2.nix b/nixos/modules/services/hardware/udisks2.nix index ad5dc8e8a49b7..bc94665472e43 100644 --- a/nixos/modules/services/hardware/udisks2.nix +++ b/nixos/modules/services/hardware/udisks2.nix @@ -51,4 +51,8 @@ with lib; }; }; + meta.tests = { + udisks2 = ./tests/udisks2.nix; + }; + } diff --git a/nixos/modules/services/logging/logstash.nix b/nixos/modules/services/logging/logstash.nix index 62f6e187ea079..5ad4f798ef142 100644 --- a/nixos/modules/services/logging/logstash.nix +++ b/nixos/modules/services/logging/logstash.nix @@ -151,4 +151,8 @@ in }; }; }; + + meta.tests = { + logstash = ./tests/logstash.nix; + }; } diff --git a/nixos/tests/logstash.nix b/nixos/modules/services/logging/tests/logstash.nix similarity index 96% rename from nixos/tests/logstash.nix rename to nixos/modules/services/logging/tests/logstash.nix index 01f6a0358b2e6..e42b8903af54e 100644 --- a/nixos/tests/logstash.nix +++ b/nixos/modules/services/logging/tests/logstash.nix @@ -1,7 +1,7 @@ # This test runs logstash and checks if messages flows and # elasticsearch is started. -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "logstash"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow offline ]; @@ -38,4 +38,4 @@ import ./make-test.nix ({ pkgs, ...} : { $one->waitUntilSucceeds("journalctl -n 20 _SYSTEMD_UNIT=logstash.service | grep flowers"); $one->fail("journalctl -n 20 _SYSTEMD_UNIT=logstash.service | grep dragons"); ''; -}) +} diff --git a/nixos/modules/services/misc/etcd.nix b/nixos/modules/services/misc/etcd.nix index 1de02d76ba0a9..a67ec7defecb4 100644 --- a/nixos/modules/services/misc/etcd.nix +++ b/nixos/modules/services/misc/etcd.nix @@ -195,4 +195,8 @@ in { home = cfg.dataDir; }; }; + + meta.tests = { + etcd = ./tests/etcd.nix; + }; } diff --git a/nixos/modules/services/misc/gitlab.nix b/nixos/modules/services/misc/gitlab.nix index f8881233dceb2..701936e7c72e4 100644 --- a/nixos/modules/services/misc/gitlab.nix +++ b/nixos/modules/services/misc/gitlab.nix @@ -565,6 +565,11 @@ in { }; - meta.doc = ./gitlab.xml; + meta = { + doc = ./gitlab.xml; + tests = { + gitlab = ./tests/gitlab.nix; + }; + }; } diff --git a/nixos/modules/services/misc/mathics.nix b/nixos/modules/services/misc/mathics.nix index 50715858881ac..e90bc2fa058f2 100644 --- a/nixos/modules/services/misc/mathics.nix +++ b/nixos/modules/services/misc/mathics.nix @@ -51,4 +51,8 @@ in { }; }; }; + + meta.tests = { + mathics = ./tests/mathics.nix; + }; } diff --git a/nixos/modules/services/misc/mesos-master.nix b/nixos/modules/services/misc/mesos-master.nix index 99583ebeebd51..4e83892be9829 100644 --- a/nixos/modules/services/misc/mesos-master.nix +++ b/nixos/modules/services/misc/mesos-master.nix @@ -101,5 +101,9 @@ in { }; }; + meta.tests = { + mesos = ./tests/mesos.nix; + }; + } diff --git a/nixos/modules/services/misc/taskserver/default.nix b/nixos/modules/services/misc/taskserver/default.nix index 6d458feec3453..bf22f7982a71b 100644 --- a/nixos/modules/services/misc/taskserver/default.nix +++ b/nixos/modules/services/misc/taskserver/default.nix @@ -536,5 +536,10 @@ in { }) ]; - meta.doc = ./doc.xml; + meta = { + doc = ./doc.xml; + tests = { + taskserver = ./test.nix; + }; + }; } diff --git a/nixos/tests/taskserver.nix b/nixos/modules/services/misc/taskserver/test.nix similarity index 99% rename from nixos/tests/taskserver.nix rename to nixos/modules/services/misc/taskserver/test.nix index d770b20a77575..ead5203574b6d 100644 --- a/nixos/tests/taskserver.nix +++ b/nixos/modules/services/misc/taskserver/test.nix @@ -1,4 +1,5 @@ -import ./make-test.nix { +{ pkgs, ... }: +{ name = "taskserver"; nodes = rec { diff --git a/nixos/tests/etcd.nix b/nixos/modules/services/misc/tests/etcd.nix similarity index 92% rename from nixos/tests/etcd.nix rename to nixos/modules/services/misc/tests/etcd.nix index f8a6791a834f7..0222081e9264e 100644 --- a/nixos/tests/etcd.nix +++ b/nixos/modules/services/misc/tests/etcd.nix @@ -1,6 +1,6 @@ # This test runs simple etcd node -import ./make-test.nix ({ pkgs, ... } : { +{ pkgs, ... } : { name = "etcd"; meta = with pkgs.stdenv.lib.maintainers; { @@ -24,4 +24,4 @@ import ./make-test.nix ({ pkgs, ... } : { $node->succeed("etcdctl get /foo/bar | grep 'Hello world'"); } ''; -}) +} diff --git a/nixos/tests/gitlab.nix b/nixos/modules/services/misc/tests/gitlab.nix similarity index 93% rename from nixos/tests/gitlab.nix rename to nixos/modules/services/misc/tests/gitlab.nix index 357911046960a..2033d4f6650d9 100644 --- a/nixos/tests/gitlab.nix +++ b/nixos/modules/services/misc/tests/gitlab.nix @@ -1,6 +1,6 @@ # This test runs gitlab and checks if it works -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "gitlab"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ domenkozar offline ]; @@ -21,4 +21,4 @@ import ./make-test.nix ({ pkgs, ...} : { $gitlab->waitForUnit("gitlab-sidekiq.service"); $gitlab->waitUntilSucceeds("curl http://localhost:8080/users/sign_in"); ''; -}) +} diff --git a/nixos/tests/mathics.nix b/nixos/modules/services/misc/tests/mathics.nix similarity index 90% rename from nixos/tests/mathics.nix rename to nixos/modules/services/misc/tests/mathics.nix index 310b751b4d844..477a19d142f09 100644 --- a/nixos/tests/mathics.nix +++ b/nixos/modules/services/misc/tests/mathics.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: { +{ pkgs, ... }: { name = "mathics"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ benley ]; @@ -17,4 +17,4 @@ import ./make-test.nix ({ pkgs, ... }: { $machine->waitForOpenPort(8888); $machine->succeed("curl http://localhost:8888/"); ''; -}) +} diff --git a/nixos/tests/mesos.nix b/nixos/modules/services/misc/tests/mesos.nix similarity index 93% rename from nixos/tests/mesos.nix rename to nixos/modules/services/misc/tests/mesos.nix index 3610603aeba2c..86d4250204881 100644 --- a/nixos/tests/mesos.nix +++ b/nixos/modules/services/misc/tests/mesos.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "simple"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ offline ]; @@ -29,4 +29,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->waitForUnit("mesos-master.service"); $machine->waitForUnit("mesos-slave.service"); ''; -}) +} diff --git a/nixos/modules/services/monitoring/cadvisor.nix b/nixos/modules/services/monitoring/cadvisor.nix index 8ae8b12056ceb..e75656693a2f9 100644 --- a/nixos/modules/services/monitoring/cadvisor.nix +++ b/nixos/modules/services/monitoring/cadvisor.nix @@ -96,4 +96,8 @@ in { virtualisation.docker.enable = mkDefault true; }; + + meta.tests = { + cadvisor = ./tests/cadvisor.nix; + }; } diff --git a/nixos/modules/services/monitoring/munin.nix b/nixos/modules/services/monitoring/munin.nix index aaa041ad4cd6a..fa97b613e318f 100644 --- a/nixos/modules/services/monitoring/munin.nix +++ b/nixos/modules/services/monitoring/munin.nix @@ -201,4 +201,8 @@ in ''; })]; + + meta.tests = { + munin = ./tests/munin.nix; + }; } diff --git a/nixos/tests/cadvisor.nix b/nixos/modules/services/monitoring/tests/cadvisor.nix similarity index 95% rename from nixos/tests/cadvisor.nix rename to nixos/modules/services/monitoring/tests/cadvisor.nix index f0083ab18e45e..e9d0c182861be 100644 --- a/nixos/tests/cadvisor.nix +++ b/nixos/modules/services/monitoring/tests/cadvisor.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... } : { +{ pkgs, ... } : { name = "cadvisor"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ offline ]; @@ -32,4 +32,4 @@ import ./make-test.nix ({ pkgs, ... } : { $influxdb->waitForUnit("cadvisor.service"); $influxdb->succeed("curl http://localhost:8080/containers/"); ''; -}) +} diff --git a/nixos/tests/munin.nix b/nixos/modules/services/monitoring/tests/munin.nix similarity index 95% rename from nixos/tests/munin.nix rename to nixos/modules/services/monitoring/tests/munin.nix index 50746d17b4515..c9ace478a8562 100644 --- a/nixos/tests/munin.nix +++ b/nixos/modules/services/monitoring/tests/munin.nix @@ -1,7 +1,7 @@ # This test runs basic munin setup with node and cron job running on the same # machine. -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "munin"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ domenkozar eelco chaoflow ]; @@ -32,4 +32,4 @@ import ./make-test.nix ({ pkgs, ...} : { $one->waitForFile("/var/lib/munin/one/one-uptime-uptime-g.rrd"); $one->waitForFile("/var/www/munin/one/index.html"); ''; -}) +} diff --git a/nixos/modules/services/network-filesystems/samba.nix b/nixos/modules/services/network-filesystems/samba.nix index 7de85b59e2af9..cc7f044b541a0 100644 --- a/nixos/modules/services/network-filesystems/samba.nix +++ b/nixos/modules/services/network-filesystems/samba.nix @@ -223,4 +223,8 @@ in }) ]; + meta.tests = { + samba = ./tests/samba.nix; + }; + } diff --git a/nixos/tests/samba.nix b/nixos/modules/services/network-filesystems/tests/samba.nix similarity index 96% rename from nixos/tests/samba.nix rename to nixos/modules/services/network-filesystems/tests/samba.nix index d6658ef0400b4..3f09924c5bcf6 100644 --- a/nixos/tests/samba.nix +++ b/nixos/modules/services/network-filesystems/tests/samba.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: +{ pkgs, ... }: { name = "samba"; @@ -45,4 +45,4 @@ import ./make-test.nix ({ pkgs, ... }: $client->waitForUnit("network.target"); $client->succeed("[[ \$(cat /public/foo) = bar ]]"); ''; -}) +} diff --git a/nixos/modules/services/networking/avahi-daemon.nix b/nixos/modules/services/networking/avahi-daemon.nix index ecc091d1d03db..ecbcc5d63c3e8 100644 --- a/nixos/modules/services/networking/avahi-daemon.nix +++ b/nixos/modules/services/networking/avahi-daemon.nix @@ -204,4 +204,8 @@ in }; + meta.tests = { + avahi = ./tests/avahi.nix; + }; + } diff --git a/nixos/modules/services/networking/cjdns.nix b/nixos/modules/services/networking/cjdns.nix index cb00139c5f1cf..6f41f97b2768f 100644 --- a/nixos/modules/services/networking/cjdns.nix +++ b/nixos/modules/services/networking/cjdns.nix @@ -263,4 +263,8 @@ in }; + meta.tests = { + cjdns = ./tests/cjdns.nix; + }; + } diff --git a/nixos/modules/services/networking/ferm.nix b/nixos/modules/services/networking/ferm.nix index 6271e82541f4e..f2f716b0285e2 100644 --- a/nixos/modules/services/networking/ferm.nix +++ b/nixos/modules/services/networking/ferm.nix @@ -60,4 +60,8 @@ in { }; }; }; + + meta.tests = { + ferm = ./tests/ferm.nix; + }; } diff --git a/nixos/modules/services/networking/quagga.nix b/nixos/modules/services/networking/quagga.nix index ac83da9206386..98348648bec7a 100644 --- a/nixos/modules/services/networking/quagga.nix +++ b/nixos/modules/services/networking/quagga.nix @@ -182,6 +182,11 @@ in }; - meta.maintainers = with lib.maintainers; [ tavyc ]; + meta = { + maintainers = with lib.maintainers; [ tavyc ]; + tests = { + quagga = ./tests/quagga.nix; + }; + }; } diff --git a/nixos/modules/services/networking/smokeping.nix b/nixos/modules/services/networking/smokeping.nix index f7a5926dc64bb..e83ff64f92537 100644 --- a/nixos/modules/services/networking/smokeping.nix +++ b/nixos/modules/services/networking/smokeping.nix @@ -257,5 +257,8 @@ in script = ''${pkgs.thttpd}/bin/thttpd -u ${cfg.user} -c "**.fcgi" -d ${smokepingHome} -p ${builtins.toString cfg.port} -D''; }; }; -} + meta.tests = { + smokeping = ./tests/smokeping.nix; + }; +} diff --git a/nixos/modules/services/networking/ssh/sshd.nix b/nixos/modules/services/networking/ssh/sshd.nix index 3e9fae35847ee..d763cd07a0cb3 100644 --- a/nixos/modules/services/networking/ssh/sshd.nix +++ b/nixos/modules/services/networking/ssh/sshd.nix @@ -373,4 +373,8 @@ in }; + meta.tests = { + openssh = ./tests/openssh.nix; + }; + } diff --git a/nixos/tests/openssh.nix b/nixos/modules/services/networking/ssh/tests/openssh.nix similarity index 98% rename from nixos/tests/openssh.nix rename to nixos/modules/services/networking/ssh/tests/openssh.nix index 390363b88e218..ec4862643a547 100644 --- a/nixos/tests/openssh.nix +++ b/nixos/modules/services/networking/ssh/tests/openssh.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: +{ pkgs, ... }: let snakeOilPrivateKey = pkgs.writeText "privkey.snakeoil" '' @@ -68,4 +68,4 @@ in { " server true"); }; ''; -}) +} diff --git a/nixos/tests/avahi.nix b/nixos/modules/services/networking/tests/avahi.nix similarity index 97% rename from nixos/tests/avahi.nix rename to nixos/modules/services/networking/tests/avahi.nix index 976a770e887c2..7c763c3359111 100644 --- a/nixos/tests/avahi.nix +++ b/nixos/modules/services/networking/tests/avahi.nix @@ -1,5 +1,5 @@ # Test whether `avahi-daemon' and `libnss-mdns' work as expected. -import ./make-test.nix ({ pkgs, ... } : { +{ pkgs, ... } : { name = "avahi"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow ]; @@ -57,4 +57,4 @@ import ./make-test.nix ({ pkgs, ... } : { $two->succeed("getent hosts one.local >&2"); $two->succeed("getent hosts two.local >&2"); ''; -}) +} diff --git a/nixos/tests/cjdns.nix b/nixos/modules/services/networking/tests/cjdns.nix similarity index 98% rename from nixos/tests/cjdns.nix rename to nixos/modules/services/networking/tests/cjdns.nix index f61c82b916ad0..197882b517185 100644 --- a/nixos/tests/cjdns.nix +++ b/nixos/modules/services/networking/tests/cjdns.nix @@ -22,7 +22,7 @@ let in -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "cjdns"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ ehmry ]; @@ -122,4 +122,4 @@ import ./make-test.nix ({ pkgs, ...} : { $bob->succeed("curl --fail -g http://[$aliceIp6]"); ''; -}) +} diff --git a/nixos/tests/ferm.nix b/nixos/modules/services/networking/tests/ferm.nix similarity index 97% rename from nixos/tests/ferm.nix rename to nixos/modules/services/networking/tests/ferm.nix index 8f2a8c01eebc0..118c1143ce976 100644 --- a/nixos/tests/ferm.nix +++ b/nixos/modules/services/networking/tests/ferm.nix @@ -1,5 +1,4 @@ - -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "ferm"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ mic92 ]; @@ -69,4 +68,4 @@ import ./make-test.nix ({ pkgs, ...} : { $client->fail("curl --fail -g http://[fd00::1]:8080/status"); }; ''; -}) +} diff --git a/nixos/tests/quagga.nix b/nixos/modules/services/networking/tests/quagga.nix similarity index 98% rename from nixos/tests/quagga.nix rename to nixos/modules/services/networking/tests/quagga.nix index b9644b4768c0e..84701a6d84c7f 100644 --- a/nixos/tests/quagga.nix +++ b/nixos/modules/services/networking/tests/quagga.nix @@ -5,7 +5,7 @@ # # All interfaces are in OSPF Area 0. -import ./make-test.nix ({ pkgs, ... }: +{ pkgs, ... }: let ifAddr = node: iface: (pkgs.lib.head node.config.networking.interfaces.${iface}.ip4).address; @@ -94,4 +94,4 @@ import ./make-test.nix ({ pkgs, ... }: $server->waitForUnit("httpd"); $client->succeed("curl --fail http://server/ >&2"); ''; - }) + } diff --git a/nixos/tests/smokeping.nix b/nixos/modules/services/networking/tests/smokeping.nix similarity index 94% rename from nixos/tests/smokeping.nix rename to nixos/modules/services/networking/tests/smokeping.nix index 324f83147e003..cb978724d2944 100644 --- a/nixos/tests/smokeping.nix +++ b/nixos/modules/services/networking/tests/smokeping.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "smokeping"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ cransom ]; @@ -28,4 +28,4 @@ import ./make-test.nix ({ pkgs, ...} : { $sm->succeed("curl -s -f localhost:8081/smokeping.fcgi?target=Local"); $sm->succeed("ls /var/lib/smokeping/cache/Local/LocalMachine_mini.png"); ''; -}) +} diff --git a/nixos/modules/services/security/haka.nix b/nixos/modules/services/security/haka.nix index f48a79b1f7f1a..924dc6e9a835d 100644 --- a/nixos/modules/services/security/haka.nix +++ b/nixos/modules/services/security/haka.nix @@ -154,4 +154,8 @@ in }; }; }; + + meta.tests = { + haka = ./tests/haka.nix; + }; } diff --git a/nixos/tests/haka.nix b/nixos/modules/services/security/tests/haka.nix similarity index 90% rename from nixos/tests/haka.nix rename to nixos/modules/services/security/tests/haka.nix index 40548f34690f6..81f126751202d 100644 --- a/nixos/tests/haka.nix +++ b/nixos/modules/services/security/tests/haka.nix @@ -1,6 +1,6 @@ # This test runs haka and probes it with hakactl -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "haka"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ tvestelind ]; @@ -21,4 +21,4 @@ import ./make-test.nix ({ pkgs, ...} : { $haka->succeed("hakactl status"); $haka->succeed("hakactl stop"); ''; -}) +} diff --git a/nixos/modules/services/torrent/peerflix.nix b/nixos/modules/services/torrent/peerflix.nix index 2e3dd9902d729..c709c80422559 100644 --- a/nixos/modules/services/torrent/peerflix.nix +++ b/nixos/modules/services/torrent/peerflix.nix @@ -60,4 +60,8 @@ in { users.extraUsers.peerflix.uid = config.ids.uids.peerflix; }; + + meta.tests = { + peerflix = ./tests/peerflix.nix; + }; } diff --git a/nixos/tests/peerflix.nix b/nixos/modules/services/torrent/tests/peerflix.nix similarity index 90% rename from nixos/tests/peerflix.nix rename to nixos/modules/services/torrent/tests/peerflix.nix index eb729f22f913e..412f9b85db114 100644 --- a/nixos/tests/peerflix.nix +++ b/nixos/modules/services/torrent/tests/peerflix.nix @@ -1,6 +1,6 @@ # This test runs peerflix and checks if peerflix starts -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "peerflix"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ offline ]; @@ -20,4 +20,4 @@ import ./make-test.nix ({ pkgs, ...} : { $peerflix->waitForUnit("peerflix.service"); $peerflix->waitUntilSucceeds("curl localhost:9000"); ''; -}) +} diff --git a/nixos/modules/services/web-apps/pump.io.nix b/nixos/modules/services/web-apps/pump.io.nix index b7c64bc6940bf..b69138e828a6e 100644 --- a/nixos/modules/services/web-apps/pump.io.nix +++ b/nixos/modules/services/web-apps/pump.io.nix @@ -361,4 +361,8 @@ in createHome = true; }; }; + + meta.tests = { + pumpio = ./tests/pump.io.nix; + }; } diff --git a/nixos/tests/pump.io.nix b/nixos/modules/services/web-apps/tests/pump.io.nix similarity index 98% rename from nixos/tests/pump.io.nix rename to nixos/modules/services/web-apps/tests/pump.io.nix index 18da52b5134b4..d2a1632763c9c 100644 --- a/nixos/tests/pump.io.nix +++ b/nixos/modules/services/web-apps/tests/pump.io.nix @@ -1,6 +1,6 @@ # This test runs pump.io with mongodb, listing on port 443. -import ./make-test.nix ({ pkgs, ...} : let +{ pkgs, ...} : let snakeOilKey = '' -----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCqVemio78R41Tz @@ -91,4 +91,4 @@ in { $one->waitForUnit("pump.io.service"); $one->waitUntilSucceeds("curl -k https://localhost"); ''; -}) +} diff --git a/nixos/tests/tomcat.nix b/nixos/modules/services/web-servers/tests/tomcat.nix similarity index 94% rename from nixos/tests/tomcat.nix rename to nixos/modules/services/web-servers/tests/tomcat.nix index 475c947e72d98..5333d11573ffb 100644 --- a/nixos/tests/tomcat.nix +++ b/nixos/modules/services/web-servers/tests/tomcat.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "tomcat"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow ]; @@ -27,4 +27,4 @@ import ./make-test.nix ({ pkgs, ...} : { $client->waitUntilSucceeds("curl --fail http://server/examples/servlets/servlet/HelloWorldExample"); $client->waitUntilSucceeds("curl --fail http://server/examples/jsp/jsp2/simpletag/hello.jsp"); ''; -}) +} diff --git a/nixos/modules/services/web-servers/tomcat.nix b/nixos/modules/services/web-servers/tomcat.nix index 943415e08c645..bc205610968a1 100644 --- a/nixos/modules/services/web-servers/tomcat.nix +++ b/nixos/modules/services/web-servers/tomcat.nix @@ -365,4 +365,8 @@ in }; + meta.tests = { + tomcat = ./tests/tomcat.nix; + }; + } diff --git a/nixos/modules/services/x11/desktop-managers/gnome3.nix b/nixos/modules/services/x11/desktop-managers/gnome3.nix index dc71531759b85..1b8d78080ef6b 100644 --- a/nixos/modules/services/x11/desktop-managers/gnome3.nix +++ b/nixos/modules/services/x11/desktop-managers/gnome3.nix @@ -188,5 +188,9 @@ in { }; + meta.tests = { + gnome3 = ./tests/gnome3.nix; + gnome3-gdm = ./tests/gnome3-gdm.nix; + }; } diff --git a/nixos/modules/services/x11/desktop-managers/kde4.nix b/nixos/modules/services/x11/desktop-managers/kde4.nix index 3aa4821a05218..69b2f5d0134ae 100644 --- a/nixos/modules/services/x11/desktop-managers/kde4.nix +++ b/nixos/modules/services/x11/desktop-managers/kde4.nix @@ -196,4 +196,8 @@ in }; + meta.tests = { + kde4 = ./tests/kde4.nix; + }; + } diff --git a/nixos/modules/services/x11/desktop-managers/kde5.nix b/nixos/modules/services/x11/desktop-managers/kde5.nix index bc010d1ce1cf1..fc5c214d3c5e5 100644 --- a/nixos/modules/services/x11/desktop-managers/kde5.nix +++ b/nixos/modules/services/x11/desktop-managers/kde5.nix @@ -225,4 +225,8 @@ in }; + meta.tests = { + kde5 = ./tests/kde5.nix; + }; + } diff --git a/nixos/tests/gnome3-gdm.nix b/nixos/modules/services/x11/desktop-managers/tests/gnome3-gdm.nix similarity index 91% rename from nixos/tests/gnome3-gdm.nix rename to nixos/modules/services/x11/desktop-managers/tests/gnome3-gdm.nix index 42425b57ba330..401a77d2c5c63 100644 --- a/nixos/tests/gnome3-gdm.nix +++ b/nixos/modules/services/x11/desktop-managers/tests/gnome3-gdm.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "gnome3-gdm"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ lethalman ]; @@ -7,7 +7,7 @@ import ./make-test.nix ({ pkgs, ...} : { machine = { config, pkgs, ... }: - { imports = [ ./common/user-account.nix ]; + { imports = [ ]; services.xserver.enable = true; @@ -37,4 +37,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->sleep(20); $machine->screenshot("screen"); ''; -}) +} diff --git a/nixos/tests/gnome3.nix b/nixos/modules/services/x11/desktop-managers/tests/gnome3.nix similarity index 91% rename from nixos/tests/gnome3.nix rename to nixos/modules/services/x11/desktop-managers/tests/gnome3.nix index bd8f9502e2fc0..6ca4bcd46d601 100644 --- a/nixos/tests/gnome3.nix +++ b/nixos/modules/services/x11/desktop-managers/tests/gnome3.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "gnome3"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ domenkozar eelco chaoflow lethalman ]; @@ -7,7 +7,7 @@ import ./make-test.nix ({ pkgs, ...} : { machine = { config, pkgs, ... }: - { imports = [ ./common/user-account.nix ]; + { imports = [ ]; services.xserver.enable = true; @@ -33,4 +33,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->sleep(10); $machine->screenshot("screen"); ''; -}) +} diff --git a/nixos/tests/kde4.nix b/nixos/modules/services/x11/desktop-managers/tests/kde4.nix similarity index 95% rename from nixos/tests/kde4.nix rename to nixos/modules/services/x11/desktop-managers/tests/kde4.nix index 9ecfe68705643..b5fa45e6903e7 100644 --- a/nixos/tests/kde4.nix +++ b/nixos/modules/services/x11/desktop-managers/tests/kde4.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: { +{ pkgs, ... }: { name = "kde4"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ domenkozar eelco chaoflow ]; @@ -7,7 +7,7 @@ import ./make-test.nix ({ pkgs, ... }: { machine = { config, pkgs, ... }: - { imports = [ ./common/user-account.nix ]; + { imports = [ ]; virtualisation.memorySize = 1024; @@ -67,4 +67,4 @@ import ./make-test.nix ({ pkgs, ... }: { $machine->screenshot("screen"); ''; -}) +} diff --git a/nixos/tests/kde5.nix b/nixos/modules/services/x11/desktop-managers/tests/kde5.nix similarity index 100% rename from nixos/tests/kde5.nix rename to nixos/modules/services/x11/desktop-managers/tests/kde5.nix diff --git a/nixos/tests/xfce.nix b/nixos/modules/services/x11/desktop-managers/tests/xfce.nix similarity index 92% rename from nixos/tests/xfce.nix rename to nixos/modules/services/x11/desktop-managers/tests/xfce.nix index c8b18f1226580..0dd2ccaaaf861 100644 --- a/nixos/tests/xfce.nix +++ b/nixos/modules/services/x11/desktop-managers/tests/xfce.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "xfce"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow shlevy ]; @@ -7,7 +7,7 @@ import ./make-test.nix ({ pkgs, ...} : { machine = { config, pkgs, ... }: - { imports = [ ./common/user-account.nix ]; + { imports = [ ]; services.xserver.enable = true; @@ -39,4 +39,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->mustFail("su - bob -c 'DISPLAY=:0.0 xmessage Foo'"); $machine->mustFail("su - bob -c 'DISPLAY=:0 xmessage Foo'"); ''; -}) +} diff --git a/nixos/modules/services/x11/desktop-managers/xfce.nix b/nixos/modules/services/x11/desktop-managers/xfce.nix index 530468be5f96d..f2c801e206813 100644 --- a/nixos/modules/services/x11/desktop-managers/xfce.nix +++ b/nixos/modules/services/x11/desktop-managers/xfce.nix @@ -118,4 +118,8 @@ in }; + meta.tests = { + xfce = ./tests/xfce.nix; + }; + } diff --git a/nixos/modules/services/x11/display-managers/lightdm.nix b/nixos/modules/services/x11/display-managers/lightdm.nix index 33cd51f37c682..91d13a6567fb0 100644 --- a/nixos/modules/services/x11/display-managers/lightdm.nix +++ b/nixos/modules/services/x11/display-managers/lightdm.nix @@ -250,4 +250,8 @@ in services.xserver.tty = null; # We might start multiple X servers so let the tty increment themselves.. services.xserver.display = null; # We specify our own display (and logfile) in xserver-wrapper up there }; + + meta.tests = { + lightdm = ./tests/lightdm.nix; + }; } diff --git a/nixos/modules/services/x11/display-managers/sddm.nix b/nixos/modules/services/x11/display-managers/sddm.nix index c79893e77aa60..6d1dbce4a89fb 100644 --- a/nixos/modules/services/x11/display-managers/sddm.nix +++ b/nixos/modules/services/x11/display-managers/sddm.nix @@ -255,4 +255,8 @@ in users.extraGroups.sddm.gid = config.ids.gids.sddm; }; + + meta.tests = { + sddm = ./tests/sddm.nix; + }; } diff --git a/nixos/tests/lightdm.nix b/nixos/modules/services/x11/display-managers/tests/lightdm.nix similarity index 90% rename from nixos/tests/lightdm.nix rename to nixos/modules/services/x11/display-managers/tests/lightdm.nix index 97ec79406b884..d660ebd74cc51 100644 --- a/nixos/tests/lightdm.nix +++ b/nixos/modules/services/x11/display-managers/tests/lightdm.nix @@ -1,11 +1,11 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "lightdm"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ aszlig ]; }; machine = { lib, ... }: { - imports = [ ./common/user-account.nix ]; + imports = [ ]; services.xserver.enable = true; services.xserver.displayManager.lightdm.enable = true; services.xserver.windowManager.default = "icewm"; @@ -26,4 +26,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->succeed("xauth merge ~alice/.Xauthority"); $machine->waitForWindow("^IceWM "); ''; -}) +} diff --git a/nixos/tests/sddm.nix b/nixos/modules/services/x11/display-managers/tests/sddm.nix similarity index 88% rename from nixos/tests/sddm.nix rename to nixos/modules/services/x11/display-managers/tests/sddm.nix index 22a9e1bd2c7c4..4535dce778faf 100644 --- a/nixos/tests/sddm.nix +++ b/nixos/modules/services/x11/display-managers/tests/sddm.nix @@ -1,11 +1,11 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "sddm"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ ttuegel ]; }; machine = { lib, ... }: { - imports = [ ./common/user-account.nix ]; + imports = [ ]; services.xserver.enable = true; services.xserver.displayManager.sddm = { enable = true; @@ -27,4 +27,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->succeed("xauth merge ~alice/.Xauthority"); $machine->waitForWindow("^IceWM "); ''; -}) +} diff --git a/nixos/modules/services/x11/window-managers/i3.nix b/nixos/modules/services/x11/window-managers/i3.nix index cfe9439b688cc..c90ff9938e287 100644 --- a/nixos/modules/services/x11/window-managers/i3.nix +++ b/nixos/modules/services/x11/window-managers/i3.nix @@ -51,4 +51,8 @@ in (mkIf wmCfg.i3.enable (i3config "i3" pkgs.i3 wmCfg.i3)) (mkIf wmCfg.i3-gaps.enable (i3config "i3-gaps" pkgs.i3-gaps wmCfg.i3-gaps)) ]; + + meta.tests = { + i3wm = ./tests/i3wm.nix; + }; } diff --git a/nixos/tests/i3wm.nix b/nixos/modules/services/x11/window-managers/tests/i3wm.nix similarity index 87% rename from nixos/tests/i3wm.nix rename to nixos/modules/services/x11/window-managers/tests/i3wm.nix index 4685992d7a053..5c378426a8a43 100644 --- a/nixos/tests/i3wm.nix +++ b/nixos/modules/services/x11/window-managers/tests/i3wm.nix @@ -1,11 +1,14 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "i3wm"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ aszlig ]; }; machine = { lib, pkgs, ... }: { - imports = [ ./common/x11.nix ./common/user-account.nix ]; + imports = [ + + + ]; services.xserver.displayManager.auto.user = "alice"; services.xserver.windowManager.default = lib.mkForce "i3"; services.xserver.windowManager.i3.enable = true; @@ -30,4 +33,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->sleep(1); $machine->screenshot("terminal"); ''; -}) +} diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix index aa28a25be7aca..b3b3e310596a3 100644 --- a/nixos/modules/virtualisation/containers.nix +++ b/nixos/modules/virtualisation/containers.nix @@ -655,4 +655,12 @@ in environment.systemPackages = [ pkgs.nixos-container ]; }); + + meta.tests = { + containers-ipv4 = ./tests/containers-ipv4.nix; + containers-ipv6 = ./tests/containers-ipv6.nix; + containers-bridge = ./tests/containers-bridge.nix; + containers-imperative = ./tests/containers-imperative.nix; + containers-extra_veth = ./tests/containers-extra_veth.nix; + }; } diff --git a/nixos/modules/virtualisation/docker.nix b/nixos/modules/virtualisation/docker.nix index 92fe98f3f9c27..a54d493b8e96a 100644 --- a/nixos/modules/virtualisation/docker.nix +++ b/nixos/modules/virtualisation/docker.nix @@ -134,4 +134,8 @@ in }) ]); + meta.tests = { + docker = ./tests/docker.nix; + }; + } diff --git a/nixos/tests/containers-bridge.nix b/nixos/modules/virtualisation/tests/containers-bridge.nix similarity index 95% rename from nixos/tests/containers-bridge.nix rename to nixos/modules/virtualisation/tests/containers-bridge.nix index bb32d852a6f56..9fb98ee0fd2ee 100644 --- a/nixos/tests/containers-bridge.nix +++ b/nixos/modules/virtualisation/tests/containers-bridge.nix @@ -7,7 +7,7 @@ let containerIp6 = "fc00::2/7"; in -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "containers-bridge"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ aristid aszlig eelco chaoflow kampfschlaefer ]; @@ -15,7 +15,7 @@ import ./make-test.nix ({ pkgs, ...} : { machine = { config, pkgs, ... }: - { imports = [ ../modules/installer/cd-dvd/channel.nix ]; + { imports = [ ]; virtualisation.writableStore = true; virtualisation.memorySize = 768; @@ -78,4 +78,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->fail("nixos-container destroy webserver"); ''; -}) +} diff --git a/nixos/tests/containers-extra_veth.nix b/nixos/modules/virtualisation/tests/containers-extra_veth.nix similarity index 96% rename from nixos/tests/containers-extra_veth.nix rename to nixos/modules/virtualisation/tests/containers-extra_veth.nix index 2a54b1d961c80..e6cf84503f95b 100644 --- a/nixos/tests/containers-extra_veth.nix +++ b/nixos/modules/virtualisation/tests/containers-extra_veth.nix @@ -1,6 +1,6 @@ # Test for NixOS' container support. -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "containers-bridge"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ kampfschlaefer ]; @@ -8,7 +8,7 @@ import ./make-test.nix ({ pkgs, ...} : { machine = { config, pkgs, ... }: - { imports = [ ../modules/installer/cd-dvd/channel.nix ]; + { imports = [ ]; virtualisation.writableStore = true; virtualisation.memorySize = 768; virtualisation.vlans = []; @@ -100,4 +100,4 @@ import ./make-test.nix ({ pkgs, ...} : { # Destroying a declarative container should fail. $machine->fail("nixos-container destroy webserver"); ''; -}) +} diff --git a/nixos/tests/containers-imperative.nix b/nixos/modules/virtualisation/tests/containers-imperative.nix similarity index 95% rename from nixos/tests/containers-imperative.nix rename to nixos/modules/virtualisation/tests/containers-imperative.nix index 7e2a54976387d..ee4eff59547eb 100644 --- a/nixos/tests/containers-imperative.nix +++ b/nixos/modules/virtualisation/tests/containers-imperative.nix @@ -1,6 +1,6 @@ # Test for NixOS' container support. -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "containers-imperative"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ aristid aszlig eelco chaoflow kampfschlaefer ]; @@ -8,13 +8,13 @@ import ./make-test.nix ({ pkgs, ...} : { machine = { config, pkgs, lib, ... }: - { imports = [ ../modules/installer/cd-dvd/channel.nix ]; + { imports = [ ]; virtualisation.writableStore = true; virtualisation.memorySize = 768; # Make sure we always have all the required dependencies for creating a # container available within the VM, because we don't have network access. virtualisation.pathsInNixDB = let - emptyContainer = import ../lib/eval-config.nix { + emptyContainer = import { inherit (config.nixpkgs) system; modules = lib.singleton { containers.foo.config = {}; @@ -93,4 +93,4 @@ import ./make-test.nix ({ pkgs, ...} : { ); ''; -}) +} diff --git a/nixos/tests/containers-ipv4.nix b/nixos/modules/virtualisation/tests/containers-ipv4.nix similarity index 94% rename from nixos/tests/containers-ipv4.nix rename to nixos/modules/virtualisation/tests/containers-ipv4.nix index 31d05990a679b..0225f8d5e77c6 100644 --- a/nixos/tests/containers-ipv4.nix +++ b/nixos/modules/virtualisation/tests/containers-ipv4.nix @@ -1,6 +1,6 @@ # Test for NixOS' container support. -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "containers-ipv4"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ aristid aszlig eelco chaoflow kampfschlaefer ]; @@ -8,7 +8,7 @@ import ./make-test.nix ({ pkgs, ...} : { machine = { config, pkgs, ... }: - { imports = [ ../modules/installer/cd-dvd/channel.nix ]; + { imports = [ ]; virtualisation.writableStore = true; virtualisation.memorySize = 768; @@ -52,4 +52,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->fail("nixos-container destroy webserver"); ''; -}) +} diff --git a/nixos/tests/containers-ipv6.nix b/nixos/modules/virtualisation/tests/containers-ipv6.nix similarity index 94% rename from nixos/tests/containers-ipv6.nix rename to nixos/modules/virtualisation/tests/containers-ipv6.nix index 320465ebb95b1..976b145bd3333 100644 --- a/nixos/tests/containers-ipv6.nix +++ b/nixos/modules/virtualisation/tests/containers-ipv6.nix @@ -5,7 +5,7 @@ let localIp = "fc00::1"; in -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "containers-ipv6"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ aristid aszlig eelco chaoflow kampfschlaefer ]; @@ -13,7 +13,7 @@ import ./make-test.nix ({ pkgs, ...} : { machine = { config, pkgs, ... }: - { imports = [ ../modules/installer/cd-dvd/channel.nix ]; + { imports = [ ]; virtualisation.writableStore = true; virtualisation.memorySize = 768; @@ -58,4 +58,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->fail("nixos-container destroy webserver"); ''; -}) +} diff --git a/nixos/tests/docker.nix b/nixos/modules/virtualisation/tests/docker.nix similarity index 94% rename from nixos/tests/docker.nix rename to nixos/modules/virtualisation/tests/docker.nix index 1b57a94a05d40..8d82ced548ea8 100644 --- a/nixos/tests/docker.nix +++ b/nixos/modules/virtualisation/tests/docker.nix @@ -1,6 +1,6 @@ # This test runs docker and checks if simple container starts -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "docker"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ offline ]; @@ -23,4 +23,4 @@ import ./make-test.nix ({ pkgs, ...} : { $docker->succeed("docker ps | grep sleeping"); $docker->succeed("docker stop sleeping"); ''; -}) +} diff --git a/nixos/tests/virtualbox.nix b/nixos/modules/virtualisation/tests/virtualbox.nix similarity index 97% rename from nixos/tests/virtualbox.nix rename to nixos/modules/virtualisation/tests/virtualbox.nix index 66f16ed8bcc5c..35f0df4d05cae 100644 --- a/nixos/tests/virtualbox.nix +++ b/nixos/modules/virtualisation/tests/virtualbox.nix @@ -1,6 +1,5 @@ -{ system ? builtins.currentSystem, debug ? false }: +{ pkgs, system ? builtins.currentSystem, debug ? false, ... }: -with import ../lib/testing.nix { inherit system; }; with pkgs.lib; let @@ -85,10 +84,10 @@ let in optionalString debug "$machine->execute(ru '${logcmd} & disown');"; testVM = vmName: vmScript: let - cfg = (import ../lib/eval-config.nix { + cfg = (import { system = "i686-linux"; modules = [ - ../modules/profiles/minimal.nix + (testVMConfig vmName vmScript) ]; }).config; @@ -323,14 +322,14 @@ let headless.services.xserver.enable = false; }; - mkVBoxTest = name: testScript: makeTest { + mkVBoxTest = name: testScript: { name = "virtualbox-${name}"; machine = { lib, config, ... }: { imports = let mkVMConf = name: val: val.machine // { key = "${name}-config"; }; vmConfigs = mapAttrsToList mkVMConf vboxVMs; - in [ ./common/user-account.nix ./common/x11.nix ] ++ vmConfigs; + in [ ] ++ vmConfigs; virtualisation.memorySize = 2048; virtualisation.virtualbox.host.enable = true; services.xserver.displayManager.auto.user = "alice"; diff --git a/nixos/modules/virtualisation/virtualbox-host.nix b/nixos/modules/virtualisation/virtualbox-host.nix index 7214543871d6f..ffddbf865b6ee 100644 --- a/nixos/modules/virtualisation/virtualbox-host.nix +++ b/nixos/modules/virtualisation/virtualbox-host.nix @@ -129,4 +129,8 @@ in # means we have internet access. networking.networkmanager.unmanaged = ["vboxnet0"]; })]); + + meta.tests = { + virtualbox = ./tests/virtualbox.nix; + }; } diff --git a/nixos/release-combined.nix b/nixos/release-combined.nix index 70b29aa23a5bc..785d8c48cdd2f 100644 --- a/nixos/release-combined.nix +++ b/nixos/release-combined.nix @@ -51,7 +51,7 @@ in rec { nixos.tests.chromium (all nixos.tests.firefox) (all nixos.tests.firewall) - nixos.tests.gnome3.x86_64-linux # FIXME: i686-linux + nixos.tests.module.gnome3.x86_64-linux # FIXME: i686-linux (all nixos.tests.installer.lvm) (all nixos.tests.installer.luksroot) (all nixos.tests.installer.separateBoot) @@ -71,9 +71,9 @@ in rec { (all nixos.tests.hibernate) (all nixos.tests.ecryptfs) (all nixos.tests.ipv6) - (all nixos.tests.i3wm) - (all nixos.tests.kde4) - (all nixos.tests.kde5) + (all nixos.tests.module.i3wm) + (all nixos.tests.module.kde4) + (all nixos.tests.module.kde5) #(all nixos.tests.lightdm) (all nixos.tests.login) (all nixos.tests.misc) @@ -90,13 +90,13 @@ in rec { (all nixos.tests.networking.scripted.vlan) (all nixos.tests.nfs3) (all nixos.tests.nfs4) - (all nixos.tests.openssh) + (all nixos.tests.module.openssh) (all nixos.tests.printing) (all nixos.tests.proxy) - (all nixos.tests.sddm) + (all nixos.tests.module.sddm) (all nixos.tests.simple) - (all nixos.tests.udisks2) - (all nixos.tests.xfce) + (all nixos.tests.module.udisks2) + (all nixos.tests.module.xfce) nixpkgs.tarball (all nixpkgs.emacs) diff --git a/nixos/release.nix b/nixos/release.nix index bff17da607f30..1d0c5bb15c7ee 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -3,7 +3,9 @@ , supportedSystems ? [ "x86_64-linux" "i686-linux" ] }: -with import ../lib; +with { + inherit (import ../lib/testing { inherit supportedSystems; }) callTest; +} // (import ../lib); let @@ -17,25 +19,8 @@ let inherit system; } // args); - callTest = fn: args: forAllSystems (system: hydraJob (importTest fn args system)); - - callSubTests = fn: args: let - discover = attrs: let - subTests = filterAttrs (const (hasAttr "test")) attrs; - in mapAttrs (const (t: hydraJob t.test)) subTests; - - discoverForSystem = system: mapAttrs (_: test: { - ${system} = test; - }) (discover (importTest fn args system)); - - # If the test is only for a particular system, use only the specified - # system instead of generating attributes for all available systems. - in if args ? system then discover (import fn args) - else foldAttrs mergeAttrs {} (map discoverForSystem supportedSystems); - pkgs = import nixpkgs { system = "x86_64-linux"; }; - versionModule = { system.nixosVersionSuffix = versionSuffix; system.nixosRevision = nixpkgs.rev or nixpkgs.shortRev; @@ -89,6 +74,28 @@ let }); }).config)); + # list of blacklisted module tests that shouldn't end in `tests.module` + blacklistedModuleTests = [ + "postgis" + "emacs-daemon" + "gitlab" + "haka" + "lightdm" + "logstash" + "mesos" + "panamax" + "rabbitmq" + "riak" + "slurm" + ]; + + # Gather tests declared in modules meta.tests + # args is a set of { "testName" = { extra args }; } to override test arguments, typically systems + moduleTests = args: + let tests = (import lib/eval-config.nix { modules = []; }).config.meta.tests; + filteredTests = filterAttrs (k: _: !(elem k blacklistedModuleTests)) tests; + args' = k: attrByPath [k] {} args; + in mapAttrs (k: v: callTest (head v).value (args' k)) filteredTests; in rec { @@ -214,86 +221,52 @@ in rec { # Run the tests for each platform. You can run a test by doing # e.g. ‘nix-build -A tests.login.x86_64-linux’, or equivalently, # ‘nix-build tests/login.nix -A result’. - tests.avahi = callTest tests/avahi.nix {}; tests.bittorrent = callTest tests/bittorrent.nix {}; tests.blivet = callTest tests/blivet.nix {}; - tests.boot = callSubTests tests/boot.nix {}; + tests.boot = callTest tests/boot.nix {}; tests.boot-stage1 = callTest tests/boot-stage1.nix {}; - tests.cadvisor = hydraJob (import tests/cadvisor.nix { system = "x86_64-linux"; }); - tests.chromium = (callSubTests tests/chromium.nix { system = "x86_64-linux"; }).stable; - tests.cjdns = callTest tests/cjdns.nix {}; - tests.containers-ipv4 = callTest tests/containers-ipv4.nix {}; - tests.containers-ipv6 = callTest tests/containers-ipv6.nix {}; - tests.containers-bridge = callTest tests/containers-bridge.nix {}; - tests.containers-imperative = callTest tests/containers-imperative.nix {}; - tests.containers-extra_veth = callTest tests/containers-extra_veth.nix {}; - tests.docker = hydraJob (import tests/docker.nix { system = "x86_64-linux"; }); - tests.dnscrypt-proxy = callTest tests/dnscrypt-proxy.nix { system = "x86_64-linux"; }; + tests.chromium = (callTest tests/chromium.nix { systems = [ "x86_64-linux" ]; }).stable; + tests.dnscrypt-proxy = callTest tests/dnscrypt-proxy.nix { systems = [ "x86_64-linux" ]; }; tests.ecryptfs = callTest tests/ecryptfs.nix {}; - tests.etcd = hydraJob (import tests/etcd.nix { system = "x86_64-linux"; }); - tests.ec2-nixops = hydraJob (import tests/ec2.nix { system = "x86_64-linux"; }).boot-ec2-nixops; - tests.ec2-config = hydraJob (import tests/ec2.nix { system = "x86_64-linux"; }).boot-ec2-config; - tests.ferm = callTest tests/ferm.nix {}; + tests.ec2-nixops = (callTest tests/ec2.nix { systems = [ "x86_64-linux" ]; }).boot-ec2-nixops; + tests.ec2-config = (callTest tests/ec2.nix { systems = [ "x86_64-linux" ]; }).boot-ec2-config; tests.firefox = callTest tests/firefox.nix {}; tests.firewall = callTest tests/firewall.nix {}; - tests.fleet = hydraJob (import tests/fleet.nix { system = "x86_64-linux"; }); #tests.gitlab = callTest tests/gitlab.nix {}; - tests.gocd-agent = callTest tests/gocd-agent.nix {}; - tests.gocd-server = callTest tests/gocd-server.nix {}; - tests.gnome3 = callTest tests/gnome3.nix {}; - tests.gnome3-gdm = callTest tests/gnome3-gdm.nix {}; - tests.grsecurity = callTest tests/grsecurity.nix {}; tests.hibernate = callTest tests/hibernate.nix {}; - tests.i3wm = callTest tests/i3wm.nix {}; - tests.installer = callSubTests tests/installer.nix {}; - tests.influxdb = callTest tests/influxdb.nix {}; + tests.installer = callTest tests/installer.nix {}; tests.ipv6 = callTest tests/ipv6.nix {}; - tests.jenkins = callTest tests/jenkins.nix {}; - tests.kde4 = callTest tests/kde4.nix {}; - tests.kde5 = callTest tests/kde5.nix {}; - tests.keymap = callSubTests tests/keymap.nix {}; + tests.keymap = callTest tests/keymap.nix {}; tests.initrdNetwork = callTest tests/initrd-network.nix {}; - tests.kubernetes = hydraJob (import tests/kubernetes.nix { system = "x86_64-linux"; }); tests.latestKernel.login = callTest tests/login.nix { latestKernel = true; }; #tests.lightdm = callTest tests/lightdm.nix {}; tests.login = callTest tests/login.nix {}; #tests.logstash = callTest tests/logstash.nix {}; - tests.mathics = callTest tests/mathics.nix {}; tests.misc = callTest tests/misc.nix {}; - tests.mongodb = callTest tests/mongodb.nix {}; tests.mumble = callTest tests/mumble.nix {}; - tests.munin = callTest tests/munin.nix {}; - tests.mysql = callTest tests/mysql.nix {}; - tests.mysqlReplication = callTest tests/mysql-replication.nix {}; tests.nat.firewall = callTest tests/nat.nix { withFirewall = true; }; tests.nat.standalone = callTest tests/nat.nix { withFirewall = false; }; - tests.networking.networkd = callSubTests tests/networking.nix { networkd = true; }; - tests.networking.scripted = callSubTests tests/networking.nix { networkd = false; }; + tests.networking.networkd = callTest tests/networking.nix { networkd = true; }; + tests.networking.scripted = callTest tests/networking.nix { networkd = false; }; # TODO: put in networking.nix after the test becomes more complete tests.networkingProxy = callTest tests/networking-proxy.nix {}; tests.nfs3 = callTest tests/nfs.nix { version = 3; }; tests.nfs4 = callTest tests/nfs.nix { version = 4; }; tests.nsd = callTest tests/nsd.nix {}; - tests.openssh = callTest tests/openssh.nix {}; - #tests.panamax = hydraJob (import tests/panamax.nix { system = "x86_64-linux"; }); - tests.peerflix = callTest tests/peerflix.nix {}; - tests.postgresql = callTest tests/postgresql.nix {}; tests.printing = callTest tests/printing.nix {}; tests.proxy = callTest tests/proxy.nix {}; - tests.pumpio = callTest tests/pump.io.nix {}; - tests.quagga = callTest tests/quagga.nix {}; tests.quake3 = callTest tests/quake3.nix {}; tests.runInMachine = callTest tests/run-in-machine.nix {}; - tests.samba = callTest tests/samba.nix {}; - tests.sddm = callTest tests/sddm.nix {}; tests.simple = callTest tests/simple.nix {}; - tests.smokeping = callTest tests/smokeping.nix {}; - tests.taskserver = callTest tests/taskserver.nix {}; - tests.tomcat = callTest tests/tomcat.nix {}; - tests.udisks2 = callTest tests/udisks2.nix {}; - tests.virtualbox = callSubTests tests/virtualbox.nix { system = "x86_64-linux"; }; - tests.xfce = callTest tests/xfce.nix {}; - + tests.module = moduleTests { + cadvisor = { systems = [ "x86_64-linux" ]; }; + kubernetes = { systems = [ "x86_64-linux" ]; }; + docker = { systems = [ "x86_64-linux" ]; }; + etcd = { systems = [ "x86_64-linux" ]; }; + fleet = { systems = [ "x86_64-linux" ]; }; + panamax = { systems = [ "x86_64-linux" ]; }; + virtualbox = { systems = [ "x86_64-linux" ]; }; + }; /* Build a bunch of typical closures so that Hydra can keep track of the evolution of closure sizes. */ diff --git a/nixos/tests/bittorrent.nix b/nixos/tests/bittorrent.nix index 5aded554f4e8b..9ade66bc2b014 100644 --- a/nixos/tests/bittorrent.nix +++ b/nixos/tests/bittorrent.nix @@ -6,7 +6,7 @@ # which only works if the first client successfully uses the UPnP-IGD # protocol to poke a hole in the NAT. -import ./make-test.nix ({ pkgs, ... }: +{ pkgs, ... }: let @@ -113,4 +113,4 @@ in $client2->succeed("cmp /tmp/test.tar.bz2 ${file}"); ''; -}) +} diff --git a/nixos/tests/blivet.nix b/nixos/tests/blivet.nix index a7b836ce99a6b..5fdde90a28b84 100644 --- a/nixos/tests/blivet.nix +++ b/nixos/tests/blivet.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: with pkgs.pythonPackages; rec { +{ pkgs, ... }: with pkgs.pythonPackages; rec { name = "blivet"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ aszlig ]; @@ -84,4 +84,4 @@ import ./make-test.nix ({ pkgs, ... }: with pkgs.pythonPackages; rec { $machine->succeed("${blivetTest}"); $machine->execute("rm -rf /tmp/xchg/bigtmp"); ''; -}) +} diff --git a/nixos/tests/boot-stage1.nix b/nixos/tests/boot-stage1.nix index 50186525cf399..d4f2bc2733975 100644 --- a/nixos/tests/boot-stage1.nix +++ b/nixos/tests/boot-stage1.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: { +{ pkgs, ... }: { name = "boot-stage1"; machine = { config, pkgs, lib, ... }: { @@ -153,4 +153,4 @@ import ./make-test.nix ({ pkgs, ... }: { ''; meta.maintainers = with pkgs.stdenv.lib.maintainers; [ aszlig ]; -}) +} diff --git a/nixos/tests/boot.nix b/nixos/tests/boot.nix index 3ea0df65c8b5a..313a3e31723d8 100644 --- a/nixos/tests/boot.nix +++ b/nixos/tests/boot.nix @@ -1,6 +1,5 @@ -{ system ? builtins.currentSystem }: +{ pkgs, system ? builtins.currentSystem, ... }: -with import ../lib/testing.nix { inherit system; }; with import ../lib/qemu-flags.nix; with pkgs.lib; @@ -16,7 +15,7 @@ let }).config.system.build.isoImage; makeBootTest = name: machineConfig: - makeTest { + { inherit iso; name = "boot-" + name; nodes = { }; @@ -77,7 +76,7 @@ in { ]; }; in - makeTest { + { name = "boot-netboot"; nodes = { }; testScript = diff --git a/nixos/tests/chromium.nix b/nixos/tests/chromium.nix index 9a6414f81c390..6f55d0e782ff6 100644 --- a/nixos/tests/chromium.nix +++ b/nixos/tests/chromium.nix @@ -1,16 +1,16 @@ -{ system ? builtins.currentSystem -, pkgs ? import ../.. { inherit system; } +{ pkgs +, system ? builtins.currentSystem , channelMap ? { stable = pkgs.chromium; beta = pkgs.chromiumBeta; dev = pkgs.chromiumDev; } +, ... }: -with import ../lib/testing.nix { inherit system; }; with pkgs.lib; -mapAttrs (channel: chromiumPkg: makeTest rec { +mapAttrs (channel: chromiumPkg: rec { name = "chromium-${channel}"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ aszlig ]; diff --git a/nixos/tests/dnscrypt-proxy.nix b/nixos/tests/dnscrypt-proxy.nix index b686e9582a7d9..fb02293bcf494 100644 --- a/nixos/tests/dnscrypt-proxy.nix +++ b/nixos/tests/dnscrypt-proxy.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: { +{ pkgs, ... }: { name = "dnscrypt-proxy"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ joachifm ]; @@ -30,4 +30,4 @@ import ./make-test.nix ({ pkgs, ... }: { $client->execute("${pkgs.iputils}/bin/ping -c1 example.com"); $client->succeed("systemctl is-active dnscrypt-proxy"); ''; -}) +} diff --git a/nixos/tests/ec2.nix b/nixos/tests/ec2.nix index e1f7143e3a956..4ad0752ffccac 100644 --- a/nixos/tests/ec2.nix +++ b/nixos/tests/ec2.nix @@ -1,6 +1,5 @@ -{ system ? builtins.currentSystem }: +{ pkgs, system ? builtins.currentSystem, ... }: -with import ../lib/testing.nix { inherit system; }; with import ../lib/qemu-flags.nix; with pkgs.lib; @@ -46,7 +45,7 @@ let ln -s ${pkgs.writeText "sshPublicKey" sshPublicKey} $out/1.0/meta-data/public-keys/0/openssh-key ''; }; - in makeTest { + in { name = "ec2-" + name; nodes = {}; testScript = diff --git a/nixos/tests/ecryptfs.nix b/nixos/tests/ecryptfs.nix index db800c7bb2c25..0186c9b7eb8d6 100644 --- a/nixos/tests/ecryptfs.nix +++ b/nixos/tests/ecryptfs.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: +{ pkgs, ... }: { name = "ecryptfs"; @@ -78,4 +78,4 @@ import ./make-test.nix ({ pkgs, ... }: $machine->sendChars("logout\n"); ''; -}) +} diff --git a/nixos/tests/firefox.nix b/nixos/tests/firefox.nix index 1bdabe93fec19..0548a08cba260 100644 --- a/nixos/tests/firefox.nix +++ b/nixos/tests/firefox.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: { +{ pkgs, ... }: { name = "firefox"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow shlevy ]; @@ -20,4 +20,4 @@ import ./make-test.nix ({ pkgs, ... }: { $machine->screenshot("screen"); ''; -}) +} diff --git a/nixos/tests/firewall.nix b/nixos/tests/firewall.nix index 1119a5312eb5b..d19d5a77f6860 100644 --- a/nixos/tests/firewall.nix +++ b/nixos/tests/firewall.nix @@ -1,6 +1,6 @@ # Test the firewall module. -import ./make-test.nix ( { pkgs, ... } : { +{ pkgs, ... } : { name = "firewall"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow ]; @@ -62,4 +62,4 @@ import ./make-test.nix ( { pkgs, ... } : { $walled->succeed("${newSystem}/bin/switch-to-configuration test 2>&1" . " | grep -qF firewall.service"); ''; -}) +} diff --git a/nixos/tests/hibernate.nix b/nixos/tests/hibernate.nix index 787929f8904df..e38f7408f52d1 100644 --- a/nixos/tests/hibernate.nix +++ b/nixos/tests/hibernate.nix @@ -1,6 +1,6 @@ # Test whether hibernation from partition works. -import ./make-test.nix (pkgs: { +{ pkgs, ... }: { name = "hibernate"; nodes = { @@ -39,4 +39,4 @@ import ./make-test.nix (pkgs: { $probe->waitUntilSucceeds("echo test | nc -c machine 4444"); ''; -}) +} diff --git a/nixos/tests/initrd-network.nix b/nixos/tests/initrd-network.nix index db9f572d3c2f6..7e266a609f02b 100644 --- a/nixos/tests/initrd-network.nix +++ b/nixos/tests/initrd-network.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "initrd-network"; meta.maintainers = [ pkgs.stdenv.lib.maintainers.eelco ]; @@ -19,4 +19,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->waitForUnit("multi-user.target"); $machine->succeed("ip link >&2"); ''; -}) +} diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix index 1df2c651f9bcb..1f62444ed142d 100644 --- a/nixos/tests/installer.nix +++ b/nixos/tests/installer.nix @@ -1,6 +1,5 @@ -{ system ? builtins.currentSystem }: +{ pkgs, system ? builtins.currentSystem, ... }: -with import ../lib/testing.nix { inherit system; }; with import ../lib/qemu-flags.nix; with pkgs.lib; @@ -163,7 +162,7 @@ let , grubVersion ? 2, grubDevice ? "/dev/vda", grubIdentifier ? "uuid" , enableOCR ? false, meta ? {} }: - makeTest { + { inherit enableOCR; name = "installer-" + name; meta = with pkgs.stdenv.lib.maintainers; { diff --git a/nixos/tests/ipv6.nix b/nixos/tests/ipv6.nix index 4e2e6379cad31..0f3d7a193c264 100644 --- a/nixos/tests/ipv6.nix +++ b/nixos/tests/ipv6.nix @@ -1,7 +1,7 @@ # Test of IPv6 functionality in NixOS, including whether router # solicication/advertisement using radvd works. -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "ipv6"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow ]; @@ -76,4 +76,4 @@ import ./make-test.nix ({ pkgs, ...} : { # TODO: test reachability of a machine on another network. ''; -}) +} diff --git a/nixos/tests/kexec.nix b/nixos/tests/kexec.nix index 0f5ddef7b1aae..753920c6faa85 100644 --- a/nixos/tests/kexec.nix +++ b/nixos/tests/kexec.nix @@ -1,6 +1,6 @@ # Test whether fast reboots via kexec work. -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "kexec"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow ]; @@ -16,4 +16,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->{connected} = 0; $machine->waitForUnit("multi-user.target"); ''; -}) +} diff --git a/nixos/tests/keymap.nix b/nixos/tests/keymap.nix index 55a0e7603882c..b24615cc0480c 100644 --- a/nixos/tests/keymap.nix +++ b/nixos/tests/keymap.nix @@ -1,6 +1,4 @@ -{ system ? builtins.currentSystem }: - -with import ../lib/testing.nix { inherit system; }; +{ pkgs, system ? builtins.currentSystem, ... }: let testReader = pkgs.writeScript "test-input-reader" '' @@ -43,7 +41,7 @@ let readerInput = flatten (mapAttrsToList mkReaderInput tests); perlStr = val: "'${escape ["'" "\\"] val}'"; perlReaderInput = concatMapStringsSep ", " perlStr readerInput; - in makeTest { + in { name = "keymap-${layout}"; machine.i18n.consoleKeyMap = mkOverride 900 layout; diff --git a/nixos/tests/login.nix b/nixos/tests/login.nix index e793d89567bf4..21495501508a6 100644 --- a/nixos/tests/login.nix +++ b/nixos/tests/login.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, latestKernel ? false, ... }: +{ pkgs, latestKernel ? false, ... }: { name = "login"; @@ -68,4 +68,4 @@ import ./make-test.nix ({ pkgs, latestKernel ? false, ... }: }; ''; -}) +} diff --git a/nixos/tests/make-test.nix b/nixos/tests/make-test.nix deleted file mode 100644 index f3e26aa7e74d2..0000000000000 --- a/nixos/tests/make-test.nix +++ /dev/null @@ -1,5 +0,0 @@ -f: { system ? builtins.currentSystem, ... } @ args: - -with import ../lib/testing.nix { inherit system; }; - -makeTest (if builtins.isFunction f then f (args // { inherit pkgs; inherit (pkgs) lib; }) else f) diff --git a/nixos/tests/misc.nix b/nixos/tests/misc.nix index cd4086cb8f62c..d9e77a674e68c 100644 --- a/nixos/tests/misc.nix +++ b/nixos/tests/misc.nix @@ -1,6 +1,6 @@ # Miscellaneous small tests that don't warrant their own VM run. -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "misc"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow ]; @@ -127,4 +127,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->succeed("[ `su - alice -c 'pgrep -c -u root'` != 0 ]"); }; ''; -}) +} diff --git a/nixos/tests/mpich.nix b/nixos/tests/mpich.nix index a28e41deb31eb..d063134dc2b5d 100644 --- a/nixos/tests/mpich.nix +++ b/nixos/tests/mpich.nix @@ -1,6 +1,6 @@ # Simple example to showcase distributed tests using NixOS VMs. -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "mpich"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow ]; @@ -38,4 +38,4 @@ import ./make-test.nix ({ pkgs, ...} : { $master->succeed("mpiexec -n 2 ./example >&2"); ''; -}) +} diff --git a/nixos/tests/mumble.nix b/nixos/tests/mumble.nix index 7959b85a0cf00..492a917a069ba 100644 --- a/nixos/tests/mumble.nix +++ b/nixos/tests/mumble.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : +{ pkgs, ...} : let client = { config, pkgs, ... }: { @@ -70,4 +70,4 @@ in $client1->screenshot("screen1"); $client2->screenshot("screen2"); ''; -}) +} diff --git a/nixos/tests/nat.nix b/nixos/tests/nat.nix index 4fbf64462682d..254445c62b589 100644 --- a/nixos/tests/nat.nix +++ b/nixos/tests/nat.nix @@ -3,7 +3,7 @@ # client on the inside network, a server on the outside network, and a # router connected to both that performs Network Address Translation # for the client. -import ./make-test.nix ({ pkgs, withFirewall, ... }: +{ pkgs, withFirewall, ... }: let unit = if withFirewall then "firewall" else "nat"; in @@ -83,4 +83,4 @@ import ./make-test.nix ({ pkgs, withFirewall, ... }: $client->succeed("curl --fail http://server/ >&2"); $client->succeed("ping -c 1 server >&2"); ''; - }) + } diff --git a/nixos/tests/networking-proxy.nix b/nixos/tests/networking-proxy.nix index 4c57257314044..16cd8caf82c6b 100644 --- a/nixos/tests/networking-proxy.nix +++ b/nixos/tests/networking-proxy.nix @@ -10,7 +10,7 @@ let default-config = { virtualisation.memorySize = 128; }; -in import ./make-test.nix ({ pkgs, ...} : { +in { pkgs, ...} : { name = "networking-proxy"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ ]; @@ -108,4 +108,4 @@ in import ./make-test.nix ({ pkgs, ...} : { $machine4->mustSucceed("su - alice -c 'env | grep -i ftp_proxy | grep 000'"); $machine4->mustSucceed("su - alice -c 'env | grep -i no_proxy | grep 131415'"); ''; -}) +} diff --git a/nixos/tests/networking.nix b/nixos/tests/networking.nix index 17d4a878d3a4f..aa402be2c77e1 100644 --- a/nixos/tests/networking.nix +++ b/nixos/tests/networking.nix @@ -1,6 +1,5 @@ -{ system ? builtins.currentSystem, networkd }: +{ pkgs, system ? builtins.currentSystem, networkd, ... }: -with import ../lib/testing.nix { inherit system; }; with pkgs.lib; let @@ -385,7 +384,7 @@ let }; }; -in mapAttrs (const (attrs: makeTest (attrs // { +in mapAttrs (const (attrs: (attrs // { name = "${attrs.name}-Networking-${if networkd then "Networkd" else "Scripted"}"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ wkennington ]; diff --git a/nixos/tests/nfs.nix b/nixos/tests/nfs.nix index 36cd6a3957791..f3e93cd794914 100644 --- a/nixos/tests/nfs.nix +++ b/nixos/tests/nfs.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, version ? 4, ... }: +{ pkgs, version ? 4, ... }: let @@ -86,4 +86,4 @@ in my $duration = time - $t1; die "shutdown took too long ($duration seconds)" if $duration > 30; ''; -}) +} diff --git a/nixos/tests/nsd.nix b/nixos/tests/nsd.nix index 0b1082056f6fc..c694afa544895 100644 --- a/nixos/tests/nsd.nix +++ b/nixos/tests/nsd.nix @@ -5,7 +5,7 @@ let # for a host utility with IPv6 support environment.systemPackages = [ pkgs.bind ]; }; -in import ./make-test.nix ({ pkgs, ...} : { +in { pkgs, ...} : { name = "nsd"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ aszlig ]; @@ -83,4 +83,4 @@ in import ./make-test.nix ({ pkgs, ...} : { }; } ''; -}) +} diff --git a/nixos/tests/partition.nix b/nixos/tests/partition.nix index 291d9b278d3b1..930b8e59105d8 100644 --- a/nixos/tests/partition.nix +++ b/nixos/tests/partition.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: +{ pkgs, ... }: with pkgs.lib; @@ -244,4 +244,4 @@ in { ensureMountPoint("/mnt/boot"); }; ''; -}) +} diff --git a/nixos/tests/phabricator.nix b/nixos/tests/phabricator.nix index 3bf83ab666553..67ada199adc07 100644 --- a/nixos/tests/phabricator.nix +++ b/nixos/tests/phabricator.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: { +{ pkgs, ... }: { name = "phabricator"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ chaoflow ]; @@ -74,4 +74,4 @@ import ./make-test.nix ({ pkgs, ... }: { $client->screenshot("screen"); ''; -}) +} diff --git a/nixos/tests/printing.nix b/nixos/tests/printing.nix index e44e5bf11d333..6cc40bc3a6926 100644 --- a/nixos/tests/printing.nix +++ b/nixos/tests/printing.nix @@ -1,6 +1,6 @@ # Test printing via CUPS. -import ./make-test.nix ({pkgs, ... }: { +{pkgs, ... }: { name = "printing"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ domenkozar eelco chaoflow jgeerds ]; @@ -96,4 +96,4 @@ import ./make-test.nix ({pkgs, ... }: { }; } ''; -}) +} diff --git a/nixos/tests/proxy.nix b/nixos/tests/proxy.nix index 3fee1d3253849..87986a5beae2c 100644 --- a/nixos/tests/proxy.nix +++ b/nixos/tests/proxy.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : +{ pkgs, ...} : let @@ -93,4 +93,4 @@ in $backend2->unblock; $client->succeed("curl --fail http://proxy/"); ''; -}) +} diff --git a/nixos/tests/quake3.nix b/nixos/tests/quake3.nix index 22d71595cb488..b3d492a8c2146 100644 --- a/nixos/tests/quake3.nix +++ b/nixos/tests/quake3.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : +{ pkgs, ...} : let @@ -92,4 +92,4 @@ rec { $server->stopJob("quake3-server"); ''; -}) +} diff --git a/nixos/tests/run-in-machine.nix b/nixos/tests/run-in-machine.nix index d1102f8d40731..6bfd1b641c2b4 100644 --- a/nixos/tests/run-in-machine.nix +++ b/nixos/tests/run-in-machine.nix @@ -1,6 +1,6 @@ -{ system ? builtins.currentSystem }: +{ pkgs, system ? builtins.currentSystem, ... }: -with import ../lib/testing.nix { inherit system; }; +with import { inherit system; }; runInMachine { drv = pkgs.hello; diff --git a/nixos/tests/simple.nix b/nixos/tests/simple.nix index 04d624adcfe97..8cb64624c82ab 100644 --- a/nixos/tests/simple.nix +++ b/nixos/tests/simple.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +{ pkgs, ...} : { name = "simple"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco ]; @@ -14,4 +14,4 @@ import ./make-test.nix ({ pkgs, ...} : { $machine->waitForUnit("multi-user.target"); $machine->shutdown; ''; -}) +} diff --git a/nixos/tests/subversion.nix b/nixos/tests/subversion.nix index a8e33a6f7e59c..2c84f8293099f 100644 --- a/nixos/tests/subversion.nix +++ b/nixos/tests/subversion.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : +{ pkgs, ... }: let @@ -118,4 +118,4 @@ in $webserver->stopJob("httpd"); ''; -}) +} diff --git a/nixos/tests/trac.nix b/nixos/tests/trac.nix index e7d9759ae0cc8..1e48d36714b1f 100644 --- a/nixos/tests/trac.nix +++ b/nixos/tests/trac.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: { +{ pkgs, ... }: { name = "trac"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco chaoflow ]; @@ -71,4 +71,4 @@ import ./make-test.nix ({ pkgs, ... }: { $client->screenshot("screen"); ''; -}) +} diff --git a/pkgs/tools/package-management/nix-run-test/default.nix b/pkgs/tools/package-management/nix-run-test/default.nix new file mode 100644 index 0000000000000..631656915b705 --- /dev/null +++ b/pkgs/tools/package-management/nix-run-test/default.nix @@ -0,0 +1,17 @@ +{ substituteAll, lib, nix }: + +substituteAll { + name = "nix-run-test"; + + dir = "bin"; + isExecutable = true; + + src = ./nix-run-test.sh; + + meta = { + description = "Tool to run nix tests"; + maintainers = [ lib.maintainers.ericsagnes ]; + license = lib.licenses.mit; + platforms = nix.meta.platforms; + }; +} diff --git a/pkgs/tools/package-management/nix-run-test/nix-run-test.sh b/pkgs/tools/package-management/nix-run-test/nix-run-test.sh new file mode 100644 index 0000000000000..382eec37f469d --- /dev/null +++ b/pkgs/tools/package-management/nix-run-test/nix-run-test.sh @@ -0,0 +1,54 @@ +#! @shell@ -e + +# Shows the usage of this command to the user + +display_usage() { + echo -e "Run a Nix test in a virtual machine.\nTests can be set to run interactively with the [-i|--interactive] flag." + echo -e "\nUsage:\nnix-run-test [-i|--interactive] TEST\n" + exit 0 +} + +# Parse valid argument options + +PARAMS=`getopt -n $0 -o i,h -l interactive,help -- "$@"` + +interactive="false" + +if [ $? != 0 ] +then + display_usage + exit 1 +fi + +eval set -- "$PARAMS" + +# Evaluate valid options + +while [ "$1" != "--" ] +do + case "$1" in + -i|--interactive) + interactive="true" + ;; + -h|--help) + display_usage + ;; + esac + + shift +done + +shift + +# Validate the given options + +if [ "$1" = "" ] +then + display_usage +else + testExpr=$(readlink -f $1) +fi + +# Run the test + +nix-build -E "with import {}; callTest $testExpr { interactive = $interactive; }" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e71475bbf2bf8..f1b11c03dbb32 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -16882,6 +16882,8 @@ in nix-prefetch-zip nix-prefetch-scripts; + nix-run-test = callPackage ../tools/package-management/nix-run-test { }; + nix-template-rpm = callPackage ../build-support/templaterpm { inherit (pythonPackages) python toposort; }; nix-repl = callPackage ../tools/package-management/nix-repl { };