Jump to content

Nvidia: Difference between revisions

1,598 bytes added ,  Tuesday at 20:25
m
fixed link to „Unfree software“ (capitalization)
(→‎Installing Nvidia drivers on NixOS: What is this AI yapping? "Distributions" when we are talking about just ours? Whoever wrote this, I challenge you to a duel.)
m (fixed link to „Unfree software“ (capitalization))
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
There are several drivers that allow Nvidia GPUs to work:
There are several kernel drivers that allow Nvidia GPUs to work:


* Nouveau is the stable 3rd-party open-source driver. You probably have it by default.
* Nouveau is the stable 3rd-party open-source driver. You probably have it by default.
* Nvidia's proprietary kernel module.
* Nvidia's proprietary kernel module. Better 3D performance than nouveau.
* Nvidia's open-source kernel module, which is beta-quality and x11-only.
* Nvidia's open-source kernel module, which is beta-quality and x11-only.
* Nvidia's mesa-nvk.


This article aims to explain how to use all three of the non-default drivers, and how to disable the Nvidia GPU if you don't want it to make heat.
This article aims to explain how to use all three of the non-default drivers, and how to disable the Nvidia GPU if you don't want it to make heat.


= Installing Nvidia drivers on NixOS =
(A GPU driver is not ''purely'' kernel-mode; there are also userspace parts that allow the graphics API to use the kernel part. Mesa, for example, has userspace parts for Nouveau and NVK; they are automatically used when appropriate, so no configuration is needed.<ref>If you insist on checking which driver is in use, try running <code>vulkaninfo | grep -i "deviceName\|driverID"</code>. If you see DRIVER_ID_MESA_NVK, that means you are on the shiny new open-source Vulkan driver.</ref> Nvidia's two kernel drivers also need to be hooked up using userspace libraries provided by Nvidia.)
 
= The proprietary driver =


NixOS uses a functional package management approach &ndash; this section, like many others, will tell you how to change your <code>configuration.nix</code> to define what kind of environment you want on your system.
NixOS uses a functional package management approach &ndash; this section, like many others, will tell you how to change your <code>configuration.nix</code> to define what kind of environment you want on your system.
Line 15: Line 16:
* [https://nixos.org/manual/nixos/unstable/#sec-x11-graphics-cards-nvidia Nvidia section] in the NixOS Manual offers a shorter guide.
* [https://nixos.org/manual/nixos/unstable/#sec-x11-graphics-cards-nvidia Nvidia section] in the NixOS Manual offers a shorter guide.
* Basic installation is as simple as <code>services.xserver.videoDrivers = [ "nvidia" ];</code> (once you have unfree software enabled), which causes the default stable version to be pulled in.
* Basic installation is as simple as <code>services.xserver.videoDrivers = [ "nvidia" ];</code> (once you have unfree software enabled), which causes the default stable version to be pulled in.
* Older cards may need an older driver; see [[#Determining the correct driver version]], which describes <code>hardware.nvidia.package</code>.
* Older cards may need an older driver; see [[#Determining the correct driver version|Determining the correct driver version]], which describes <code>hardware.nvidia.package</code>.
* [[#Modifying the NixOS Configuration]] puts it all together and shows the other <code>hardware.nvidia</code> settings, some irrelevant to this driver (e.g. <code>hardware.nvidia.open</code>, which takes you to the Nvidia open kernel driver.)
* [[Nvidia#Modifying NixOS configuration|Modifying the NixOS Configuration]] puts it all together and shows the other <code>hardware.nvidia</code> settings, some irrelevant to this driver (e.g. <code>hardware.nvidia.open</code>, which takes you to the Nvidia open kernel driver.)


== Enable unfree software repositories ==  
== Enable unfree software repositories ==  


Make sure to allow [[Unfree Software|unfree software]]. The unfree NVIDIA packages include <code>nvidia-x11</code>, <code>nvidia-settings</code>, and <code>nvidia-persistenced</code>.
Make sure to allow [[Unfree software|unfree software]]. The unfree NVIDIA packages include <code>nvidia-x11</code>, <code>nvidia-settings</code>, and <code>nvidia-persistenced</code>.
 
== Determining the correct driver version ==
 
You will next need to determine the appropriate driver version for your card. The following options are available:
 
<syntaxhighlight lang="nix">
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.beta;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.production;  # (installs 550)
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.vulkan_beta;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_470;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_390;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_340;
</syntaxhighlight>
 
Out of the above, `stable` and `beta` will work for the latest RTX cards and some lower cards so long as they're not considered "legacy" by Nvidia. For "legacy" cards, you can consult the [https://www.nvidia.com/en-us/drivers/unix/legacy-gpu/ Nvidia official legacy driver list] and check whether your device is supported by the 470, 390 or 340 branches. If so, you can use the corresponding <code>legacy_470</code>, <code>legacy_390</code> or <code>legacy_340</code> driver. For a full list of options, consult the [https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/os-specific/linux/nvidia-x11/default.nix nvidia-x11 module repository].
 
{{note|As of early March 2024 the <code>production</code> driver has been updated from <code>535</code> to <code>550</code>. This is a breaking change for some people, especially those on Wayland.
To resolve this, follow the steps under [[Nvidia#Running the new RTX SUPER on NixOS stable|Running the new RTX SUPER on NixOS stable]]}}
 
Once you've determined the correct driver version, note it down; you'll need it in the next step.


== Modifying NixOS configuration ==
== Modifying NixOS configuration ==
Line 53: Line 33:
{
{


   # Enable OpenGL
   # Enable graphics driver in NixOS unstable/NixOS 24.11
   hardware.opengl = {
   hardware.graphics.enable = true;
    enable = true;
  # The same as above but for NixOS 23.11
    driSupport = true;
  #hardware.opengl = {
    driSupport32Bit = true;
  #  enable = true;
   };
  #  driSupport = true;
   #};


   # Load "nvidia" driver for Xorg and Wayland
   # Load "nvidia" driver for Xorg and Wayland
Line 84: Line 65:
     # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus  
     # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus  
     # Only available from driver 515.43.04+
     # Only available from driver 515.43.04+
     # Currently alpha-quality/buggy, so false is currently the recommended setting.
     # Currently "beta quality", so false is currently the recommended setting.
     open = false;
     open = false;


Line 98: Line 79:
</nowiki>}}
</nowiki>}}


== Laptop configuration: hybrid graphics (Nvidia Optimus PRIME) ==
=== Determining the correct driver version ===
 
You might need to determine the appropriate driver version for your card. Some of the options available are:
 
<syntaxhighlight lang="nix">
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;      # (390 on i686, else production)
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.beta;        # (555)
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.production;  # (installs 550)
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.vulkan_beta; # (550, but different)
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_470;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_390;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.legacy_340;
</syntaxhighlight>
 
Out of the above, <code>stable</code> and <code>beta</code> will work for the latest RTX cards and some lower cards so long as they're not considered "legacy" by Nvidia. For "legacy" cards, you can consult the [https://www.nvidia.com/en-us/drivers/unix/legacy-gpu/ Nvidia official legacy driver list] and check whether your device is supported by the 470, 390 or 340 branches. If so, you can use the corresponding <code>legacy_470</code>, <code>legacy_390</code> or <code>legacy_340</code> driver. For a full list of options, consult the [https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/os-specific/linux/nvidia-x11/default.nix nvidia-x11 module repository].
 
{{note|As of early March 2024 the <code>production</code> driver has been updated from <code>535</code> to <code>550</code>. This is a breaking change for some people, especially those on Wayland.
To resolve this, follow the steps under [[Nvidia#Running the new RTX SUPER on NixOS stable|Running the new RTX SUPER on NixOS stable]]}}
 
Once you've determined the correct driver version, note it down; you'll need it in the next step.
 
== Laptop configuration: hybrid graphics (Optimus PRIME) ==


In order to correctly finish configuring your Nvidia graphics driver, you must follow the below steps, which differ depending on whether or not you are using a hybrid graphics setup or not. A laptop with hybrid graphics possesses both an integrated GPU (often part of the central processor) and a discrete, more powerful Nvidia GPU, typically for performance-intensive tasks. This dual-GPU setup allows for power-saving during basic tasks and higher graphics performance when needed.
In order to correctly finish configuring your Nvidia graphics driver, you must follow the below steps, which differ depending on whether or not you are using a hybrid graphics setup or not. A laptop with hybrid graphics possesses both an integrated GPU (often part of the central processor) and a discrete, more powerful Nvidia GPU, typically for performance-intensive tasks. This dual-GPU setup allows for power-saving during basic tasks and higher graphics performance when needed.
Line 104: Line 106:
'''Nvidia Optimus PRIME''' is a technology developed by Nvidia to optimize the power consumption and performance of laptops equipped with their GPUs. It seamlessly switches between the integrated graphics, usually from Intel, for lightweight tasks to save power, and the discrete Nvidia GPU for performance-intensive tasks like gaming or video editing. By dynamically balancing graphics power and battery life, Optimus provides the best of both worlds, ensuring that users get longer battery life without sacrificing graphical performance.
'''Nvidia Optimus PRIME''' is a technology developed by Nvidia to optimize the power consumption and performance of laptops equipped with their GPUs. It seamlessly switches between the integrated graphics, usually from Intel, for lightweight tasks to save power, and the discrete Nvidia GPU for performance-intensive tasks like gaming or video editing. By dynamically balancing graphics power and battery life, Optimus provides the best of both worlds, ensuring that users get longer battery life without sacrificing graphical performance.


=== Configuring Optimus PRIME: bus ID values (mandatory) ===
=== Optimus PRIME: bus ID values (mandatory) ===


Before we can continue, we must first determine the bus ID values for both your Nvidia and Intel and AMD GPUs. This step will be essential regardless of which configuration you later adopt.
Before we can continue, we must first determine the bus ID values for both your Nvidia and Intel and AMD GPUs. This step will be essential regardless of which configuration you later adopt.
Line 153: Line 155:
</nowiki>}}
</nowiki>}}


=== Optimus PRIME option A: offload mode ===
=== Optimus PRIME modes ===


''Offload mode is available in NixOS 20.09 and higher, and requires an Nvidia card of the Turing generation or newer, an Intel chipset from the Coffee Lake generation or newer, or an AMD Ryzen CPU like the 5800H .''
==== Offload mode ====
 
:''Offload mode is available in NixOS 20.09 and higher, and requires an Nvidia card of the Turing generation or newer, an Intel chipset from the Coffee Lake generation or newer, or an AMD Ryzen CPU like the 5800H .''


Offload mode puts your Nvidia GPU to sleep and lets the Intel GPU handle all tasks, except if you call the Nvidia GPU specifically by "offloading" an application to it. For example, you can run your laptop normally and it will use the energy-efficient Intel GPU all day, and then you can offload a game from Steam onto the Nvidia GPU to make the Nvidia GPU run that game only. For many, this is the most desirable option.
Offload mode puts your Nvidia GPU to sleep and lets the Intel GPU handle all tasks, except if you call the Nvidia GPU specifically by "offloading" an application to it. For example, you can run your laptop normally and it will use the energy-efficient Intel GPU all day, and then you can offload a game from Steam onto the Nvidia GPU to make the Nvidia GPU run that game only. For many, this is the most desirable option.
Line 186: Line 190:
</nowiki>}}
</nowiki>}}


=== Optimus PRIME option B: sync mode ===
==== Sync mode ====


Enabling PRIME sync introduces better performance and greatly reduces screen tearing, at the expense of higher power consumption since the Nvidia GPU will not go to sleep completely unless called for, as is the case in Offload Mode. It may also cause its own issues in rare cases. '''PRIME Sync and Offload Mode cannot be enabled at the same time.'''
Enabling PRIME sync introduces better performance and greatly reduces screen tearing, at the expense of higher power consumption since the Nvidia GPU will not go to sleep completely unless called for, as is the case in Offload Mode. It may also cause its own issues in rare cases. '''PRIME Sync and Offload Mode cannot be enabled at the same time.'''
Line 205: Line 209:
</nowiki>}}
</nowiki>}}


=== Optimus PRIME option C: reverse sync mode (experimental) ===
==== Reverse sync mode (experimental) ====


This feature is relatively new and may not work properly on all systems ([https://forums.developer.nvidia.com/t/the-all-new-outputsink-feature-aka-reverse-prime/129828 see discussion]). It is only available on driver 460.39 or newer. Reverse sync only works with <code>services.xserver.displayManager.setupCommands</code> compatible Display Managers (LightDM, GDM and SDDM).
This feature is relatively new and may not work properly on all systems ([https://forums.developer.nvidia.com/t/the-all-new-outputsink-feature-aka-reverse-prime/129828 see discussion]). It is only available on driver 460.39 or newer. Reverse sync only works with <code>services.xserver.displayManager.setupCommands</code> compatible Display Managers (LightDM, GDM and SDDM).
Line 298: Line 302:


{
{
  # Enable graphics driver in NixOS unstable/NixOS 24.11
  hardware.graphics.enable = true;
  # The same as above but for NixOS 23.11
  #hardware.opengl = {
  #  enable = true;
  #  driSupport = true;
  #};


# Enable OpenGL
   # Load nvidia driver for Xorg and Wayland
   hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };
 
# Load nvidia driver for Xorg and Wayland
   services.xserver.videoDrivers = ["nvidia"];
   services.xserver.videoDrivers = ["nvidia"];
    
    
Line 381: Line 385:
boot.kernelParams = [ "module_blacklist=amdgpu" ];
boot.kernelParams = [ "module_blacklist=amdgpu" ];
</syntaxHighlight>
</syntaxHighlight>
= The Nvidia open driver =
The Nvidia open driver is enabled via:
<syntaxHighlight lang="nix">
services.xserver.videoDrivers = [ "nvidia" ];
hardware.nvidia.open = true;
</syntaxHighlight>
The Nvidia open driver is ''very'' similar to its proprietary sibling. Most content in the proprietary section above apply; just copy over the proprietary config above and toggle the "open" option, and you are set.
Like its proprietary sibling, it also requires some non-free userspace packages that allow software to talk to the kernel driver. As a result, you still need to enable unfree packages.
Be warned that the Nvidia open driver is considered "beta quality". Performance may be very slightly lower.


= Disable Nvidia dGPU completely =
= Disable Nvidia dGPU completely =
trusted
602

edits