105 lines
4.8 KiB
Nix
105 lines
4.8 KiB
Nix
# Shared building blocks for the two guest-config VM tests in this
|
|
# directory: test_unbridge.nix and test_bridge.nix.
|
|
#
|
|
# The guest node's configuration and every assertion that must hold in both
|
|
# networking modes are defined here, once; each mode test imports this file,
|
|
# uses guestNode as its machine, and appends only the checks that apply to
|
|
# its mode (the isolated-bridge NAT setup vs. the DHCP-served LAN bridge).
|
|
#
|
|
# Both tests boot guest/common.nix — the same module set hermes-guest-image
|
|
# is built from — in an ephemeral, throwaway NixOS test VM. No real disk
|
|
# under /var/lib/hermes-vm/** is ever touched, and `hermenix setup` is never
|
|
# run. guest/hardware.nix (the real disk-label file) is intentionally not
|
|
# imported, same as hermes-guest-image's own build — nixos-generators and,
|
|
# here, the NixOS test framework both supply their own bootloader and root
|
|
# filesystem instead.
|
|
#
|
|
# Build with (never run by an agent, only by the operator/CI):
|
|
# nix build .#checks.x86_64-linux.guest-vm-unbridged --impure -L
|
|
# nix build .#checks.x86_64-linux.guest-vm-bridged --impure -L
|
|
#
|
|
# --impure is required because guest/common.nix reads /etc/hermenix/local.nix
|
|
# if present (see its own comment) — a pre-existing property of common.nix,
|
|
# not something the tests introduce.
|
|
{ determinate }:
|
|
|
|
{
|
|
# The guest node, exactly as both tests boot it.
|
|
guestNode =
|
|
{ lib, ... }:
|
|
{
|
|
imports = [
|
|
determinate.nixosModules.default
|
|
../common.nix
|
|
];
|
|
|
|
# A real, separate, auto-formatted virtual disk for the state dir —
|
|
# not tmpfs. tmpfs would not survive the in-test reboot below, which
|
|
# would make the idempotency check pass for the wrong reason (nothing
|
|
# to re-seed over, rather than correctly skipping re-seeding).
|
|
virtualisation.emptyDiskImages = [ 1024 ];
|
|
fileSystems."/var/lib/hermes" = lib.mkForce {
|
|
device = "/dev/vdb";
|
|
fsType = "ext4";
|
|
autoFormat = true;
|
|
neededForBoot = true;
|
|
};
|
|
|
|
# The test framework's default topology is not the real guest's: it
|
|
# adds a SLiRP user-mode NIC (10.0.2.0/24, with its own DHCP server)
|
|
# alongside the shared vlan, and the guest's networkd config matches
|
|
# any ethernet NIC. Strip the user-mode NIC and keep only the shared
|
|
# vlan (which udev names eth0) so the test machine has the production
|
|
# shape: one virtual NIC, and no stray DHCP server to confuse the
|
|
# mode-specific networking assertions.
|
|
virtualisation.qemu.networkingOptions = lib.mkForce [ ];
|
|
virtualisation.vlans = [ 1 ];
|
|
|
|
# nixosTest VMs have no route to the internet by design, so the real
|
|
# hermes-install body (a third-party curl | bash installer) can't run
|
|
# hermetically here. Stubbed to just flag itself done; the real
|
|
# installer flow stays an operator-run manual smoke test.
|
|
systemd.services.hermes-install.script = lib.mkForce ''
|
|
touch /var/lib/hermes/.hermes-installed
|
|
'';
|
|
};
|
|
|
|
# Assertions that hold in both modes: first-boot seeding, seeding
|
|
# idempotency across a reboot, the agent's account, and SSH.
|
|
commonScript = ''
|
|
# allow_reboot=True: without it, the VM starts with qemu's -no-reboot,
|
|
# so the guest-initiated machine.reboot() below would just kill the VM
|
|
# instead of restarting it, and the backdoor shell would never
|
|
# reconnect. Must happen before anything else touches `machine`, which
|
|
# would otherwise auto-start it with the (False) default first.
|
|
machine.start(allow_reboot=True)
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
# seedHermesState (guest/common.nix) ran on first boot.
|
|
machine.succeed("test -e /var/lib/hermes/.seeded")
|
|
machine.succeed("test -f /var/lib/hermes/.hermes/SOUL.md")
|
|
machine.succeed("test -d /var/lib/hermes/workspace")
|
|
machine.succeed("test -d /var/lib/hermes/nixos/.git")
|
|
machine.succeed("readlink /etc/nixos | grep -q '^/var/lib/hermes/nixos$'")
|
|
|
|
# The single most important invariant in guest/common.nix (per its own
|
|
# comments): seeding must never re-run over an already-seeded state
|
|
# disk, or every rebuild would quietly wipe the agent's own edits to
|
|
# SOUL.md, memories, etc.
|
|
machine.succeed("echo IDEMPOTENCY_MARKER >> /var/lib/hermes/.hermes/SOUL.md")
|
|
machine.reboot()
|
|
machine.wait_for_unit("multi-user.target")
|
|
machine.succeed("grep -q IDEMPOTENCY_MARKER /var/lib/hermes/.hermes/SOUL.md")
|
|
|
|
# The agent's account.
|
|
machine.succeed("id hermes")
|
|
machine.succeed("groups hermes | grep -q wheel")
|
|
machine.succeed("su - hermes -c 'sudo -n true'")
|
|
|
|
# SSH is up (checked over the test backdoor, so it is independent of
|
|
# whatever address configuration the mode under test produces).
|
|
machine.wait_for_unit("sshd.service")
|
|
machine.wait_for_open_port(22)
|
|
'';
|
|
}
|