Move vm options to the vm variants

This commit is contained in:
Manuel Thalmann 2024-05-01 01:38:03 +02:00
parent 55e075e01b
commit 8bb98177cf

View file

@ -1,5 +1,7 @@
{ config, lib, options, pkgs, ... }: { { config, lib, options, pkgs, ... }: {
options = { options =
let
vmVariantOptions = {
virtualisation = { virtualisation = {
runAsRoot = lib.mkOption { runAsRoot = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
@ -17,6 +19,12 @@
}; };
}; };
}; };
in {
virtualisation = {
vmVariant = vmVariantOptions;
vmVariantWithBootLoader = vmVariantOptions;
};
};
config = { config = {
virtualisation = virtualisation =
@ -25,7 +33,10 @@
vmVariant: { vmVariant: {
boot.loader.efi.efiSysMountPoint = lib.mkVMOverride "/boot"; boot.loader.efi.efiSysMountPoint = lib.mkVMOverride "/boot";
virtualisation.sharedDirectories = lib.optionalAttrs (vmVariant.virtualisation.sharedHostKeys) { virtualisation = {
runAsRoot = lib.mkIf vmVariant.virtualisation.sharedHostKeys true;
sharedDirectories = lib.optionalAttrs (vmVariant.virtualisation.sharedHostKeys) {
hostKeys = hostKeys =
let let
path = "/etc/ssh"; path = "/etc/ssh";
@ -35,13 +46,12 @@
}; };
}; };
}; };
};
virtualisation = config.virtualisation; virtualisation = config.virtualisation;
in { in {
vmVariant = extendVMConfig virtualisation.vmVariant; vmVariant = extendVMConfig virtualisation.vmVariant;
vmVariantWithBootLoader = extendVMConfig virtualisation.vmVariantWithBootLoader; vmVariantWithBootLoader = extendVMConfig virtualisation.vmVariantWithBootLoader;
runAsRoot = lib.mkIf config.virtualisation.sharedHostKeys true;
}; };
# Replace native `qemu` with `remote-viewer` # Replace native `qemu` with `remote-viewer`