mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 13:03:28 +01:00
Closes #1283 When building `vmWithDisko` via `extendModules`, the outer `module.nix` is evaluated with `disko.enableConfig = true` (default), contributing `swapDevices = cfg.devices._config.swapDevices or [ ]`. At the same time, `lib/interactive-vm.nix` contributes `swapDevices = cfg_.disko.devices._config.swapDevices or [ ]` via `diskoBasedConfiguration`. Because `swapDevices` in NixOS is a `listOf submodule`, definitions are merged by concatenation. As a result, every swap partition in the disko config appears twice in the VM's generated `/etc/fstab`: ``` # Swap devices. /dev/mapper/dev-disk-byx2dpartlabel-diskx2dmainx2dencryptedSwap none swap defaults,pri=100 /dev/disk/by-partlabel/disk-main-plainSwap none swap defaults,discard /dev/mapper/dev-disk-byx2dpartlabel-diskx2dmainx2dencryptedSwap none swap defaults,pri=100 /dev/disk/by-partlabel/disk-main-plainSwap none swap defaults,discard ``` During boot, `systemd-fstab-generator` fails with exit status 1 because duplicate `.swap` unit files cannot be created. ### Fix Setting `disko.enableConfig = false;` in `lib/interactive-vm.nix` prevents `module.nix` from injecting the unmapped host disk configurations into the VM variant. `interactive-vm.nix`'s `diskoBasedConfiguration` already supplies the properly QEMU-mapped filesystem, boot, and swap configurations. ### Verification Evaluated on `example/swap.nix`: - **Before**: `vmSwapDevices` has 4 entries (2 pairs of identical devices). - **After**: `vmSwapDevices` has 2 unique entries. `fileSystems` and `vmWithDisko` script remain intact and functional. Added `tests/vm-with-disko-swap.nix` ensuring that `vmVariantWithDisko.swapDevices` has no duplicate devices. Checked with `nix build .#checks.x86_64-linux.vm-with-disko-swap` and verified `treefmt` formatting.