Working multi-GPU/single-GPU setup

This commit is contained in:
Gerg-L 2023-03-16 21:44:50 -04:00
parent 84b15db0af
commit 1d06b35262
12 changed files with 317 additions and 87 deletions

View file

@ -6,7 +6,6 @@ inputs: {
...
}: {
imports = [
(import ./refreshrate.nix inputs)
(import ./vfio.nix inputs)
(import ./parrot.nix inputs)
(import ./spicetify.nix inputs)
@ -33,7 +32,17 @@ inputs: {
kmscon.enable = true;
};
};
services.xserver.videoDrivers = ["amdgpu"];
hardware.nvidia = {
package = config.boot.kernelPackages.nvidiaPackages.beta;
nvidiaPersistenced = false;
nvidiaSettings = false;
modesetting.enable = true;
open = true;
};
services.xserver = {
videoDrivers = ["nvidia" "amdgpu"];
};
nixpkgs.config.allowUnfree = true;
environment.systemPackages = [
pkgs.webcord # talk to people (gross)
@ -47,12 +56,10 @@ inputs: {
pkgs.neovide #gui neovim
pkgs.ripgrep
inputs.suckless.packages.${pkgs.system}.st
pkgs.alacritty
];
#set webcord theme
systemd.tmpfiles.rules = let
theme = pkgs.writeText "black" (builtins.readFile "${self}/misc/black.theme.css");
in ["L+ /home/gerg/.config/WebCord/Themes/black - - - - ${theme}"];
environment.etc."xdg/alacritty/alacritty.yml".source = "${self}/misc/alacritty.yml";
networking = {
useDHCP = false;
hostName = "gerg-desktop";
@ -117,8 +124,8 @@ inputs: {
};
};
boot = {
kernelModules = ["amdgpu"];
initrd = {
kernelModules = ["amdgpu"];
availableKernelModules = ["nvme" "xhci_pci" "ahci" "usbhid" "sd_mod"];
includeDefaultModules = false;
};

View file

@ -1,24 +0,0 @@
_: {
services.xserver = {
#fix nasty screen tearing
screenSection = ''
Option "TearFree" "true"
'';
#set monitor as primary
#set refreshrate to 144 instead of default(60)
#disable DPMS(screen turning off)
monitorSection = ''
Option "Primary" "true"
Modeline "1920x1080_144" 332.75 1920 1952 2016 2080 1080 1084 1089 1111 +HSync +VSync
Option "PreferredMode" "1920x1080_144"
Option "DPMS" "false"
'';
#disable screen blanking in total
serverFlagsSection = ''
Option "StandbyTime" "0"
Option "SuspendTime" "0"
Option "OffTime" "0"
Option "BlankTime" "0"
'';
};
}

View file

@ -2,15 +2,51 @@ _: {
pkgs,
settings,
self,
config,
lib,
...
}: {
}: let
xcfg = config.services.xserver;
xserverbase = let
fontsForXServer =
config.fonts.fonts
++ [
pkgs.xorg.fontadobe100dpi
pkgs.xorg.fontadobe75dpi
];
in
pkgs.runCommand "xserverbase"
{
fontpath =
lib.optionalString (xcfg.fontPath != null)
''FontPath "${xcfg.fontPath}"'';
inherit (xcfg) config;
preferLocalBuild = true;
}
''
echo 'Section "Files"' >> $out
echo $fontpath >> $out
for i in ${toString fontsForXServer}; do
if test "''${i:0:''${#NIX_STORE}}" == "$NIX_STORE"; then
for j in $(find $i -name fonts.dir); do
echo " FontPath \"$(dirname $j)\"" >> $out
done
fi
done
for i in $(find ${toString xcfg.modules} -type d); do
if test $(echo $i/*.so* | wc -w) -ne 0; then
echo " ModulePath \"$i\"" >> $out
fi
done
echo '${xcfg.filesSection}' >> $out
echo 'EndSection' >> $out
echo >> $out
'';
oneMonitor = pkgs.writeText "1-monitor.conf" (lib.strings.concatStrings [(builtins.readFile xserverbase) (builtins.readFile "${self}/misc/1-monitor.conf")]);
twoMonitor = pkgs.writeText "2-monitor.conf" (lib.strings.concatStrings [(builtins.readFile xserverbase) (builtins.readFile "${self}/misc/2-monitor.conf")]);
in {
boot = {
kernelParams = ["amd_iommu=on" "iommu=pt" "vfio_iommu_type1.allow_unsafe_interrupts=1" "kvm.ignore_msrs=1"];
kernelModules = ["kvm-amd" "vfio_virqfd" "vfio_pci" "vfio_iommu_type1" "vfio"];
initrd.kernelModules = ["vfio_virqfd" "vfio_pci" "vfio_iommu_type1" "vfio"];
extraModprobeConfig = ''
options vfio-pci ids=10de:228e,10de:2504
'';
};
virtualisation = {
libvirtd = {
@ -27,7 +63,9 @@ _: {
};
};
environment = {
systemPackages = [pkgs.virt-manager];
systemPackages = [
pkgs.virt-manager
];
shellAliases = {
vm-start = "virsh start Windows";
vm-stop = "virsh shutdown Windows";
@ -36,30 +74,54 @@ _: {
users.users."${settings.username}".extraGroups = ["kvm" "libvirtd"];
services.xserver.displayManager.xserverArgs = lib.mkAfter ["-config /tmp/xorg.conf"];
services.xserver.displayManager.sessionCommands = lib.mkBefore ''
if ! (test -e "/tmp/ONE_MONITOR"); then
xrandr --setprovideroutputsource "AMD Radeon Graphics @ pci:0000:0f:00.0" NVIDIA-0
xrandr --auto
xrandr --output DP-0 --mode 3440x1440 --rate 120 --primary --left-of HDMI-A-1-0
xrandr --output HDMI-A-1-0 --mode 1920x1080 --rate 120 --set TearFree on
xset s off -dpms
fi
'';
systemd.tmpfiles.rules = let
xml = pkgs.writeText "Windows.xml" (builtins.readFile "${self}/misc/Windows.xml");
qemuHook = pkgs.writeScript "qemu-hook" ''
#!${pkgs.stdenv.shell}
qemuHook = pkgs.writeShellScript "qemu-hook" ''
GUEST_NAME="$1"
OPERATION="$2"
SUB_OPERATION="$3"
if [ "$GUEST_NAME" == "Windows" ]; then
if [ "$OPERATION" == "start" ]; then
systemctl set-property --runtime -- user.slice AllowedCPUs=8-15,24-31
systemctl set-property --runtime -- system.slice AllowedCPUs=8-15,24-31
systemctl set-property --runtime -- init.scope AllowedCPUs=8-15,24-31
if [ "$OPERATION" == "prepare" ]; then
systemctl stop display-manager.service
modprobe -r -a nvidia_uvm nvidia_drm nvidia nvidia_modeset
${pkgs.libvirt}/bin/virsh nodedev-detach pci_0000_01_00_0
${pkgs.libvirt}/bin/virsh nodedev-detach pci_0000_01_00_1
systemctl set-property --runtime -- user.slice AllowedCPUs=8-15,24-31
systemctl set-property --runtime -- system.slice AllowedCPUs=8-15,24-31
systemctl set-property --runtime -- init.scope AllowedCPUs=8-15,24-31
ln -fs ${oneMonitor} /tmp/xorg.conf
touch /tmp/ONE_MONITOR
systemctl start display-manager.service
fi
if [ "$OPERATION" == "stopped" ]; then
if [ "$OPERATION" == "release" ]; then
systemctl stop display-manager.service
systemctl set-property --runtime -- user.slice AllowedCPUs=0-31
systemctl set-property --runtime -- system.slice AllowedCPUs=0-31
systemctl set-property --runtime -- init.scope AllowedCPUs=0-31
${pkgs.libvirt}/bin/virsh nodedev-reattach pci_0000_01_00_0
${pkgs.libvirt}/bin/virsh nodedev-reattach pci_0000_01_00_1
modprobe -a nvidia_uvm nvidia_drm nvidia nvidia_modeset
ln -fs ${twoMonitor} /tmp/xorg.conf
rm /tmp/ONE_MONITOR
systemctl start display-manager.service
fi
fi
'';
in [
"L+ /var/lib/libvirt/hooks/ - - - - ${qemuHook}"
"L /tmp/xorg.conf - - - - ${twoMonitor}"
"L+ /var/lib/libvirt/hooks/qemu - - - - ${qemuHook}"
"L+ /var/lib/libvirt/qemu/Windows.xml - - - - ${xml}"
];
}