aboutsummaryrefslogtreecommitdiffstats
path: root/tests/qemu/default.nix
blob: 29ff0935188750b791be0b33b28e54ce0d55e961 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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-rig --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-rig (builtins.removeAttrs args [ "script" "layers" ] // {
  pkgs = pkgs.extend (_: _: { inherit firecracker; });
  layers = layers ++ [ (import ./debug.nix script) ];
})