Home Explore Blog Models CI



nixpkgs

2nd chunk of `doc/build-helpers/special/vm-tools.section.md`
71ae88a9f94c2c8b1d5b57c0d744214675fda880a559dcac0000000100000df5
Build the derivation hello inside a VM:
```nix
{ pkgs }: with pkgs; with vmTools; runInLinuxVM hello
```

Build inside a VM with extra memory:
```nix
{ pkgs }:
with pkgs;
with vmTools;
runInLinuxVM (
  hello.overrideAttrs (_: {
    memSize = 1024;
  })
)
```

Use VM with a disk image (implicitly sets `diskImage`, see [`vmTools.createEmptyImage`](#vm-tools-createEmptyImage)):
```nix
{ pkgs }:
with pkgs;
with vmTools;
runInLinuxVM (
  hello.overrideAttrs (_: {
    preVM = createEmptyImage {
      size = 1024;
      fullName = "vm-image";
    };
  })
)
```

## `vmTools.extractFs` {#vm-tools-extractFs}

Takes a file, such as an ISO, and extracts its contents into the store.

### Attributes {#vm-tools-extractFs-attributes}

* `file`. Path to the file to be extracted.
  Note that currently we expect the image to contain a filesystem, not a full disk image with a partition table etc.
* `fs` (optional). Filesystem of the contents of the file.

### Examples {#vm-tools-extractFs-examples}

Extract the contents of an ISO file:
```nix
{ pkgs }: with pkgs; with vmTools; extractFs { file = ./image.iso; }
```

## `vmTools.extractMTDfs` {#vm-tools-extractMTDfs}

Like [](#vm-tools-extractFs), but it makes use of a [Memory Technology Device (MTD)](https://en.wikipedia.org/wiki/Memory_Technology_Device).

## `vmTools.runInLinuxImage` {#vm-tools-runInLinuxImage}

Like [](#vm-tools-runInLinuxVM), but instead of using `stdenv` from the Nix store, run the build using the tools provided by `/bin`, `/usr/bin`, etc. from the specified filesystem image, which typically is a filesystem containing a [FHS](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard)-based Linux distribution.

## `vmTools.makeImageTestScript` {#vm-tools-makeImageTestScript}

Generate a script that can be used to run an interactive session in the given image.

### Examples {#vm-tools-makeImageTestScript-examples}

Create a script for running a Fedora 27 VM:
```nix
{ pkgs }: with pkgs; with vmTools; makeImageTestScript diskImages.fedora27x86_64
```

Create a script for running an Ubuntu 20.04 VM:
```nix
{ pkgs }: with pkgs; with vmTools; makeImageTestScript diskImages.ubuntu2004x86_64
```

## `vmTools.diskImageFuns` {#vm-tools-diskImageFuns}

A set of functions that build a predefined set of minimal Linux distributions images.

### Images {#vm-tools-diskImageFuns-images}

* Fedora
  * `fedora26x86_64`
  * `fedora27x86_64`
* CentOS
  * `centos6i386`
  * `centos6x86_64`
  * `centos7x86_64`
* Ubuntu
  * `ubuntu1404i386`
  * `ubuntu1404x86_64`
  * `ubuntu1604i386`
  * `ubuntu1604x86_64`
  * `ubuntu1804i386`
  * `ubuntu1804x86_64`
  * `ubuntu2004i386`
  * `ubuntu2004x86_64`
  * `ubuntu2204i386`
  * `ubuntu2204x86_64`
* Debian
  * `debian10i386`
  * `debian10x86_64`
  * `debian11i386`
  * `debian11x86_64`
  * `debian12i386`
  * `debian12x86_64`

### Attributes {#vm-tools-diskImageFuns-attributes}

* `size` (optional, defaults to `4096`). The size of the image, in MiB.
* `extraPackages` (optional). A list names of additional packages from the distribution that should be included in the image.

### Examples {#vm-tools-diskImageFuns-examples}

8GiB image containing Firefox in addition to the default packages:
```nix
{ pkgs }:
with pkgs;
with vmTools;
diskImageFuns.ubuntu2004x86_64 {
  extraPackages = [ "firefox" ];
  size = 8192;
}
```

## `vmTools.diskImageExtraFuns` {#vm-tools-diskImageExtraFuns}

Shorthand for `vmTools.diskImageFuns.<attr> { extraPackages = ... }`.

## `vmTools.diskImages` {#vm-tools-diskImages}

Shorthand for `vmTools.diskImageFuns.<attr> { }`.

Title: vmTools: Image Extraction, VM Execution, and Predefined Linux Images
Summary
This section of the `vmTools` documentation expands on utilities for virtual machine and disk image management. It details `vmTools.extractFs` for extracting filesystem contents from files like ISOs, and `vmTools.extractMTDfs` for Memory Technology Devices. `vmTools.runInLinuxImage` is introduced as an alternative to `runInLinuxVM`, executing builds within a specified FHS-based Linux filesystem image. `vmTools.makeImageTestScript` generates interactive session scripts for given images, exemplified with Fedora and Ubuntu. Finally, `vmTools.diskImageFuns` is presented as a collection of functions for building predefined minimal Linux distribution images (Fedora, CentOS, Ubuntu, Debian), allowing customization of image size and inclusion of extra packages. Shorthands `vmTools.diskImageExtraFuns` and `vmTools.diskImages` are also provided for convenience.