diff --git a/lib/config/custom-build-vm.nix b/lib/config/custom-build-vm.nix index 5d42460..ba9d6fd 100644 --- a/lib/config/custom-build-vm.nix +++ b/lib/config/custom-build-vm.nix @@ -31,6 +31,11 @@ in { default = false; }; + virt-viewer = lib.mkOption { + type = lib.types.bool; + default = false; + }; + qemu = { runInBackground = lib.mkOption { type = lib.types.bool; @@ -70,18 +75,23 @@ in { virtualisation = { runAsRoot = lib.mkIf vmVariant.virtualisation.sharedHostKeys true; - qemu.options = - with { - inherit (vmVariant.virtualisation.qemu) spice; - }; - ( - lib.optional (spice.enable) - ("-spice " + ( - lib.concatStringsSep "," [ - "addr=${lib.escapeShellArg spice.bindAddress}" - "port=${toString spice.port}" - "disable-ticketing=on" - ]))); + qemu = { + spice.enable = lib.mkIf vmVariant.virtualisation.virt-viewer true; + runInBackground = lib.mkIf vmVariant.virtualisation.virt-viewer true; + + options = + with { + inherit (vmVariant.virtualisation.qemu) spice; + }; + ( + lib.optional (spice.enable) + ("-spice " + ( + lib.concatStringsSep "," [ + "addr=${lib.escapeShellArg spice.bindAddress}" + "port=${toString spice.port}" + "disable-ticketing=on" + ]))); + }; sharedDirectories = lib.optionalAttrs (vmVariant.virtualisation.sharedHostKeys) { hostKeys = @@ -126,9 +136,20 @@ in { wrapped = pkgs.writeShellApplication { name = "run-${config.system.name}-vm"; - text = '' - ${prefix} ${vm}/bin/run-${config.system.name}-vm ${suffix} - ''; + text = lib.strings.concatLines ( + [ + "${prefix} ${vm}/bin/run-${config.system.name}-vm ${suffix}" + ] ++ ( + let + spice = config.virtualisation.qemu.spice; + in + ( + lib.optionals + config.virtualisation.virt-viewer + [ + "${pkgs.virt-viewer}/bin/remote-viewer spice://${lib.escapeShellArg spice.bindAddress}:${toString spice.port}" + "kill %1" + ]))); }; in pkgs.symlinkJoin {