96 lines
4.2 KiB
Nix
96 lines
4.2 KiB
Nix
# Guest-config tier VM test: boots guest/common.nix (the same module set
|
|
# used to build hermes-guest-image, see flake.nix) in an ephemeral,
|
|
# throwaway NixOS test VM, and checks seeding/services. This never touches
|
|
# a real disk under /var/lib/hermes-vm/** and never runs `hermenix setup`.
|
|
#
|
|
# guest/hardware.nix (the real disk-label file) is intentionally not
|
|
# imported here, 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 --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 introduced by this test.
|
|
{ pkgs, determinate }:
|
|
|
|
pkgs.testers.runNixOSTest {
|
|
name = "hermenix-guest-config";
|
|
|
|
nodes.machine =
|
|
{ lib, ... }:
|
|
{
|
|
imports = [
|
|
determinate.nixosModules.default
|
|
../guest/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 below 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;
|
|
};
|
|
|
|
# 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
|
|
'';
|
|
};
|
|
|
|
testScript = ''
|
|
# 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.
|
|
machine.wait_for_unit("sshd.service")
|
|
machine.wait_for_open_port(22)
|
|
|
|
# NOTE: not checking /etc/nix/nix.custom.conf's content here. `nix eval`
|
|
# on environment.etc."nix/nix.custom.conf".text confirms guest/common.nix
|
|
# itself renders the expected (no-host-cache) content, but the actual
|
|
# booted guest's copy of that file instead holds the NixOS test
|
|
# framework's own injected nix.settings (substituters = cache.nixos.org,
|
|
# trusted-users = root, system-features = nixos-test ...) — needed so
|
|
# nested Nix operations inside the test VM work at all. That's an
|
|
# artifact of running under nixosTest, not something guest/common.nix or
|
|
# this test controls, so it's not a reliable thing to assert on here.
|
|
'';
|
|
}
|