nixos/vms: Make drives a list (for ordering)

This commit is contained in:
Jack O'Sullivan 2022-06-18 03:06:01 +01:00
parent 6971048268
commit 128accbade
2 changed files with 41 additions and 48 deletions

View File

@ -13,33 +13,31 @@
if config.my.build.isDevVM then "00:02.0" else "27:00.0"; if config.my.build.isDevVM then "00:02.0" else "27:00.0";
vmLVM = vm: lv: { vmLVM = vm: lv: {
"${lv}" = { name = lv;
backend = { backend = {
driver = "host_device"; driver = "host_device";
filename = "/dev/ssds/vm-${vm}-${lv}"; filename = "/dev/ssds/vm-${vm}-${lv}";
# It appears this needs to be set on the backend _and_ the format # It appears this needs to be set on the backend _and_ the format
discard = "unmap"; discard = "unmap";
};
format = {
driver = "raw";
discard = "unmap";
};
frontend = "virtio-blk";
}; };
format = {
driver = "raw";
discard = "unmap";
};
frontend = "virtio-blk";
}; };
installerDisk = { installerDisk = {
installer = { name = "installer";
backend = { backend = {
driver = "file"; driver = "file";
filename = "${systems.installer.configuration.config.my.buildAs.iso}/iso/nixos-installer-devplayer0.iso"; filename = "${systems.installer.configuration.config.my.buildAs.iso}/iso/nixos-installer-devplayer0.iso";
read-only = "on"; read-only = "on";
}; };
format.driver = "raw"; format.driver = "raw";
frontend = "ide-cd"; frontend = "ide-cd";
frontendOpts = { frontendOpts = {
bootindex = 1; bootindex = 1;
};
}; };
}; };
in in
@ -58,12 +56,11 @@
waitOnline = "no-carrier"; waitOnline = "no-carrier";
mac = "52:54:00:15:1a:53"; mac = "52:54:00:15:1a:53";
}; };
drives = mkMerge ([ ] ++ (optionals (!config.my.build.isDevVM) [ drives = [ ] ++ (optionals (!config.my.build.isDevVM) [
(vmLVM "estuary" "esp") (vmLVM "estuary" "esp")
(vmLVM "estuary" "nix") (vmLVM "estuary" "nix")
(vmLVM "estuary" "persist") (vmLVM "estuary" "persist")
{ esp.frontendOpts.bootindex = 0; } ]);
]));
hostDevices."${wanBDF}" = { }; hostDevices."${wanBDF}" = { };
}; };
@ -76,29 +73,24 @@
memory = 65536; memory = 65536;
networks.vms.mac = "52:54:00:27:3d:5c"; networks.vms.mac = "52:54:00:27:3d:5c";
cleanShutdown.timeout = 120; cleanShutdown.timeout = 120;
drives = mkMerge ([ drives = [ ] ++ (optionals (!config.my.build.isDevVM) [
installerDisk
] ++ (optionals (!config.my.build.isDevVM) [
(vmLVM "shill" "esp") (vmLVM "shill" "esp")
(vmLVM "shill" "nix") (vmLVM "shill" "nix")
(vmLVM "shill" "persist") (vmLVM "shill" "persist")
{ {
esp.frontendOpts.bootindex = 0; name = "media";
backend = {
media = { driver = "host_device";
backend = { filename = "/dev/hdds/media";
driver = "host_device"; discard = "unmap";
filename = "/dev/hdds/media";
discard = "unmap";
};
format = {
driver = "raw";
discard = "unmap";
};
frontend = "virtio-blk";
}; };
format = {
driver = "raw";
discard = "unmap";
};
frontend = "virtio-blk";
} }
])); ]);
}; };
}; };
}; };

View File

@ -82,6 +82,7 @@ let
driveOpts = with lib.types; { driveOpts = with lib.types; {
options = { options = {
name = mkOpt' str null "Drive name.";
backend = mkOpt' qemuOpts { } "Backend blockdev options."; backend = mkOpt' qemuOpts { } "Backend blockdev options.";
format = mkOpt' qemuOpts { } "Format blockdev options."; format = mkOpt' qemuOpts { } "Format blockdev options.";
@ -128,7 +129,7 @@ let
}); });
default = { }; default = { };
}; };
drives = mkOpt' (attrsOf (submodule driveOpts)) { } "Drives to attach to VM."; drives = mkOpt' (listOf (submodule driveOpts)) { } "Drives to attach to VM.";
hostDevices = mkOpt' (attrsOf (submodule hostDevOpts)) { } "Host PCI devices to pass to the VM."; hostDevices = mkOpt' (attrsOf (submodule hostDevOpts)) { } "Host PCI devices to pass to the VM.";
}; };
}; };
@ -170,10 +171,10 @@ let
"netdev tap,id=${nn},ifname=${c.ifname},script=no" "netdev tap,id=${nn},ifname=${c.ifname},script=no"
("device ${c.model},netdev=${nn},mac=${c.mac}" + (extraQEMUOpts c.extraOptions)) ("device ${c.model},netdev=${nn},mac=${c.mac}" + (extraQEMUOpts c.extraOptions))
]) i.networks)) ++ ]) i.networks)) ++
(flatten (mapAttrsToList (dn: c: [ (flatten (map (d: [
"blockdev node-name=${dn}-backend,${c.backend}" "blockdev node-name=${d.name}-backend,${d.backend}"
"blockdev node-name=${dn}-format,${c.formatBackendProp}=${dn}-backend,${c.format}" "blockdev node-name=${d.name}-format,${d.formatBackendProp}=${d.name}-backend,${d.format}"
("device ${c.frontend},id=${dn},drive=${dn}-format" + (extraQEMUOpts c.frontendOpts)) ("device ${d.frontend},id=${d.name},drive=${d.name}-format" + (extraQEMUOpts d.frontendOpts))
]) i.drives)) ++ ]) i.drives)) ++
(map (bdf: "device vfio-pci,host=${bdf}") (attrNames i.hostDevices)); (map (bdf: "device vfio-pci,host=${bdf}") (attrNames i.hostDevices));
args = map (v: "-${v}") flags; args = map (v: "-${v}") flags;