Create disk image files from NixOS + disko configuration.
This is done by running disko-create
, disko-mount
and thennixos-install
in a VM, where
each config.disko.devices.disk
is mounted as a qcow2 image.
It heavily relies on qcow2 as to not create too large image files. Compression is optional.
Add disko-images as a NixOS module (using flakes):
# flake.nix
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-22.11";
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
disko-images.url = "github:chrillefkr/disko-images";
};
outputs = { self, nixpkgs, disko, disko-images, ... } @inputs:
let
pkgs = import nixpkgs {
system = "x86_64-linux";
config.allowUnfree = true;
};
in
{
nixosConfigurations.my-machine = nixpkgs.lib.nixosSystem {
inherit pkgs;
specialArgs.inputs = inputs;
modules = [
./configuration.nix
./disko.nix
disko.nixosModules.disko
disko-images.nixosModules.disko-images
];
};
};
}
Build disko images using nix build '.#nixosConfigurations.my-machine.config.system.build.diskoImages'
.
Your disk image files appear at ./results/*.qcow2
.
First of all, this is a very simple (but working) way of creating disk images from NixOS + disko configuration. I've used it mainly to create Raspberry Pi SD card images.
Inspired by:
config.diskoImages.diskAllocSizes
)The Raspberry Pi 4 Linux kernel (pkgs.linuxPackages_rpi4
) (and problably kernels for the older boards) doesn't seem to work, as
the kernel seems to lack support for 9pnet_virtio. It gives me the error message 9pnet_virtio: no channels available for device <device>
when it attemts to mount the nix store.
A fix is to use official Linux kernel, e.g.:
boot.kernelPackages = pkgs.linuxPackages;
Please help. I'm quite new to Nix and NixOS, so any PR or issue is appreciated.