NixOS Generators: Azure & QEMU
Using nixos-generators to build images for Azure VM and QEMU
nixos-generators is a tool to build NixOS images for various platforms, including Azure and QEMU. This guide covers how to generate images for both.
Prerequisites
Nix installed with flakes enabled
nixos-generators installed (as a flake or via
nix run)
General Usage
You can use nixos-generators as a flake or with nix run:
nix run github:nix-community/nixos-generators -- --format <format> [options]Or with flakes:
nix build github:nix-community/nixos-generators#nixos-generate -- --format <format> [options]1. Generate a NixOS Image for Azure VM
Azure uses the VHD format. You can generate a VHD image as follows:
nix run github:nix-community/nixos-generators -- --format azure -c /etc/nixos/configuration.nixThe output will be a
.vhdfile, which you can upload to Azure as a managed disk or custom image.You can specify a custom configuration with
-cor use the default.
Uploading the VHD to Azure
2. Generate a NixOS Image for QEMU
QEMU uses the qcow2 format. To generate a QEMU image:
The output will be a
.qcow2file, which you can use directly with QEMU or other virtualization tools.
Running the Image with QEMU
Customizing the Configuration
You can pass a custom NixOS configuration file with the -c flag. For example:
References
Last updated