Nvidia: Difference between revisions

No edit summary
m Correct broken bullet points
 
(16 intermediate revisions by 7 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. Better 3D performance than nouveau.
* 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.
(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 =
= The proprietary driver =
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;


     # Enable the Nvidia settings menu,
     # Enable the Nvidia settings menu,
# accessible via `nvidia-settings`.
    # accessible via `nvidia-settings`.
     nvidiaSettings = true;
     nvidiaSettings = true;


Line 97: Line 78:
}
}
</nowiki>}}
</nowiki>}}
=== 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) ==
== Laptop configuration: hybrid graphics (Optimus PRIME) ==
Line 140: Line 142:
</syntaxhighlight>
</syntaxhighlight>


Note the two values under "bus info" above, which may differ from laptop to laptop. Our Nvidia Bus ID is <code>0e:00.0</code> and our Intel Bus ID is <code>00:02.0</code>. Watch out for the formatting; convert them from hexadecimal to decimal, remove the padding (leading zeroes), replace the dot with a colon, then add them like this:
Note the two values under "bus info" above, which may differ from laptop to laptop. Our Nvidia Bus ID is <code>0e:00.0</code> and our Intel Bus ID is <code>00:02.0</code>.
 
{{Warning|Watch out for the formatting; convert the values from hexadecimal to decimal, remove the padding (leading zeroes), replace the dot with a colon.}}{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
{
hardware.nvidia.prime = {
hardware.nvidia.prime = {
Line 288: Line 289:


Then restart your graphical environment session (or simply reboot).
Then restart your graphical environment session (or simply reboot).
=== Running Specific NVIDIA Driver Versions ===
To run a specific version of the NVIDIA driver in NixOS, you can customize your configuration by specifying the desired version along with the corresponding SHA256 hashes. Below is an example configuration for using NVIDIA driver version `555.58.02`:
{{file|/etc/nixos/nvidia.nix|nix|<nowiki>
  package = config.boot.kernelPackages.nvidiaPackages.mkDriver {
    version = "555.58.02";
    sha256_64bit = "sha256-xctt4TPRlOJ6r5S54h5W6PT6/3Zy2R4ASNFPu8TSHKM=";
    sha256_aarch64 = "sha256-xctt4TPRlOJ6r5S54h5W6PT6/3Zy2R4ASNFPu8TSHKM=";
    openSha256 = "sha256-ZpuVZybW6CFN/gz9rx+UJvQ715FZnAOYfHn5jt5Z2C8=";
    settingsSha256 = "sha256-ZpuVZybW6CFN/gz9rx+UJvQ715FZnAOYfHn5jt5Z2C8=";
    persistencedSha256 = lib.fakeSha256;
  };
</nowiki>}}
In this configuration:
* Replace `version` with the desired driver version.
* Update the SHA256 hashes to match the new version you want to use.
* After updating the configuration, run <code>sudo nixos-rebuild switch</code> to apply the changes and load the specified NVIDIA driver version.
This allows you to pin the specific driver version being used in your NixOS installation.


=== Running the new RTX SUPER on NixOS stable ===
=== Running the new RTX SUPER on NixOS stable ===
Line 297: Line 321:


{{file|/etc/nixos/nvidia.nix|nix|<nowiki>
{{file|/etc/nixos/nvidia.nix|nix|<nowiki>
{ pkgs, config, libs, ... }:
{
  pkgs,
  config,
  ...
}:


{
{
  # 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 = {
   services.xserver.videoDrivers = [ "nvidia" ];
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };


# Load nvidia driver for Xorg and Wayland
  services.xserver.videoDrivers = ["nvidia"];
 
   hardware.nvidia.modesetting.enable = true;
   hardware.nvidia.modesetting.enable = true;
   hardware.nvidia.powerManagement.enable = false;
   hardware.nvidia.powerManagement.enable = false;
Line 316: Line 344:
   hardware.nvidia.open = false;
   hardware.nvidia.open = false;
   hardware.nvidia.nvidiaSettings = true;
   hardware.nvidia.nvidiaSettings = true;
# Special config to load the latest (535 or 550) driver for the support of the 4070 SUPER
  # Special config to load the latest (535 or 550) driver for the support of the 4070 SUPER
   hardware.nvidia.package = let  
   hardware.nvidia.package =
  rcu_patch = pkgs.fetchpatch {
    let
    url = "https://github.com/gentoo/gentoo/raw/c64caf53/x11-drivers/nvidia-drivers/files/nvidia-drivers-470.223.02-gpl-pfn_valid.patch";
      rcu_patch = pkgs.fetchpatch {
    hash = "sha256-eZiQQp2S/asE7MfGvfe6dA/kdCvek9SYa/FFGp24dVg=";
        url = "https://github.com/gentoo/gentoo/raw/c64caf53/x11-drivers/nvidia-drivers/files/nvidia-drivers-470.223.02-gpl-pfn_valid.patch";
  };
        hash = "sha256-eZiQQp2S/asE7MfGvfe6dA/kdCvek9SYa/FFGp24dVg=";
in config.boot.kernelPackages.nvidiaPackages.mkDriver {
      };
    version = "535.154.05";
    in
    sha256_64bit = "sha256-fpUGXKprgt6SYRDxSCemGXLrEsIA6GOinp+0eGbqqJg=";
    config.boot.kernelPackages.nvidiaPackages.mkDriver {
    sha256_aarch64 = "sha256-G0/GiObf/BZMkzzET8HQjdIcvCSqB1uhsinro2HLK9k=";
      version = "535.154.05";
    openSha256 = "sha256-wvRdHguGLxS0mR06P5Qi++pDJBCF8pJ8hr4T8O6TJIo=";
      sha256_64bit = "sha256-fpUGXKprgt6SYRDxSCemGXLrEsIA6GOinp+0eGbqqJg=";
    settingsSha256 = "sha256-9wqoDEWY4I7weWW05F4igj1Gj9wjHsREFMztfEmqm10=";
      sha256_aarch64 = "sha256-G0/GiObf/BZMkzzET8HQjdIcvCSqB1uhsinro2HLK9k=";
    persistencedSha256 = "sha256-d0Q3Lk80JqkS1B54Mahu2yY/WocOqFFbZVBh+ToGhaE=";
      openSha256 = "sha256-wvRdHguGLxS0mR06P5Qi++pDJBCF8pJ8hr4T8O6TJIo=";
      settingsSha256 = "sha256-9wqoDEWY4I7weWW05F4igj1Gj9wjHsREFMztfEmqm10=";
      persistencedSha256 = "sha256-d0Q3Lk80JqkS1B54Mahu2yY/WocOqFFbZVBh+ToGhaE=";


    #version = "550.40.07";
      #version = "550.40.07";
    #sha256_64bit = "sha256-KYk2xye37v7ZW7h+uNJM/u8fNf7KyGTZjiaU03dJpK0=";
      #sha256_64bit = "sha256-KYk2xye37v7ZW7h+uNJM/u8fNf7KyGTZjiaU03dJpK0=";
    #sha256_aarch64 = "sha256-AV7KgRXYaQGBFl7zuRcfnTGr8rS5n13nGUIe3mJTXb4=";
      #sha256_aarch64 = "sha256-AV7KgRXYaQGBFl7zuRcfnTGr8rS5n13nGUIe3mJTXb4=";
    #openSha256 = "sha256-mRUTEWVsbjq+psVe+kAT6MjyZuLkG2yRDxCMvDJRL1I=";
      #openSha256 = "sha256-mRUTEWVsbjq+psVe+kAT6MjyZuLkG2yRDxCMvDJRL1I=";
    #settingsSha256 = "sha256-c30AQa4g4a1EHmaEu1yc05oqY01y+IusbBuq+P6rMCs=";
      #settingsSha256 = "sha256-c30AQa4g4a1EHmaEu1yc05oqY01y+IusbBuq+P6rMCs=";
    #persistencedSha256 = "sha256-11tLSY8uUIl4X/roNnxf5yS2PQvHvoNjnd2CB67e870=";
      #persistencedSha256 = "sha256-11tLSY8uUIl4X/roNnxf5yS2PQvHvoNjnd2CB67e870=";


    patches = [ rcu_patch ];
      patches = [ rcu_patch ];
};
    };
}
}
</nowiki>}}
</nowiki>}}
Line 384: Line 414:
</syntaxHighlight>
</syntaxHighlight>


= The nvidia-open driver =
= The Nvidia open driver =
The Nvidia open driver is enabled via:
The Nvidia open driver is enabled via:
<pre>
<syntaxHighlight lang="nix">
services.xserver.videoDrivers = [ "nvidia" ];
services.xserver.videoDrivers = [ "nvidia" ];
hardware.nvidia.open = true;
hardware.nvidia.open = true;
</pre>
</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.


Really, just copy over the proprietary config above and toggle the "open" option. A lot of the userspace parts are shared, so you still need to enable unfree.
(Update to be incorporated: Nvidia has [https://developer.nvidia.com/blog/nvidia-transitions-fully-towards-open-source-gpu-kernel-modules/ announced in July 2024] that the upcoming version R560 will "fully transisition" towards the open-source kernel module. This means that the default kernel module installed by Nvidia scripts will be the open-source one. This is justified as the open-source driver is now as stable and performant as (if not more than) the closed-sourced driver. The new driver only applies to Turing and later GPUs; older hardware with Maxwell, Pascal, or Volta will still require the proprietary version.)


Not everything will work, and it will probably not be as stable as its proprietary sibling. Performance may be lower.


= Disable Nvidia dGPU completely =
= Disable Nvidia dGPU completely =