about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorChristian Kögler <ck3d@gmx.de>2019-08-22 22:45:20 +0200
committerFranz Pletz <fpletz@fnordicwalking.de>2019-09-13 17:33:11 +0200
commit65792923afe7b48708b59c57c380c0e35cb836af (patch)
tree65286957dbb8d4b8e809c5a3f85c431c4fbf7bb9 /nixos
parent28853d8954199bc7944797c260d8116a68da2b46 (diff)
downloadnixlib-65792923afe7b48708b59c57c380c0e35cb836af.tar
nixlib-65792923afe7b48708b59c57c380c0e35cb836af.tar.gz
nixlib-65792923afe7b48708b59c57c380c0e35cb836af.tar.bz2
nixlib-65792923afe7b48708b59c57c380c0e35cb836af.tar.lz
nixlib-65792923afe7b48708b59c57c380c0e35cb836af.tar.xz
nixlib-65792923afe7b48708b59c57c380c0e35cb836af.tar.zst
nixlib-65792923afe7b48708b59c57c380c0e35cb836af.zip
nixos: added machinectl test
Diffstat (limited to 'nixos')
-rw-r--r--nixos/tests/all-tests.nix1
-rwxr-xr-xnixos/tests/nixos-install-simple19
-rw-r--r--nixos/tests/systemd-machinectl.nix49
3 files changed, 69 insertions, 0 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index 60762de76d33..86aafd02685b 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -260,6 +260,7 @@ in
   syncthing-relay = handleTest ./syncthing-relay.nix {};
   systemd = handleTest ./systemd.nix {};
   systemd-confinement = handleTest ./systemd-confinement.nix {};
+  systemd-machinectl = handleTest ./systemd-machinectl.nix {};
   systemd-timesyncd = handleTest ./systemd-timesyncd.nix {};
   systemd-networkd-wireguard = handleTest ./systemd-networkd-wireguard.nix {};
   pdns-recursor = handleTest ./pdns-recursor.nix {};
diff --git a/nixos/tests/nixos-install-simple b/nixos/tests/nixos-install-simple
new file mode 100755
index 000000000000..c6044eeffb15
--- /dev/null
+++ b/nixos/tests/nixos-install-simple
@@ -0,0 +1,19 @@
+#!/bin/sh -eux
+
+mkdir -p "$1"
+
+ROOT="$(readlink -f $1)"
+SYSTEM="$(readlink -f ${2:-./result})"
+
+# create root folders
+mkdir -p "$ROOT/etc" "$ROOT/boot"
+
+# install NixOS
+nix-env --store "$ROOT" \
+  --extra-substituters "auto?trusted=1" \
+  -p "$ROOT/nix/var/nix/profiles/system" --set "$SYSTEM"
+
+# activate NixOS
+touch "$ROOT/etc/NIXOS"
+nixos-enter --root "$ROOT" \
+  -- /run/current-system/bin/switch-to-configuration boot
diff --git a/nixos/tests/systemd-machinectl.nix b/nixos/tests/systemd-machinectl.nix
new file mode 100644
index 000000000000..f28941bca5ae
--- /dev/null
+++ b/nixos/tests/systemd-machinectl.nix
@@ -0,0 +1,49 @@
+import ./make-test.nix (let
+
+  container = { ... }: {
+    boot.isContainer = true;
+
+    # use networkd to obtain systemd network setup
+    networking.useNetworkd = true;
+
+    # systemd-nspawn expects /sbin/init
+    boot.loader.initScript.enable = true;
+
+    imports = [ ../modules/profiles/minimal.nix ];
+  };
+
+  containerSystem = (import ../lib/eval-config.nix {
+    modules = [ container ];
+  }).config.system.build.toplevel;
+
+  containerName = "container";
+
+in {
+  name = "systemd-machinectl";
+
+  machine = { lib, ... }: {
+    # use networkd to obtain systemd network setup
+    networking.useNetworkd = true;
+
+    # open DHCP server on interface to container
+    networking.firewall.trustedInterfaces = [ "ve-+" ];
+
+    # do not try to access cache.nixos.org
+    nix.binaryCaches = lib.mkForce [];
+
+    virtualisation.pathsInNixDB = [ containerSystem ];
+  };
+
+  testScript = ''
+    startAll;
+
+    $machine->waitForUnit("default.target");
+    $machine->succeed("mkdir -p ${containerRoot}");
+    $machine->succeed("${./nixos-install-simple} /var/lib/machines/${containerName} ${containerSystem}");
+
+    $machine->succeed("machinectl start ${containerName}");
+    $machine->waitUntilSucceeds("systemctl -M ${containerName} is-active default.target");
+    $machine->succeed("ping -n -c 1 ${containerName}");
+    $machine->succeed("machinectl stop ${containerName}");
+  '';
+})