machines/nix/modules/nixos/virtualisation/qemu-guest/default.nix
Kaare Hoff Skovgaard 3027ff2f1a
Some checks failed
/ check (push) Failing after 1m7s
/ dev-shell (push) Successful in 1m3s
/ rust-packages (push) Successful in 1m5s
/ terraform-providers (push) Successful in 1m40s
/ systems (push) Successful in 39m4s
Some minor fixes for vm target
2025-08-09 23:47:36 +02:00

52 lines
1.6 KiB
Nix

{
config,
lib,
...
}:
let
cfg = config.khscodes.virtualisation.qemu-guest;
rng = "-device virtio-rng-pci,rng=rng0 -object rng-random,id=rng0,filename=/dev/urandom";
spice = [
"-spice disable-ticketing=on,gl=on,unix=on,addr=/tmp/spice.sock"
"-device virtio-serial-pci"
"-chardev socket,id=agent0,path=vm.sock,server=on,wait=off"
"-device virtserialport,chardev=agent0,name=org.qemu.guest_agent.0"
"-chardev spicevmc,id=vdagent0,name=vdagent"
"-device virtserialport,chardev=vdagent0,name=com.redhat.spice.0"
"-chardev spiceport,id=webdav0,name=org.spice-space.webdav.0"
"-device virtserialport,chardev=webdav0,name=org.spice-space.webdav.0"
];
in
{
options.khscodes.virtualisation.qemu-guest = {
enable = lib.mkEnableOption "Configures machine with NixOS profile for qemu guest";
enableWhenVmTarget = lib.mkEnableOption "Enables some enhancement settings when building as a vm";
};
imports = [ ./profile.nix ];
config = lib.mkMerge [
(lib.mkIf cfg.enable {
services.qemuGuest.enable = true;
})
(lib.mkIf cfg.enableWhenVmTarget {
virtualisation = {
vmVariant = {
khscodes.virtualisation.qemu-guest.enable = true;
services.spice-vdagentd.enable = true;
virtualisation = {
memorySize = 1024 * 8;
qemu = {
options = [
"-smp 8"
"-vga none -device virtio-gpu-gl,hostmem=2G,blob=true,venus=true"
rng
]
++ spice;
};
};
};
};
})
];
}