From 45e5685372c2c5cdb2329fcd5a486c681910d046 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Mon, 16 Nov 2026 16:37:32 +0100 Subject: [PATCH] feat(runner): forward microvm-run command-line arguments to the VMM Forward positional arguments in microvm-run to the VMM/hypervisor to allow passing extra options with `nix run .#my-microvm -- `. This makes it possible to reuse the same runner/Nix derivation with additional runtime options, without having to edit and reevaluate the Nix configuration for each set of options. This can be used (for example) to: - Dynamically attach optional disks/devices with dynamic paths/IDs - Capture network traffic - Enable QEMU's GDB server (-s -S) for early boot debugging microvm.extraArgsScript can also supply runtime arguments, but the script must be configured in advance and supply the arguments at runtime. CLI forwarding lets callers pass arguments directly. When both are used, CLI arguments come last. The host module invokes microvm-run without arguments, so its behavior is unchanged. --- CHANGELOG.md | 4 ++++ doc/src/packages.md | 6 ++++++ lib/runner.nix | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba3e4cae..0119ba34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased: `main` branch +* Runner scripts now forward command-line arguments to the hypervisor, + allowing extra VMM options for a single invocation with + `nix run .#my-microvm -- `. + * Shell scripts to setup virtiofsd, interfaces, and PCI devices for pass-through have moved from systemd units in the host to the `bin/` subdirectory of MicroVM packages. That means you can actually use diff --git a/doc/src/packages.md b/doc/src/packages.md index 3c3be27b..3e3b472a 100644 --- a/doc/src/packages.md +++ b/doc/src/packages.md @@ -23,3 +23,9 @@ packages.x86_64-linux.my-microvm = self.nixosConfigurations.my-microvm.config.mi ``` You can then run the MicroVM with a simple `nix run .#my-microvm` + +## Pass extra hypervisor arguments + +Use `nix run .#my-microvm -- ` to pass extra arguments to the +hypervisor for a single run. The runner appends them after the configured +hypervisor arguments and any arguments from `microvm.extraArgsScript`. diff --git a/lib/runner.nix b/lib/runner.nix index 73329533..a8623038 100644 --- a/lib/runner.nix +++ b/lib/runner.nix @@ -182,7 +182,7 @@ let '' } - exec ${execArg} ${command} ''${runtime_args:-} + exec ${execArg} ${command} ''${runtime_args:-} "$@" ''; } // lib.optionalAttrs canShutdown {