diff options
| author | tv <tv@krebsco.de> | 2026-11-21 16:17:35 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-25 22:53:22 +0100 |
| commit | 595f6e3f69702aa50f17d37eb49d9050257307a0 (patch) | |
| tree | fdd2a8ffe357e7dd425a564193c024d7abb089ec /tests/qemu/default.nix | |
| parent | fe46f7703e6145af9d3c9eb43d6ded19b316c83c (diff) | |
tests: the run script in qemu, and a NixOS VM test of modules/host
Both were only in the sandbox the project was developed in so far.
tests/qemu builds the run script with a qemu stand-in for Firecracker
(same kernel, initrd, drives, vsock via vhost-device-vsock; network via
qemu's user networking, the guest's port 22 on 127.0.0.1:2222) and a
test layer running a script at the end of boot, its output on the
console. The run script still takes a tap, so it needs modules/host
where it runs.
tests/vm-host.nix is a NixOS VM test of modules/host, with network
namespaces on veths in place of taps as guests: a VM's static address
by name, tcp:// rules over IPv4 and IPv6 and by name, DNS, anti-spoofing,
POST /check, the path units and the timer.
Diffstat (limited to 'tests/qemu/default.nix')
| -rw-r--r-- | tests/qemu/default.nix | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/qemu/default.nix b/tests/qemu/default.nix new file mode 100644 index 0000000..82c7de6 --- /dev/null +++ b/tests/qemu/default.nix @@ -0,0 +1,25 @@ +# The run script with a qemu stand-in for Firecracker (firecracker.sh), +# for testing without Firecracker (fast with /dev/kvm, else under TCG). +# +# nix-build tests/qemu --argstr script 'echo TEST $(nproc); systemctl poweroff' +# ./result/bin/run-firecracker-vm --secret ssh_host_ed25519_key=KEY [OPTION...] | tee log +# +# script: a shell script run as root at the end of boot (see debug.nix); +# end it with `systemctl poweroff` for the guest to exit, or leave it out +# to log in via ssh (127.0.0.1:2222; authorize a key with another layer). +# layers: further layers, below the test's (e.g. [ ../../layers/nix.nix ], +# which needs --store). +# The run script still takes a tap, so this needs modules/host on the +# machine it runs on, and a free tap of the user's; qemu doesn't use it. +{ pkgs ? import <nixpkgs> {}, layers ? [ ], script ? "", ... }@args: +let + firecracker = pkgs.writeShellApplication { + name = "firecracker"; + runtimeInputs = [ pkgs.jq pkgs.gnused pkgs.qemu_kvm pkgs.vhost-device-vsock ]; + text = builtins.readFile ./firecracker.sh; + }; +in +import ../../pkgs/run-firecracker-vm (builtins.removeAttrs args [ "script" "layers" ] // { + pkgs = pkgs.extend (_: _: { inherit firecracker; }); + layers = layers ++ [ (import ./debug.nix script) ]; +}) |
