From 0e76632d2e0b365ec9509821ef46e355ce6eed93 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Thu, 17 Sep 2026 15:16:29 -0400 Subject: [PATCH] fixing vm issues --- .envrc | 1 + GUIDELINES.md | 6 ++--- README.md | 7 ++++- bin/runvmtest | 18 +++++++++++++ bin/runvmtest-debug | 20 ++++++++++++++ devenv.lock | 65 +++++++++++++++++++++++++++++++++++++++++++++ devenv.nix | 1 + guest/common.nix | 11 ++++++-- guest/vm-test.nix | 19 ++++++++++--- 9 files changed, 138 insertions(+), 10 deletions(-) create mode 100755 bin/runvmtest create mode 100755 bin/runvmtest-debug create mode 100644 devenv.lock diff --git a/.envrc b/.envrc index bed9d77..309182d 100644 --- a/.envrc +++ b/.envrc @@ -4,3 +4,4 @@ watch_file flake.lock # devenv needs impure eval (git metadata, DEVENV_ROOT, git-hooks install). use flake . --no-pure-eval +pre-commit install -f --hook-type pre-commit diff --git a/GUIDELINES.md b/GUIDELINES.md index cf5bb73..4658280 100644 --- a/GUIDELINES.md +++ b/GUIDELINES.md @@ -29,7 +29,7 @@ Only after the user approves the plan may you proceed with edits. **DO NOT RUN ANY OF THESE COMMANDS AT ANY TIME, FOR ANY REASON:** ``` -nix build +nix build # unless it's to test the vm via 'bin/runvmtest' nix flake check hermenix setup # unless the user is actively running it themselves with you watching hermenix migrate # same — it writes into a live guest @@ -95,9 +95,9 @@ These are always safe to perform without asking: - Reading any file in this repo - Editing `modules/host.nix` to add/adjust options (gated behind `mkIf - cfg.enable`, following the existing style) +cfg.enable`, following the existing style) - Editing `nu/hermenix.nu` — check any change by parsing it (`nu - nu/hermenix.nu --help` and `nu nu/hermenix.nu --help` parse +nu/hermenix.nu --help` and `nu nu/hermenix.nu --help` parse the whole file without running any subcommand body) before handing it back - Editing `guest/hermes/home` / `guest/hermes/workspace` template seed content (as long as it stays free of real secrets — see above) diff --git a/README.md b/README.md index 4872f3e..99aa592 100644 --- a/README.md +++ b/README.md @@ -869,7 +869,8 @@ 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: ```bash -nix build .#checks.x86_64-linux.guest-vm --impure -L +runvmtest # plain pass/fail (nix build .#checks.x86_64-linux.guest-vm --impure -L) +runvmtest-debug # build the interactive driver and drop into it (ptpython REPL) ``` Checks first-boot seeding (`~/.hermes`, `~/workspace`, the `/etc/nixos` @@ -878,3 +879,7 @@ the `.seeded` marker), the `hermes` user/sudo setup, and SSH. It deliberately does not cover the real `hermes-install` script (no internet route inside the test VM) or `modules/host.nix`'s own `hermes-vm` QEMU service — both stay manual, operator-run checks. + +`runvmtest-debug` gives you `start_all()`, `machine.wait_for_unit(...)`, and +`machine.shell_interact()` (a live shell inside the guest) to step through a +failure by hand instead of just getting pass/fail. diff --git a/bin/runvmtest b/bin/runvmtest new file mode 100755 index 0000000..5fa9b00 --- /dev/null +++ b/bin/runvmtest @@ -0,0 +1,18 @@ +#!/usr/bin/env nu +# +# runvmtest — build and run the guest-config VM test (guest/vm-test.nix). +# +# Plain pass/fail: the build fails if any testScript assertion fails. For +# stepping through it interactively instead, use runvmtest-debug. +# +# --impure is required because guest/common.nix reads +# /etc/hermenix/local.nix if present, same as the real hermes-guest-image +# build — a pre-existing property of common.nix, not something this test +# introduces. +# +# Not run for you automatically: this needs a real build, which agents in +# this repo don't run (see GUIDELINES.md). You (or CI) run this by hand. + +def main [] { + ^nix build ".#checks.x86_64-linux.guest-vm" --impure -L +} diff --git a/bin/runvmtest-debug b/bin/runvmtest-debug new file mode 100755 index 0000000..7d5a194 --- /dev/null +++ b/bin/runvmtest-debug @@ -0,0 +1,20 @@ +#!/usr/bin/env nu +# +# runvmtest-debug — build the guest-config VM test's interactive driver and +# drop into it, instead of just running it for pass/fail (see runvmtest). +# +# Opens a Python (ptpython) REPL with the test's node defined but not yet +# started. Useful from there: +# start_all() +# machine.wait_for_unit("multi-user.target") +# machine.shell_interact() # live shell inside the guest, over the console +# machine.succeed("...") # run any assertion from guest/vm-test.nix by hand +# +# Same --impure requirement as runvmtest, same reason (guest/common.nix +# reads /etc/hermenix/local.nix if present). Not run for you automatically +# — needs a real build, which agents in this repo don't run. + +def main [] { + ^nix build ".#checks.x86_64-linux.guest-vm.driverInteractive" --impure -L + ^./result/bin/nixos-test-driver +} diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 0000000..953257d --- /dev/null +++ b/devenv.lock @@ -0,0 +1,65 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1789480904, + "narHash": "sha256-anHWHTkxI7423/eUroN9Rc4+H8VIGyIUWq/hV1egBDQ=", + "owner": "cachix", + "repo": "devenv", + "rev": "0fd5e6d3a9b2ae6f10205a3e95e0ca58d526c5a6", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "nixpkgs": { + "inputs": { + "nixpkgs-src": "nixpkgs-src" + }, + "locked": { + "lastModified": 1789506231, + "narHash": "sha256-vNkJbtmqyBfFhn/HnzQo4ROuoyYWuy/allqTfJb4kMY=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "c2f38fe7f9e04d9aadd354d380f2bd40531d9737", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "nixpkgs-src": { + "flake": false, + "locked": { + "lastModified": 1789370336, + "narHash": "sha256-6RSEDHIWQtesQKWSu5qRai8L2h4KgCgMEfJHstW99G4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c7def046b9a883d46974757852106483d741586f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} \ No newline at end of file diff --git a/devenv.nix b/devenv.nix index 6ed2a96..fa290a4 100644 --- a/devenv.nix +++ b/devenv.nix @@ -21,6 +21,7 @@ in nixfmt deadnix statix + pre-commit ]; env.NU_LIB_DIRS = "${inputs.nutest}"; diff --git a/guest/common.nix b/guest/common.nix index b8571e6..5ceabf2 100644 --- a/guest/common.nix +++ b/guest/common.nix @@ -137,19 +137,26 @@ in cp -rTn ${./hermes/workspace} ${stateDir}/workspace chmod -R u+w ${stateDir}/nixos ${stateDir}/.hermes ${stateDir}/workspace - chown -R hermes:hermes ${stateDir}/nixos ${stateDir}/.hermes ${stateDir}/workspace # Git history here is the agent's cheapest undo, and it stops # nixos-rebuild complaining about an untracked flake. + # + # Must run before the chown below, while ${stateDir}/nixos is still + # root-owned: activation runs as root, and git refuses to operate on + # a repository whose working tree is owned by a different user + # ("detected dubious ownership") - it would otherwise fail here on + # every boot, silently (activation script failures are non-fatal), + # and the seed would never actually get committed. if [ ! -d ${stateDir}/nixos/.git ]; then ${pkgs.git}/bin/git -C ${stateDir}/nixos init -q -b main ${pkgs.git}/bin/git -C ${stateDir}/nixos add -A ${pkgs.git}/bin/git -C ${stateDir}/nixos \ -c user.name=seed -c user.email=seed@localhost \ commit -q -m "seed configuration from bootstrap image" - chown -R hermes:hermes ${stateDir}/nixos/.git fi + chown -R hermes:hermes ${stateDir}/nixos ${stateDir}/.hermes ${stateDir}/workspace + touch ${stateDir}/.seeded chown hermes:hermes ${stateDir}/.seeded fi diff --git a/guest/vm-test.nix b/guest/vm-test.nix index 07435c9..b1d051f 100644 --- a/guest/vm-test.nix +++ b/guest/vm-test.nix @@ -49,6 +49,12 @@ pkgs.testers.runNixOSTest { }; 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. @@ -76,9 +82,14 @@ pkgs.testers.runNixOSTest { machine.wait_for_unit("sshd.service") machine.wait_for_open_port(22) - # nix.custom.conf reflects the no-host-cache default (no local.nix in - # this hermetic build). - machine.succeed("grep -q cache.flakehub.com /etc/nix/nix.custom.conf") - machine.fail("grep -q 'http://10.77.0.1:5000' /etc/nix/nix.custom.conf") + # 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. ''; }