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}"); + ''; +})