dotfiles/hosts/malachite/default.nix

82 lines
2.2 KiB
Nix
Raw Normal View History

2024-03-13 23:13:52 -07:00
{ config, pkgs, ... }
let
passthrough = pkgs.writeShellScript "pasthrough.sh" ''
GUEST_NAME="$1"
HOOK_NAME="$2"
STATE_NAME="$3"
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
set -e
set -x
# For the windows 10 VM
if[$GUEST_NAME == 'win10']; then
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
# Prepare hook
if["$HOOK_NAME/$STATE_NAME" == "prepare/begin"]; then
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
# Remove Hyprland
2024-03-14 00:28:34 -07:00
${pkgs.busybox}/bin/pkill Hyprland
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
# Unbind VTconsoles
2024-03-14 00:28:34 -07:00
${pkgs.busybox}/bin/echo 0 > /sys/class/vtconsole/vtcon0/bind
${pkgs.busybox}/bin/echo 0 > /sys/class/vtconsole/vtcon1/bind
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
# Unbind EFI-Framebuffer
2024-03-14 00:28:34 -07:00
${pkgs.busybox}/bin/echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
# Unload Modules
2024-03-14 00:28:34 -07:00
${pkgs.busybox}/bin/modprobe -r nvidia_drm nvidia_modeset nvidia_uvm nvidia
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
# Unbind the GPU from display driver
2024-03-14 00:28:34 -07:00
${pkgs.libvirt}/bin/virsh nodedev-detach pci_0000_01_00_0
${pkgs.libvirt}/bin/virsh nodedev-detach pci_0000_01_00_1
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
# Load VFIO Kernel Module
2024-03-14 00:28:34 -07:00
${pkgs.busybox}/bin/modprobe vfio_pci
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
elif["$HOOK_NAME/$STATE_NAME" == "release/end"]; then
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
# Re-Bind GPU to Nvidia Driver (replace the pci addresses with yours)
2024-03-14 00:28:34 -07:00
${pkgs.libvirt}/bin/virsh nodedev-reattach pci_0000_01_00_0
${pkgs.libvirt}/bin/virsh nodedev-reattach pci_0000_01_00_1
2024-03-13 23:01:33 -07:00
2024-03-14 00:28:34 -07:00
${pkgs.busybox}/bin/modprobe -r vfio-pci
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
#bind efi
2024-03-14 00:28:34 -07:00
${pkgs.busybox}/bin/echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
# Reload nvidia modules
2024-03-14 00:28:34 -07:00
${pkgs.busybox}/bin/modprobe nvidia_drm
${pkgs.busybox}/bin/modprobe nvidia_modeset
${pkgs.busybox}/bin/modprobe nvidia_uvm
${pkgs.busybox}/bin/modprobe nvidia
2024-03-13 23:01:33 -07:00
2024-03-13 23:13:52 -07:00
# Rebind VT consoles
2024-03-14 00:28:34 -07:00
${pkgs.busybox}/bin/echo 1 > /sys/class/vtconsole/vtcon0/bind
${pkgs.busybox}/bin/echo 1 > /sys/class/vtconsole/vtcon1/bind
2024-03-13 23:01:33 -07:00
fi
2024-03-13 23:13:52 -07:00
fi
'';
in {
imports =
[
./hardware-configuration.nix
];
2024-03-13 23:01:33 -07:00
virtualization.libvirtd.hooks.qemu = {
passthrough = "${passthrough}";
};
2024-03-13 23:13:52 -07:00
networking.hostName = "malachite";
time.timeZone = "America/Los_Angeles";
2024-03-13 23:01:33 -07:00
2024-02-25 19:49:15 -08:00
# Read the Docs before Changing
system.stateVersion = "23.05"; # Did you read the comment?
2024-03-13 23:13:52 -07:00
};