A nixos/tests/default.nix => nixos/tests/default.nix +38 -0
@@ 0,0 1,38 @@
+{self, ...}: {
+ perSystem = {pkgs, ...}: {
+ checks.router = pkgs.stdenv.mkDerivation {
+ name = "router";
+ phases = [
+ "runPhase"
+ ];
+
+ env.ROUTER_CMD =
+ (self.nixosConfigurations.liveusb.extendModules {
+ modules = [
+ "${pkgs.path}/nixos/modules/testing/test-instrumentation.nix"
+ ];
+ })
+ .config
+ .system
+ .build
+ .vm;
+
+ nativeBuildInputs = with pkgs; [
+ iproute2
+ (python3.withPackages (ps:
+ with ps; [
+ ptpython
+ colorama
+ junit-xml
+ ]))
+ ];
+
+ runPhase = ''
+ PYTHONPATH=${pkgs.path}/nixos/lib/test-driver python ${./router.py}
+
+ mkdir -p $out
+ touch $out/success
+ '';
+ };
+ };
+}
A nixos/tests/router.py => nixos/tests/router.py +21 -0
@@ 0,0 1,21 @@
+from test_driver.machine import Machine, StartCommand, NixStartScript
+from test_driver.logger import TerminalLogger
+from pathlib import Path
+import os
+
+
+def make_machine(out_dir: Path, tmp_dir: Path) -> Machine:
+ out_dir.mkdir(parents=True, exist_ok=True)
+ tmp_dir.mkdir(parents=True, exist_ok=True)
+ return Machine(
+ out_dir = out_dir.absolute(),
+ tmp_dir = tmp_dir.absolute(),
+ start_command = NixStartScript(os.getenv("ROUTER_CMD") + "/bin/run-nixos-vm"),
+ logger = TerminalLogger(),
+ name = "router",
+ )
+
+router = make_machine(Path("router/out"), Path("router/tmp"))
+router.start()
+router.wait_for_unit("multi-user.target")
+router.shutdown()