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; default = false;
}; };
virt-viewer = lib.mkOption {
type = lib.types.bool;
default = false;
};
qemu = { qemu = {
runInBackground = lib.mkOption { runInBackground = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
@ -70,7 +75,11 @@ in {
virtualisation = { virtualisation = {
runAsRoot = lib.mkIf vmVariant.virtualisation.sharedHostKeys true; 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 { with {
inherit (vmVariant.virtualisation.qemu) spice; inherit (vmVariant.virtualisation.qemu) spice;
}; };
@ -82,6 +91,7 @@ in {
"port=${toString spice.port}" "port=${toString spice.port}"
"disable-ticketing=on" "disable-ticketing=on"
]))); ])));
};
sharedDirectories = lib.optionalAttrs (vmVariant.virtualisation.sharedHostKeys) { sharedDirectories = lib.optionalAttrs (vmVariant.virtualisation.sharedHostKeys) {
hostKeys = hostKeys =
@ -126,9 +136,20 @@ in {
wrapped = pkgs.writeShellApplication { wrapped = pkgs.writeShellApplication {
name = "run-${config.system.name}-vm"; name = "run-${config.system.name}-vm";
text = '' text = lib.strings.concatLines (
${prefix} ${vm}/bin/run-${config.system.name}-vm ${suffix} [
''; "${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 in
pkgs.symlinkJoin { pkgs.symlinkJoin {