From 8bb98177cfb9841116b5c841fe150619c47793dc Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 1 May 2024 01:38:03 +0200 Subject: [PATCH] Move vm options to the vm variants --- lib/config/custom-build-vm.nix | 58 ++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/lib/config/custom-build-vm.nix b/lib/config/custom-build-vm.nix index 8582ddd..ebc0cbe 100644 --- a/lib/config/custom-build-vm.nix +++ b/lib/config/custom-build-vm.nix @@ -1,20 +1,28 @@ { config, lib, options, pkgs, ... }: { - options = { + options = + let + vmVariantOptions = { + virtualisation = { + runAsRoot = lib.mkOption { + type = lib.types.bool; + default = false; + }; + + sharedHostKeys = lib.mkOption { + type = lib.types.bool; + default = false; + }; + + qemu.runInBackground = lib.mkOption { + type = lib.types.bool; + default = false; + }; + }; + }; + in { virtualisation = { - runAsRoot = lib.mkOption { - type = lib.types.bool; - default = false; - }; - - sharedHostKeys = lib.mkOption { - type = lib.types.bool; - default = false; - }; - - qemu.runInBackground = lib.mkOption { - type = lib.types.bool; - default = false; - }; + vmVariant = vmVariantOptions; + vmVariantWithBootLoader = vmVariantOptions; }; }; @@ -25,23 +33,25 @@ vmVariant: { boot.loader.efi.efiSysMountPoint = lib.mkVMOverride "/boot"; - virtualisation.sharedDirectories = lib.optionalAttrs (vmVariant.virtualisation.sharedHostKeys) { - hostKeys = - let - path = "/etc/ssh"; - in { - source = path; - target = path; + virtualisation = { + runAsRoot = lib.mkIf vmVariant.virtualisation.sharedHostKeys true; + + sharedDirectories = lib.optionalAttrs (vmVariant.virtualisation.sharedHostKeys) { + hostKeys = + let + path = "/etc/ssh"; + in { + source = path; + target = path; + }; }; }; }; virtualisation = config.virtualisation; in { - vmVariant = extendVMConfig virtualisation.vmVariant; vmVariantWithBootLoader = extendVMConfig virtualisation.vmVariantWithBootLoader; - runAsRoot = lib.mkIf config.virtualisation.sharedHostKeys true; }; # Replace native `qemu` with `remote-viewer`