dotfiles/hosts/malachite/default.nix

110 lines
2.6 KiB
Nix
Raw Normal View History

2024-04-05 02:21:55 -07:00
{ config, pkgs, lib, ... }:
2024-03-13 23:13:52 -07:00
let
2024-04-05 02:21:55 -07:00
passthrough = pkgs.writeShellApplication {
2024-06-05 05:46:08 -07:00
name = "passthrough.sh";
2024-04-05 02:23:27 -07:00
runtimeInputs = lib.attrVals [ "coreutils" "kmod" "libvirt" "procps" ] pkgs;
2024-04-05 02:21:55 -07:00
text = ''
GUEST_NAME="$1"
HOOK_NAME="$2"
STATE_NAME="$3"
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
set -x
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# For the windows 10 VM
if [[ "$GUEST_NAME" == "win10" ]]; then
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# Prepare hook
if [[ "$HOOK_NAME/$STATE_NAME" == "prepare/begin" ]]; then
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# Remove Hyprland
2024-06-05 05:46:08 -07:00
#pkill Hyprland
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# Unbind VTconsoles
echo 0 > /sys/class/vtconsole/vtcon0/bind
echo 0 > /sys/class/vtconsole/vtcon1/bind
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# Unbind EFI-Framebuffer
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# We love race conditions
sleep 2
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# Unload Modules
modprobe -r nvidia_drm nvidia_modeset nvidia_uvm nvidia
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# Unbind the GPU from display driver
virsh nodedev-detach pci_0000_01_00_0
virsh nodedev-detach pci_0000_01_00_1
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# Load VFIO Kernel Module
modprobe vfio_pci
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
sleep 2
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
elif [[ "$HOOK_NAME/$STATE_NAME" == "release/end" ]]; then
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# Re-Bind GPU to Nvidia Driver (replace the pci addresses with yours)
virsh nodedev-reattach pci_0000_01_00_0
virsh nodedev-reattach pci_0000_01_00_1
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
modprobe -r vfio-pci
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
#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
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
fi
fi
2024-03-13 23:13:52 -07:00
2024-04-05 02:21:55 -07:00
'';
2024-04-05 02:23:27 -07:00
};
2024-03-13 23:13:52 -07:00
in {
imports =
[
./hardware-configuration.nix
../default.nix
2024-03-13 23:13:52 -07:00
];
2024-03-14 00:29:36 -07:00
virtualisation.libvirtd.hooks.qemu = {
2024-06-05 05:46:08 -07:00
passthrough = "${passthrough}/bin/passthrough.sh";
2024-03-13 23:01:33 -07:00
};
2024-03-13 23:13:52 -07:00
2024-03-26 21:34:28 -07:00
stitchyconf = {
artPkgs.enable = true;
};
2024-06-05 05:46:08 -07:00
virtualisation.libvirtd = {
enable = true;
onBoot = "ignore";
};
hardware = {
2024-06-05 05:46:08 -07:00
opentabletdriver.enable = true;
steam-hardware.enable = true;
};
2024-03-13 23:13:52 -07:00
2024-04-05 02:23:27 -07:00
networking.networkmanager.enable = true;
services.syncthing = {
enable = true;
user = "stitchynyan";
openDefaultPorts = true;
databaseDir = "/home/stitchynyan/.local/share/syncthing";
dataDir = "/home/stitchynyan";
};
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-14 00:29:36 -07:00
}