diff options
author | Chuck <chuck@intelligence.org> | 2020-01-28 15:08:56 -0800 |
---|---|---|
committer | Niklas Hambüchen <mail@nh2.me> | 2020-07-04 14:40:42 +0200 |
commit | e74755c422180bfa0ca2f74eb11f32e20d4030ee (patch) | |
tree | 7907a199d952904c85c9bab30a250846b39345b5 /nixos/modules/virtualisation/qemu-vm.nix | |
parent | a5e211dd7f95167ab42066e82bfaa5a65971e67c (diff) | |
download | nixpkgs-e74755c422180bfa0ca2f74eb11f32e20d4030ee.tar nixpkgs-e74755c422180bfa0ca2f74eb11f32e20d4030ee.tar.gz nixpkgs-e74755c422180bfa0ca2f74eb11f32e20d4030ee.tar.bz2 nixpkgs-e74755c422180bfa0ca2f74eb11f32e20d4030ee.tar.lz nixpkgs-e74755c422180bfa0ca2f74eb11f32e20d4030ee.tar.xz nixpkgs-e74755c422180bfa0ca2f74eb11f32e20d4030ee.tar.zst nixpkgs-e74755c422180bfa0ca2f74eb11f32e20d4030ee.zip |
nixos/qemu-vm: Don't assume boot drive is always vdb
Diffstat (limited to 'nixos/modules/virtualisation/qemu-vm.nix')
-rw-r--r-- | nixos/modules/virtualisation/qemu-vm.nix | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index 7507db40578..5a502c36180 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -46,6 +46,13 @@ let description = "Extra options passed to device flag."; }; + name = mkOption { + type = types.nullOr types.str; + default = null; + description = + "A name for the drive. Must be unique in the drives list. Not passed to qemu."; + }; + }; }; @@ -84,6 +91,14 @@ let else "/dev/vd${letter}"; + lookupDriveDeviceName = driveName: driveList: + (findSingle (drive: drive.name == driveName) + (throw "Drive ${driveName} not found") + (throw "Multiple drives named ${driveName}") driveList).device; + + addDeviceNames = + imap1 (idx: drive: drive // { device = driveDeviceName idx; }); + # Shell script to start the VM. startVM = '' @@ -406,6 +421,7 @@ in mkOption { type = types.listOf (types.submodule driveOpts); description = "Drives passed to qemu."; + apply = addDeviceNames; }; diskInterface = @@ -552,12 +568,14 @@ in virtualisation.qemu.drives = mkMerge [ [{ + name = "root"; file = "$NIX_DISK_IMAGE"; driveExtraOpts.cache = "writeback"; driveExtraOpts.werror = "report"; }] (mkIf cfg.useBootLoader [ { + name = "boot"; file = "$TMPDIR/disk.img"; driveExtraOpts.media = "disk"; deviceExtraOpts.bootindex = "1"; @@ -610,7 +628,7 @@ in }; } // optionalAttrs cfg.useBootLoader { "/boot" = - { device = "${driveDeviceName 1}2"; + { device = "${lookupDriveDeviceName "boot" cfg.qemu.drives}2"; fsType = "vfat"; options = [ "ro" ]; noCheck = true; # fsck fails on a r/o filesystem |