Skip to content

About

Re-use the NixOS VM test infrastructure to test Ubuntu, Debian, and Fedora machines.

Resources

Code of conduct

Contributing

Security policy

Stars

105 stars

Watchers

4 watching

Forks

Repository files navigation

nix-vm-test


Instant VMs to test your project

Fedora logo Debian logo Ubuntu logo Rocky Linux logo

Get Started Reference


README

Testing your project on different Linux distributions is essential, but time-consuming.

nix-vm-test allows you to quickly spin up a virtual machine running any of the following Linux distributions under Qemu:

  • Ubuntu
  • Debian
  • Fedora
  • Rocky
  • Arch Linux

And run your tests using a single CLI command.

Overview

This project builds on the NixOS VM test infrastructure to allow you to test your software instantly on Ubuntu, Debian, Fedora, Rocky, and Arch Linux virtual machines.

It runs on any Linux machine with Nix installed, and on Apple Silicon (aarch64) macOS with a Linux builder configured (see Prerequisites).

Your tests can either be used:

  • interactively, for development purposes.
  • noninteractively. This is perfect for CI, and you can use it as an integration test matrix on a wide variety of Linux distributions.

You configure nix-vm-test using Nix package manager, either in a flake or in a .nix configuration. This includes defining the parameters of the virtual machine you need for the test, and writing a Python script to define your tests. Once you've built the project, you can create the virtual machine and run your tests with a single CLI command.


Prerequisites

  • Nix Package Manager

  • Either:

    • Linux: any x86_64-linux or aarch64-linux machine, with hardware KVM acceleration (/dev/kvm). The project will run without it, but it will be too slow for practical purposes.
    • macOS: Apple Silicon (aarch64-darwin) running macOS 15 or later (the VMs are accelerated with Apple's Hypervisor.framework, accel=hvf), with a Linux builder — nix-darwin's linux-builder or a remote aarch64-linux build machine. This is required: the guest image is customized in a Linux derivation that is not available from any binary cache and therefore must be built. VMs run as aarch64-linux guests.

The guest image is customized offline inside a short-lived VM (nixpkgs' vmTools.runInLinuxVM), the same way on every host, so the machine that builds it needs the kvm Nix system feature. On Linux that is the default when /dev/kvm is available; without it the build falls back to (slow) emulation or is refused.


How to use nix-vm-test

The Get Started guide walks you through setting up and running a simple test scenario.

For more detailed information, see the Reference guide.


Status of the Project

Beta-grade

The API will be backward compatible. The project is already used in some production setups in the wild.

However, expect to experience some paper cuts along the way. Check out the bug tracker to see the currently unfixed known bugs and their workaround.

API Peek

let
  test = nix-vm-test.lib.ubuntu."23_04" {
    diskSize = "+2M"
    sharedDirs = {
      numtideShare = {
        source = "/home/numtide/share";
        target = "/mnt";
      };
    };
    testScript = ''
      vm.wait_for_unit("multi-user.target")
      vm.succeed("apt-get update")
    '';
    };
in test.sandboxed
}

This project is supported by Numtide. Untitledpng

We are a team of independent freelancers that love open source.  We help our customers make their project lifecycles more efficient by:

  • Providing and supporting useful tools such as this one
  • Building and deploying infrastructure, and offering dedicated DevOps support
  • Building their in-house Nix skills, and integrating Nix with their workflows
  • Developing additional features and tools
  • Carrying out custom research and development.

Contact us if you have a project in mind, or if you need help with any of our supported tools, including this one. We'd love to hear from you.

About

Re-use the NixOS VM test infrastructure to test Ubuntu, Debian, and Fedora machines.

Resources

Code of conduct

Contributing

Security policy

Stars

105 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages