mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 13:03:28 +01:00
interactive-vm: disable disko.enableConfig to avoid duplicate swapDevices (#1300)
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.
This commit is contained in:
2 files changed
+22
No files matched your search
@@ -55,6 +55,7 @@ in
|
||||
diskoBasedConfiguration
|
||||
];
|
||||
|
||||
disko.enableConfig = false;
|
||||
disko.testMode = true;
|
||||
|
||||
disko.imageBuilder.copyNixStore = false;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# vmWithDisko must not duplicate swapDevices generated from the disko config.
|
||||
# Regression test for https://github.com/nix-community/disko/issues/1283
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
...
|
||||
}:
|
||||
let
|
||||
lib = pkgs.lib;
|
||||
system = pkgs.nixos [
|
||||
../module.nix
|
||||
../example/swap.nix
|
||||
{
|
||||
documentation.enable = false;
|
||||
system.stateVersion = "26.11";
|
||||
}
|
||||
];
|
||||
vmSwap = system.config.virtualisation.vmVariantWithDisko.swapDevices;
|
||||
uniqueSwapDevices = lib.unique (map (s: s.device) vmSwap);
|
||||
in
|
||||
assert (builtins.length vmSwap == builtins.length uniqueSwapDevices);
|
||||
pkgs.runCommand "test-vm-with-disko-swap" { } "touch $out"
|
||||
Reference in new issue
Block a user