better way of doing this

This commit is contained in:
stitchy 2024-04-05 02:21:55 -07:00
parent 16ae890458
commit 8d69eb76d6
Signed by: stitchy
SSH key fingerprint: SHA256:p+xeQgmOvQ2br1d2STl5OnRRMef2LRqCtGA7SO4WYk0

View file

@ -1,65 +1,74 @@
{ config, pkgs, ... }: { config, pkgs, lib, ... }:
let let
passthrough = pkgs.writeShellScript "pasthrough.sh" '' passthrough = pkgs.writeShellApplication {
GUEST_NAME="$1" name = "pasthrough.sh";
HOOK_NAME="$2" runtimeInputs = lib.attrVals [ "coreutils" "kmod" "libvirtd" "procps" ] pkgs;
STATE_NAME="$3" text = ''
GUEST_NAME="$1"
HOOK_NAME="$2"
STATE_NAME="$3"
set -e echo 19>/home/stitchynyan/startlogfile
set -x BASH_XTRACEFD=19
set -x
# For the windows 10 VM
if [[ "$GUEST_NAME" == "win10" ]]; then
# Prepare hook # For the windows 10 VM
if [[ "$HOOK_NAME/$STATE_NAME" == "prepare/begin" ]]; then if [[ "$GUEST_NAME" == "win10" ]]; then
# Remove Hyprland # Prepare hook
${pkgs.busybox}/bin/pkill Hyprland if [[ "$HOOK_NAME/$STATE_NAME" == "prepare/begin" ]]; then
# Unbind VTconsoles # Remove Hyprland
${pkgs.busybox}/bin/echo 0 > /sys/class/vtconsole/vtcon0/bind pkill Hyprland
${pkgs.busybox}/bin/echo 0 > /sys/class/vtconsole/vtcon1/bind
# Unbind EFI-Framebuffer # Unbind VTconsoles
${pkgs.busybox}/bin/echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind echo 0 > /sys/class/vtconsole/vtcon0/bind
echo 0 > /sys/class/vtconsole/vtcon1/bind
# Unload Modules # Unbind EFI-Framebuffer
${pkgs.busybox}/bin/modprobe -r nvidia_drm nvidia_modeset nvidia_uvm nvidia echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
# Unbind the GPU from display driver # We love race conditions
${pkgs.libvirt}/bin/virsh nodedev-detach pci_0000_01_00_0 sleep 2
${pkgs.libvirt}/bin/virsh nodedev-detach pci_0000_01_00_1
# Load VFIO Kernel Module # Unload Modules
${pkgs.busybox}/bin/modprobe vfio_pci modprobe -r nvidia_drm nvidia_modeset nvidia_uvm nvidia
elif [[ "$HOOK_NAME/$STATE_NAME" == "release/end" ]]; then # Unbind the GPU from display driver
virsh nodedev-detach pci_0000_01_00_0
virsh nodedev-detach pci_0000_01_00_1
# Re-Bind GPU to Nvidia Driver (replace the pci addresses with yours) # Load VFIO Kernel Module
${pkgs.libvirt}/bin/virsh nodedev-reattach pci_0000_01_00_0 modprobe vfio_pci
${pkgs.libvirt}/bin/virsh nodedev-reattach pci_0000_01_00_1
${pkgs.busybox}/bin/modprobe -r vfio-pci sleep 2
#bind efi elif [[ "$HOOK_NAME/$STATE_NAME" == "release/end" ]]; then
${pkgs.busybox}/bin/echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
# Reload nvidia modules # Re-Bind GPU to Nvidia Driver (replace the pci addresses with yours)
${pkgs.busybox}/bin/modprobe nvidia_drm virsh nodedev-reattach pci_0000_01_00_0
${pkgs.busybox}/bin/modprobe nvidia_modeset virsh nodedev-reattach pci_0000_01_00_1
${pkgs.busybox}/bin/modprobe nvidia_uvm
${pkgs.busybox}/bin/modprobe nvidia
# Rebind VT consoles modprobe -r vfio-pci
${pkgs.busybox}/bin/echo 1 > /sys/class/vtconsole/vtcon0/bind
${pkgs.busybox}/bin/echo 1 > /sys/class/vtconsole/vtcon1/bind #bind efi
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
# Reload nvidia modules
modprobe nvidia_drm
modprobe nvidia_modeset
modprobe nvidia_uvm
modprobe nvidia
# Rebind VT consoles
echo 1 > /sys/class/vtconsole/vtcon0/bind
bin/echo 1 > /sys/class/vtconsole/vtcon1/bind
fi
fi fi
fi '';
'';
in { in {
imports = imports =
[ [