# Host-side VM test: boots a NixOS host with services.hermenix enabled and # asserts the runtime plumbing the module sets up - the bridge, the tap, the # addresses, the nftables ruleset, the MAC clone, the on-bridge DHCP server, # and the host binary cache. The QEMU process is stubbed so no nested # virtualization is needed; the real QEMU command line is covered statically # by tests/network-modes-check.nix. # # Run by the operator/CI, never by an agent (see GUIDELINES.md): # nix build .#checks.x86_64-linux.host-vm -L { pkgs, self }: let hostNode = { lib, ... }: { imports = [ self.nixosModules.default ]; services.hermenix = { enable = true; network = { externalInterface = "eth1"; bridged = true; lanAddress = "10.7.7.50"; hostLanAddress = "10.7.7.2"; lanGateway = "10.7.7.1"; }; snapshots.enable = false; backup.enable = false; }; # The hermes-vm unit joins the kvm group; a bare test node has none # (libvirtd creates it on a real host). users.groups.kvm = { }; # eth0 = SLiRP (management); eth1 = the "uplink" vlan the module bridges. virtualisation.vlans = [ 1 ]; # Dummy images so hermes-vm's preStart passes, owned by the unit user so # it can drop OVMF_VARS.fd alongside them. systemd.tmpfiles.rules = [ "d /var/lib/hermes-vm 0750 hermes-vm hermes-vm" "d /var/lib/hermes-vm/system 0750 hermes-vm hermes-vm" "d /var/lib/hermes-vm/state 0750 hermes-vm hermes-vm" "f /var/lib/hermes-vm/system/system.raw 0600 hermes-vm hermes-vm -" "f /var/lib/hermes-vm/state/state.raw 0600 hermes-vm hermes-vm -" ]; # Stub QEMU: this test covers the host plumbing, not the guest. systemd.services.hermes-vm.serviceConfig.ExecStart = lib.mkForce "${pkgs.coreutils}/bin/sleep infinity"; }; in pkgs.testers.runNixOSTest { name = "hermenix-host"; globalTimeout = 600; # The module wraps pkgs.hermenix; a real host supplies it via an overlay. # runNixOSTest pins node.pkgs, so extend it here. node.pkgs = pkgs.lib.mkForce ( pkgs.extend (_final: prev: { hermenix = self.packages.${prev.system}.hermenix; }) ); nodes.host = hostNode; testScript = '' host.start() host.wait_for_unit("multi-user.target") for unit in [ "hermes-vm-tap.service", "hermes-vm.service", "hermes-bridge-mac.service", "hermes-lan-dhcp.service", ]: host.wait_for_unit(unit) # Bridge, tap, and the absorbed uplink. host.succeed("ip link show hermes-br") host.succeed("ip link show vm-hermes") host.succeed("bridge link show dev vm-hermes | grep -q hermes-br") host.succeed("bridge link show dev eth1 | grep -q hermes-br") # Service-net address plus the bridged host LAN address. host.succeed("ip -4 addr show hermes-br | grep -q '10.77.0.1/24'") host.succeed("ip -4 addr show hermes-br | grep -q '10.7.7.2/24'") # The bridge cloned the uplink MAC, so the host keeps its LAN identity. host.succeed( 'test "$(cat /sys/class/net/hermes-br/address)" = "$(cat /sys/class/net/eth1/address)"' ) # The bridged L2 table and the guest-mark rule are loaded. host.succeed("nft list ruleset | grep -q hermenix-bridge") host.succeed("nft list ruleset | grep -q 'meta mark set 18501'") # The host binary cache answers on the service net. host.wait_until_succeeds("${pkgs.curl}/bin/curl -fsS http://10.77.0.1:5000/nix-cache-info") ''; }