runInLinuxVM
pkgs.vmTools.runInLinuxVM
Run a derivation in a Linux virtual machine (using Qemu/KVM). By default, there is no disk image; the root filesystem is a tmpfs, and the nix store is shared with the host (via the 9P protocol). Thus, any pure Nix derivation should run unmodified, e.g. the call
runInLinuxVM patchelf
will build the derivation patchelf' inside a VM. The attribute
preVM' can optionally contain a shell command to be evaluated
before the VM is started (i.e., on the host). The attribute
memSize' specifies the memory size of the VM in megabytes, defaulting to 512. The attribute
diskImage' can optionally
specify a file system image to be attached to /dev/sda. (Note
that currently we expect the image to contain a filesystem, not a
full disk image with a partition table etc.)
If the build fails and Nix is run with the -K' option, a script
run-vm' will be left behind in the temporary build directory
that allows you to boot into the VM and debug it interactively.
Inputs
drv
-
1. Function argument
Noogle detected
Implementation
The following is the current implementation of this function.
runInLinuxVM =
drv:
lib.overrideDerivation drv (
{
memSize ? 512,
QEMU_OPTS ? "",
args,
builder,
...
}:
{
requiredSystemFeatures = [ "kvm" ];
builder = "${bash}/bin/sh";
args = [
"-e"
(vmRunCommand qemuCommandLinux)
];
origArgs = args;
origBuilder = builder;
QEMU_OPTS = "${QEMU_OPTS} -m ${toString memSize} -object memory-backend-memfd,id=mem,size=${toString memSize}M,share=on -machine memory-backend=mem";
passAsFile = [ ]; # HACK fix - see https://github.com/NixOS/nixpkgs/issues/16742
}
);