Skip to content

feat: add vm-headless app to run the VM detached in the background#6

Merged
gotha merged 1 commit into
mainfrom
feat/vm-headless
Jun 28, 2026
Merged

feat: add vm-headless app to run the VM detached in the background#6
gotha merged 1 commit into
mainfrom
feat/vm-headless

Conversation

@gotha

@gotha gotha commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a vm-headless flake app so the VM can be started detached in the background, printing the SSH port to connect to instead of attaching a console to your terminal.

  • nix run .#vm — unchanged (foreground; serial console attached to your terminal).
  • nix run .#vm-headlessnew; daemonizes QEMU and prints the SSH command, then returns control to your shell.
  • nix run .#vm-gui — unchanged (graphical window).

How it works

  • lib/mk-vm-runner.nix gains a background runner that launches QEMU with -daemonize -display none -monitor none, captures the serial console to /tmp/<vm>-console.log, and writes a pidfile to /tmp/<vm>.pid for easy stopping.
  • lib/mk-vm-apps.nix exposes it as the vm-headless app.
  • The SSH port is chosen the same way as the existing runners (random 20000–30000, also saved to /tmp/<vm>-ssh-port).

Example output:

VM 'dev-vm' started in background.

  SSH:         ssh dev@localhost -p 24817
  Port file:   /tmp/dev-vm-ssh-port
  Console log: /tmp/dev-vm-console.log
  Stop:        kill $(cat /tmp/dev-vm.pid)

Notes

Test plan

  • nix eval .#apps.x86_64-linux lists default, vm, vm-gui, vm-headless.
  • Rendered runner shell passes bash -n.
  • nix run .#vm-headless boots a VM detached and ssh dev@localhost -p <port> connects.
  • nix run .#vm still attaches to the terminal as before.

🤖 Generated with Claude Code

`nix run .#vm` keeps its current foreground behavior (serial console
attached to the terminal). The new `nix run .#vm-headless` starts the VM
fully detached and prints the SSH port to connect to, then returns control
to the shell.

- lib/mk-vm-runner.nix: new `background` runner that launches QEMU with
  `-daemonize -display none -monitor none`, captures the serial console to
  /tmp/<vm>-console.log, writes a pidfile, and prints the SSH command
- lib/mk-vm-apps.nix: expose the runner as the `vm-headless` app
- README: document the foreground / background / GUI run modes
@gotha gotha force-pushed the feat/vm-headless branch from 0b09266 to 04db654 Compare June 28, 2026 14:45
@gotha gotha marked this pull request as ready for review June 28, 2026 17:41
@gotha gotha merged commit e4e3b32 into main Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant