Files
dotfiles/nixos/ryu/vms/win11.nix
2025-02-21 15:12:09 +05:30

87 lines
2.0 KiB
Nix

{
config,
pkgs,
lib,
...
}: {
virtualisation.libvirtd.enable = true;
virtualisation.libvirtd.qemu.ovmf.enable = true;
virtualisation.libvirtd.qemu.swtpm.enable = true;
# IOMMU and VFIO settings
# boot.kernelParams = [
# "amd_iommu=on" # Use "intel_iommu=on" for Intel CPUs
# "iommu=pt"
# "vfio-pci.ids=10de:2504,10de:228e" # Replace with your GPU's vendor:device IDs
# ];
# boot.kernelModules = [
# "vfio_pci"
# "vfio"
# "vfio_iommu_type1"
# "vfio_virqfd"
# ];
#
# # Early loading of VFIO
# boot.initrd.kernelModules = [
# "vfio_pci"
# "vfio"
# "vfio_iommu_type1"
# "vfio_virqfd"
# ];
# Define the Windows 11 VM
virtualisation.libvirtd.qemu.verbatimConfig = ''
user = "root"
group = "root"
cgroup_device_acl = [
"/dev/null", "/dev/full", "/dev/zero",
"/dev/random", "/dev/urandom",
"/dev/ptmx", "/dev/kvm", "/dev/kqemu",
"/dev/rtc","/dev/hpet"
]
'';
virtualisation.libvirtd.hooks.qemu = {
"win11" = ''
# Add any VM hooks here if needed
'';
};
systemd.services.libvirtd-win11 = {
description = "Windows 11 VM";
after = ["libvirtd.service"];
requires = ["libvirtd.service"];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = "yes";
ExecStart = "${pkgs.libvirt}/bin/virsh define ${./windows.xml} && ${pkgs.libvirt}/bin/virsh start win11";
ExecStop = "${pkgs.libvirt}/bin/virsh shutdown win11";
};
wantedBy = ["multi-user.target"];
};
# Setup Looking Glass shared memory
systemd.tmpfiles.rules = [
"f /dev/shm/looking-glass 0660 root qemu-libvirtd 32M"
];
environment.systemPackages = with pkgs; [
virt-manager
OVMF
swtpm
win-virtio
looking-glass-client
];
# Networking for VM
networking.bridges.virbr0.interfaces = [];
networking.interfaces.virbr0.useDHCP = true;
# Enable huge pages for better performance
boot.kernel.sysctl."vm.nr_hugepages" = 8192;
# Optional: Enable looking glass for low-latency VM display
}