Files
nixos/hosts/jude/virt.nix
T

94 lines
2.1 KiB
Nix
Raw Normal View History

2025-01-07 10:58:24 -06:00
{
config,
lib,
pkgs,
...
}:
2022-05-04 13:52:38 -05:00
2025-01-07 10:58:24 -06:00
let
passthru = [
"1002:164e" # Raphael - embedded GPU
"1002:1640" # Rembrandt - Audio
#"10de:2507" # RTX 3050 video
#"10de:228e" # RTX 3050 audio
];
in
2022-05-04 13:52:38 -05:00
{
greg.vmdev.enable = true;
2022-05-04 13:52:38 -05:00
2024-11-18 21:11:17 -06:00
age.secrets.runner-reg.file = ../../secrets/gitlab/isaiah-vbox-runner-reg.age;
2024-04-21 21:54:45 -05:00
2025-01-07 10:58:24 -06:00
# These options enable sharing of the GPU with the VM
boot = {
# Order matters here, to prevent the AMD driver from getting to the driver before
# vfio-pci does
initrd.kernelModules = [
"vfio_pci"
"vfio"
"vfio_iommu_type1"
2025-01-08 08:05:24 -06:00
#"amdgpu"
2025-01-07 10:58:24 -06:00
#"nvidia"
#"nvidia_modeset"
#"nvidia_uvm"
#"nvidia_drm"
];
kernelParams = [
"amd_iommu=on"
2025-01-08 08:05:24 -06:00
"iommu=pt"
2025-01-07 10:58:24 -06:00
("vfio-pci.ids=" + (lib.concatStringsSep "," passthru))
];
};
hardware.graphics.enable = true;
2025-01-07 10:58:24 -06:00
services.gitlab-runner = {
enable = true;
settings.concurrent = 5;
services.vbox = {
executor = "shell";
limit = 5;
authenticationTokenConfigFile = config.age.secrets.runner-reg.path;
environmentVariables = {
EFI_DIR = "${pkgs.OVMF.fd}/FV/";
};
};
};
2024-12-10 09:57:19 -06:00
2025-01-07 10:58:24 -06:00
systemd.services = {
gitlab-runner = {
conflicts = [ "libvirtd.service" ];
preStart = builtins.concatStringsSep "\n" [
"${pkgs.kmod}/bin/modprobe vboxnetflt vboxdrv"
"${pkgs.kmod}/bin/modprobe vboxnetadp"
];
postStop = "${pkgs.kmod}/bin/rmmod vboxnetflt vboxnetadp vboxdrv";
wantedBy = pkgs.lib.mkForce [ ];
serviceConfig.User = "root";
2024-12-10 09:57:19 -06:00
};
2025-01-08 08:05:24 -06:00
2025-01-09 10:15:55 -06:00
"libvirt-nosleep@" = {
2025-01-08 08:05:24 -06:00
description = "Prevent sleep while %i is running";
serviceConfig = {
Type = "simple";
ExecStart = ''
${pkgs.systemd}/bin/systemd-inhibit --what=sleep --why="Libvirt domain %i is running" --who=%U --mode=block sleep infinity
'';
};
};
2025-01-07 10:58:24 -06:00
};
virtualisation = {
2025-01-08 08:05:24 -06:00
libvirtd = {
extraConfig = ''
log_filters="1:qemu"
log_outputs="1:file:/var/log/libvirt/libvirtd.log"
'';
hooks.qemu = {
win10 = lib.getExe pkgs.qemu-hook;
2025-01-07 10:58:24 -06:00
};
2025-01-08 08:05:24 -06:00
};
2025-01-07 10:58:24 -06:00
spiceUSBRedirection.enable = true;
2024-12-10 09:57:19 -06:00
};
2022-05-04 13:52:38 -05:00
}