diff --git a/modules/nixos/nvidia.nix b/modules/nixos/nvidia.nix index bf308d7..5b2711e 100644 --- a/modules/nixos/nvidia.nix +++ b/modules/nixos/nvidia.nix @@ -6,54 +6,67 @@ }: { - # Enable OpenGL - hardware.graphics = { - enable = true; - }; + # Allow to use the nvidia driver in the special case + # Use in the boot menu + specialisation = { + nvidia-enabled = { + configuration = { + system.nixos.tags = [ "nvidia-enabled" ]; + # Enable OpenGL + hardware.graphics = { + enable = true; + }; + hardware.nvidia = { + prime = { + sync.enable = true; + # reverseSync.enable = true; + # allowExternalGpu = false; + nvidiaBusId = "PCI:1:0:0"; + intelBusId = "PCI:0:2:0"; - # Load nvidia driver for Xorg and Wayland - services.xserver.videoDrivers = ["nvidia"]; + }; + modesetting.enable = true; + powerManagement.enable = false; + powerManagement.finegrained = false; + open = false; + nvidiaSettings = false; - # specify nvidia driver version - hardware.nvidia = { + package = config.boot.kernelPackages.nvidiaPackages.mkDriver { + version = "565.77"; # latest + sha256_64bit = "sha256-CnqnQsRrzzTXZpgkAtF7PbH9s7wbiTRNcM0SPByzFHw="; + sha256_aarch64 = "sha256-LSAYUnhfnK3rcuPe1dixOwAujSof19kNOfdRHE7bToE="; + openSha256 = "sha256-Fxo0t61KQDs71YA8u7arY+503wkAc1foaa51vi2Pl5I="; + settingsSha256 = "sha256-VUetj3LlOSz/LB+DDfMCN34uA4bNTTpjDrb6C6Iwukk="; + persistencedSha256 = "sha256-wnDjC099D8d9NJSp9D0CbsL+vfHXyJFYYgU3CwcqKww="; + }; + }; - # Modesetting is required. - modesetting.enable = true; - - # Nvidia power management. Experimental, and can cause sleep/suspend to fail. - # Enable this if you have graphical corruption issues or application crashes after waking - # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead - # of just the bare essentials. - powerManagement.enable = false; - - # Fine-grained power management. Turns off GPU when not in use. - # Experimental and only works on modern Nvidia GPUs (Turing or newer). - powerManagement.finegrained = false; - - # the open source drivers are not compatible with the old 1050ti - open = false; - - # Enable the Nvidia settings menu, - # accessible via `nvidia-settings`. - nvidiaSettings = true; - - # Optionally, you may need to select the appropriate driver version for your specific GPU. - package = config.boot.kernelPackages.nvidiaPackages.mkDriver { - version = "565.77"; # latest - sha256_64bit = "sha256-CnqnQsRrzzTXZpgkAtF7PbH9s7wbiTRNcM0SPByzFHw="; - sha256_aarch64 = "sha256-LSAYUnhfnK3rcuPe1dixOwAujSof19kNOfdRHE7bToE="; - openSha256 = "sha256-Fxo0t61KQDs71YA8u7arY+503wkAc1foaa51vi2Pl5I="; - settingsSha256 = "sha256-VUetj3LlOSz/LB+DDfMCN34uA4bNTTpjDrb6C6Iwukk="; - persistencedSha256 = "sha256-wnDjC099D8d9NJSp9D0CbsL+vfHXyJFYYgU3CwcqKww="; + boot.extraModprobeConfig = ""; + boot.blacklistedKernelModules = []; + services.udev.extraRules = ""; + services.xserver.videoDrivers = ["nvidia"]; + }; }; - - prime = { - offload = { - enable = true; - enableOffloadCmd = true; - }; - intelBusId = "PCI:0:2:0"; - nvidiaBusId = "PCI:1:0:0"; - }; }; + + + # In the global configuration, we blacklist the nouveau driver and load the nvidia driver + boot.extraModprobeConfig = lib.mkDefault '' + blacklist nouveau + options nouveau modeset=0 + ''; + + services.udev.extraRules = lib.mkDefault '' + # Remove NVIDIA USB xHCI Host Controller devices, if present + ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c0330", ATTR{power/control}="auto", ATTR{remove}="1" + # Remove NVIDIA USB Type-C UCSI devices, if present + ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c8000", ATTR{power/control}="auto", ATTR{remove}="1" + # Remove NVIDIA Audio devices, if present + ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", ATTR{power/control}="auto", ATTR{remove}="1" + # Remove NVIDIA VGA/3D controller devices + ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", ATTR{power/control}="auto", ATTR{remove}="1" + ''; + + boot.blacklistedKernelModules = lib.mkDefault [ "nouveau" "nvidia" "nvidia_drm" "nvidia_modeset" ]; + }