@@ -9,7 +9,6 @@
99 # Modules to add to each VM
1010, extraConfigurations ? [] }:
1111
12−with import ./build-vms.nix { inherit system pkgs minimal specialArgs extraConfigurations; };
1312with pkgs;
1413
1514rec {
@@ -51,9 +50,6 @@ rec {
5150 '';
5251 };
5352
54− testDriver = mkTestDriver qemu_test;
55− testDriverInteractive = mkTestDriver qemu_kvm;
56−
5753 # Run an automated test suite in the given virtual network.
5854 # `driver' is the script that runs the network.
5955 runTests = driver:
@@ -88,25 +84,7 @@ rec {
8884 maxTestNameLen = 50;
8985 testNameLen = builtins.stringLength name;
9086
91− testDriverName = with builtins;
92− if testNameLen > maxTestNameLen then
93− abort ("The name of the test '${name}' must not be longer than ${toString maxTestNameLen} " +
94− "it's currently ${toString testNameLen} characters long.")
95− else
96− "nixos-test-driver-${name}";
97−
98− nodes = buildVirtualNetwork (
99− t.nodes or (if t ? machine then { machine = t.machine; } else { }));
100−
101− testScript' =
102− # Call the test script with the computed nodes.
103− if lib.isFunction testScript
104− then testScript { inherit nodes; }
105− else testScript;
106−
107− vlans = map (m: m.config.virtualisation.vlans) (lib.attrValues nodes);
10887
109− vms = map (m: m.config.system.build.vm) (lib.attrValues nodes);
11088
11189 ocrProg = tesseract4.override { enableLanguages = [ "eng" ]; };
11290
@@ -115,8 +93,38 @@ rec {
11593 # Generate convenience wrappers for running the test driver
11694 # interactively with the specified network, and for starting the
11795 # VMs from the command line.
118− driver = testDriver:
119− let
96+ mkDriver = qemu_pkg:
97+ let
98+ build-vms = import ./build-vms.nix {
99+ inherit system pkgs minimal specialArgs;
100+ extraConfigurations = extraConfigurations ++ (pkgs.lib.optional (qemu_pkg != null)
101+ {
102+ virtualisation.qemu.package = qemu_pkg;
103+ }
104+ );
105+ };
106+
107+ # FIXME: get this pkg from the module system
108+ testDriver = mkTestDriver (if qemu_pkg == null then pkgs.qemu_test else qemu_pkg);
109+
110+ nodes = build-vms.buildVirtualNetwork (
111+ t.nodes or (if t ? machine then { machine = t.machine; } else { }));
112+ vlans = map (m: m.config.virtualisation.vlans) (lib.attrValues nodes);
113+ vms = map (m: m.config.system.build.vm) (lib.attrValues nodes);
114+
115+ testScript' =
116+ # Call the test script with the computed nodes.
117+ if lib.isFunction testScript
118+ then testScript { inherit nodes; }
119+ else testScript;
120+
121+ testDriverName = with builtins;
122+ if testNameLen > maxTestNameLen then
123+ abort ("The name of the test '${name}' must not be longer than ${toString maxTestNameLen} " +
124+ "it's currently ${toString testNameLen} characters long.")
125+ else
126+ "nixos-test-driver-${name}";
127+
120128 warn = if skipLint then lib.warn "Linting is disabled!" else lib.id;
121129 in
122130 warn (runCommand testDriverName
@@ -124,6 +132,9 @@ rec {
124132 testScript = testScript';
125133 preferLocalBuild = true;
126134 testName = name;
135+ passthru = {
136+ inherit nodes;
137+ };
127138 }
128139 ''
129140 mkdir -p $out/bin
@@ -154,9 +165,12 @@ rec {
154165 meta = (drv.meta or {}) // t.meta;
155166 };
156167
157− test = passMeta (runTests (driver testDriver));
168+ driver = mkDriver null;
169+ driverInteractive = mkDriver pkgs.qemu;
170+
171+ test = passMeta (runTests driver);
158172
159− nodeNames = builtins.attrNames nodes;
173+ nodeNames = builtins.attrNames driver.nodes;
160174 invalidNodeNames = lib.filter
161175 (node: builtins.match "^[A-z_]([A-z0-9_]+)?$" node == null) nodeNames;
162176
@@ -170,10 +184,9 @@ rec {
170184 Please stick to alphanumeric chars and underscores as separation.
171185 ''
172186 else
173− test // {
174− inherit nodes test;
175− driver = driver testDriver;
176− driverInteractive = driver testDriverInteractive;
187+ test // {
188+ inherit test driver driverInteractive;
189+ inherit (test) nodes;
177190 };
178191
179192 runInMachine =
@@ -184,7 +197,11 @@ rec {
184197 , ... # ???
185198 }:
186199 let
187− vm = buildVM { }
200+ build-vms = import ./build-vms.nix {
201+ inherit system pkgs minimal specialArgs extraConfigurations;
202+ };
203+
204+ vm = build-vms.buildVM { }
188205 [ machine
189206 { key = "run-in-machine";
190207 networking.hostName = "client";