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,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 {