os/hosts/chocolatebar/virtualisation/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.2 KiB
Nix
Raw Normal View History

2023-01-28 21:27:52 +00:00
{
config,
pkgs,
lib,
...
}:
with lib; let
2021-05-30 19:33:09 +00:00
psCfg = config.pub-solar;
xdg = config.home-manager.users."${psCfg.user.name}".xdg;
createService = import ./create-service.nix;
2022-10-17 13:58:03 +00:00
generateXML = import ./guest-xml.nix;
generateTailsXML = import ./tails-xml.nix;
isolateGPU = "rx550x";
2022-10-17 13:58:03 +00:00
memory = 48; # in GB
handOverUSBDevices = false;
isolateAnyGPU = isolateGPU != null;
2023-01-28 21:27:52 +00:00
in {
2021-05-30 19:33:09 +00:00
config = mkIf psCfg.virtualisation.enable {
boot.extraModprobeConfig = mkIf isolateAnyGPU (concatStringsSep "\n" [
"softdep amdgpu pre: vfio vfio_pci"
2023-01-28 21:27:52 +00:00
(
if isolateGPU == "rx5700xt"
then "options vfio-pci ids=1002:731f,1002:ab38"
else "options vfio-pci ids=1002:699f,1002:aae0"
2021-05-30 19:33:09 +00:00
)
]);
systemd.user.services = {
vm-windows = createService {
inherit config;
inherit pkgs;
inherit lib;
vm = {
name = "windows";
disk = "/dev/disk/by-id/ata-SanDisk_SDSSDA240G_162402455603";
id = "http://microsoft.com/win/10";
gpu = true;
mountHome = false;
2022-10-17 13:58:03 +00:00
memory = memory;
isolateGPU = isolateGPU;
handOverUSBDevices = handOverUSBDevices;
2022-10-17 13:58:03 +00:00
generateXML = generateXML;
2021-05-30 19:33:09 +00:00
};
};
vm-manjaro = createService {
inherit config;
inherit pkgs;
inherit lib;
vm = {
name = "manjaro";
disk = "/dev/disk/by-id/ata-KINGSTON_SM2280S3G2240G_50026B726B0265CE";
id = "https://manjaro.org/download/#i3";
gpu = true;
mountHome = true;
2022-10-17 13:58:03 +00:00
memory = memory;
isolateGPU = isolateGPU;
handOverUSBDevices = handOverUSBDevices;
2022-10-17 13:58:03 +00:00
generateXML = generateXML;
};
};
vm-tails = createService {
inherit config;
inherit pkgs;
inherit lib;
vm = {
name = "tails";
disk = "/var/lib/vms/tails/tails-amd64-5.4.iso";
# disk = "/var/lib/vms/nixos/nixos-minimal.iso";
id = "https://tails.boum.org/install/index.en.html";
gpu = false;
mountHome = false;
memory = 16;
isolateGPU = isolateGPU;
handOverUSBDevices = false;
generateXML = generateTailsXML;
2021-05-30 19:33:09 +00:00
};
};
};
};
}