Allow running the VM using virt-viewer

This commit is contained in:
Manuel Thalmann 2024-05-01 03:21:34 +02:00
parent 2b5fe69994
commit 90368fcda8

View file

@ -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,7 +75,11 @@ in {
virtualisation = {
runAsRoot = lib.mkIf vmVariant.virtualisation.sharedHostKeys true;
qemu.options =
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;
};
@ -82,6 +91,7 @@ in {
"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 {