Testing GPU Accellerated VM's
This commit is contained in:
parent
b6d5383690
commit
024f92974e
4 changed files with 50 additions and 50 deletions
nixos
|
@ -82,7 +82,6 @@
|
|||
# General apps
|
||||
newsflash
|
||||
gnome-photos
|
||||
gnome-boxes
|
||||
|
||||
# Gnome relevant packages
|
||||
gnome-tweaks
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
inputs.nixos-hardware.nixosModules.framework-16-7040-amd
|
||||
(modulesPath + "/installer/scan/not-detected.nix")
|
||||
./disks.nix
|
||||
./vm-gpu.nix
|
||||
../../common/services/tailscale-autoconnect.nix
|
||||
../../common/modules/secureboot.nix
|
||||
# ../../common/modules/boot.nix
|
||||
|
@ -15,9 +16,6 @@
|
|||
../../common/services/ollama.nix
|
||||
];
|
||||
|
||||
virtualisation.libvirtd.enable = true;
|
||||
programs.virt-manager.enable = true;
|
||||
|
||||
# https://wiki.nixos.org/wiki/Ollama
|
||||
services.ollama = {
|
||||
acceleration = "rocm";
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
hibernateEnvironment = {
|
||||
HIBERNATE_SECONDS = "10";
|
||||
HIBERNATE_LOCK = "/var/run/autohibernate.lock";
|
||||
};
|
||||
in {
|
||||
|
||||
systemd.services."awake-after-suspend-for-a-time" = {
|
||||
description = "Sets up the suspend so that it'll wake for hibernation only if not on AC power";
|
||||
wantedBy = [ "suspend.target" ];
|
||||
before = [ "systemd-suspend.service" ];
|
||||
environment = hibernateEnvironment;
|
||||
script = ''
|
||||
if [ $(cat /sys/class/power_supply/ACAD/online) -eq 0 ]; then
|
||||
curtime=$(date +%s)
|
||||
echo "$curtime $1" >> /tmp/autohibernate.log
|
||||
echo "$curtime" > $HIBERNATE_LOCK
|
||||
${pkgs.utillinux}/bin/rtcwake -m no -s $HIBERNATE_SECONDS
|
||||
else
|
||||
echo "System is on AC power, skipping wake-up scheduling for hibernation." >> /tmp/autohibernate.log
|
||||
fi
|
||||
'';
|
||||
serviceConfig.Type = "simple";
|
||||
};
|
||||
|
||||
systemd.services."hibernate-after-recovery" = {
|
||||
description = "Hibernates after a suspend recovery due to timeout";
|
||||
wantedBy = [ "suspend.target" ];
|
||||
after = [ "systemd-suspend.service" ];
|
||||
environment = hibernateEnvironment;
|
||||
script = ''
|
||||
curtime=$(date +%s)
|
||||
sustime=$(cat $HIBERNATE_LOCK)
|
||||
rm $HIBERNATE_LOCK
|
||||
if [ $(($curtime - $sustime)) -ge $HIBERNATE_SECONDS ] ; then
|
||||
systemctl hibernate
|
||||
else
|
||||
${pkgs.utillinux}/bin/rtcwake -m no -s 1
|
||||
fi
|
||||
'';
|
||||
serviceConfig.Type = "simple";
|
||||
};
|
||||
|
||||
}
|
49
nixos/hosts/framework16/vm-gpu.nix
Normal file
49
nixos/hosts/framework16/vm-gpu.nix
Normal file
|
@ -0,0 +1,49 @@
|
|||
{ pkgs, lib, ... }: # https://olai.dev/blog/nvidia-vm-passthrough/
|
||||
let
|
||||
devices = [
|
||||
"1002:7480" # Video
|
||||
"1002:1640" # Audio
|
||||
];
|
||||
in {
|
||||
virtualisation.libvirtd = {
|
||||
enable = true;
|
||||
qemu.ovmf.enable = true;
|
||||
onBoot = "ignore";
|
||||
onShutdown = "shutdown";
|
||||
};
|
||||
|
||||
|
||||
programs.virt-manager.enable = true;
|
||||
users.users.albert.extraGroups = [ "libvirtd" ];
|
||||
environment.systemPackages = [ pkgs.virt-manager ];
|
||||
|
||||
boot.kernelParams = [
|
||||
"vfio-pci.ids=${lib.concatStringsSep "," devices}"
|
||||
"intel_iommu=on"
|
||||
"iommu=pt"
|
||||
];
|
||||
|
||||
# Make the devices bind to VFIO
|
||||
boot.initrd.kernelModules = [
|
||||
"vfio_pci"
|
||||
"vfio"
|
||||
"vfio_iommu_type1"
|
||||
];
|
||||
|
||||
# Blacklist the nvidia drivers to make sure they don't get loaded
|
||||
boot.extraModprobeConfig = ''
|
||||
softdep nvidia pre: vfio-pci
|
||||
softdep drm pre: vfio-pci
|
||||
softdep nouveau pre: vfio-pci
|
||||
'';
|
||||
boot.blacklistedKernelModules = [
|
||||
"nouveau"
|
||||
"nvidia"
|
||||
"nvidia_drm"
|
||||
"nvidia_modeset"
|
||||
"i2c_nvidia_gpu"
|
||||
];
|
||||
virtualisation.spiceUSBRedirection.enable = true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue