{
  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";
  };

  config = 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;
          };
        };
      };
    };
  };
}
