dotfiles/hosts/malachite/default.nix

127 lines
3.4 KiB
Nix
Raw Normal View History

2024-08-08 04:49:22 -07:00
{ config, nixpkgs-xr, pkgs, lib, ... }:
2024-03-13 23:13:52 -07:00
let
2024-11-27 02:41:47 -08: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
2024-08-08 04:49:22 -07:00
#echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
2024-03-13 23:01:33 -07:00
2024-08-08 04:49:22 -07:00
# Unbind the GPU from display driver
virsh nodedev-detach pci_0000_03_00_0
virsh nodedev-detach pci_0000_03_00_1
virsh nodedev-detach pci_0000_03_00_2
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# Unload Modules
2024-08-08 04:49:22 -07:00
modprobe -r amdgpu
2024-03-13 23:01:33 -07:00
2024-08-08 04:49:22 -07:00
# We love race conditions
sleep 2
2024-03-13 23:01:33 -07:00
2024-04-05 02:21:55 -07:00
# Load VFIO Kernel Module
2024-08-08 04:49:22 -07:00
modprobe vfio vfio_pci vfio_iommu_type1
2024-03-13 23:01:33 -07:00
2024-11-03 11:11:06 -08:00
# Performance Governer
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "performance" > "$file"; done
# Isolating CPU
systemctl set-property --runtime -- user.slice AllowedCPUs=16-19
systemctl set-property --runtime -- system.slice AllowedCPUs=16-19
systemctl set-property --runtime -- init.scope AllowedCPUs=16-19
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-08-08 04:49:22 -07:00
modprobe -r vfio_iommu_type1 vfio_pci vfio
2024-03-13 23:01:33 -07:00
2024-08-08 04:49:22 -07:00
# Re-Bind GPU to Host
virsh nodedev-reattach pci_0000_03_00_0
virsh nodedev-reattach pci_0000_03_00_1
virsh nodedev-reattach pci_0000_03_00_2
2024-04-05 02:21:55 -07:00
# Rebind VT consoles
echo 1 > /sys/class/vtconsole/vtcon0/bind
2024-08-08 04:49:22 -07:00
echo 1 > /sys/class/vtconsole/vtcon1/bind
sleep 2
# Bind Framebuffer
#echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
# Reload Modules
modprobe amdgpu
2024-03-13 23:01:33 -07:00
2024-11-03 11:11:06 -08:00
# Back to On-Demand Scheduler
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "ondemand" > "$file"; done
systemctl set-property --runtime -- user.slice AllowedCPUs=0-19
systemctl set-property --runtime -- system.slice AllowedCPUs=0-19
systemctl set-property --runtime -- init.scope AllowedCPUs=0-19
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-08-08 04:49:22 -07:00
environment.systemPackages = [
pkgs.wlx-overlay-s ];
2024-11-27 02:41:47 -08:00
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
}