Create disk image files from NixOS + disko configuration.
Go to file
Christopher Janzon 49f16bf330 Cleanup & zfs trim
2023-12-29 16:34:03 +01:00
create-disko-images-in-vm.nix Cleanup & zfs trim 2023-12-29 16:34:03 +01:00
disko-images.nix BREAKING CHANGES: changing output to system.build.diskoPartImages, as to not conflict with new builtin image output from Disko 2023-12-29 16:33:33 +01:00
flake.lock initial commit 2023-05-19 00:05:54 +02:00
flake.nix initial commit 2023-05-19 00:05:54 +02:00
README.md update disko-images url 2023-05-19 00:09:50 +02:00

Disko Images

Create disk image files from NixOS + disko configuration.

This is done by running disko-create, disko-mountand 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.

Usage

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.

About

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:

TODO

  • Ensure support for
    • zfs
    • btrfs
    • lvm
  • Individual disk size (config.diskoImages.diskAllocSizes)
  • Create tests
  • Create examples

Known issues

Raspberry Pi Linux kernel

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;

Contribution

Please help. I'm quite new to Nix and NixOS, so any PR or issue is appreciated.