Nvidia: Difference between revisions

(Update configuration file with comment)
(Copyedit 1st heading & 1st sentence, link unfree software, case in headings throughout)
Line 1: Line 1:
= NixOS Manual =
= Proprietary drivers =
First check out the [https://nixos.org/manual/nixos/stable/#sec-x11-graphics-cards-nvidia method] in the NixOS Manual.  
Nvidia's proprietary drivers are not enabled by default. To overcome this, refer to the [https://nixos.org/manual/nixos/stable/#sec-x11-graphics-cards-nvidia method] in the NixOS Manual.  


= Installing Nvidia Drivers on NixOS =
= Installing Nvidia drivers on NixOS =


NixOS uses a functional package management approach, which necessitates specific procedures for driver installation. When considering NVIDIA GPU drivers in a Linux environment, the installation process can be more complex compared to AMD and Intel. This complexity arises primarily because NVIDIA's official drivers are closed source and not typically bundled with many distributions. This document outlines the technical steps required to install NVIDIA GPU drivers on NixOS, factoring in both the unique nature of NixOS and the proprietary status of NVIDIA's drivers.
NixOS uses a functional package management approach, which necessitates specific procedures for driver installation. When considering NVIDIA GPU drivers in a Linux environment, the installation process can be more complex compared to AMD and Intel. This complexity arises primarily because NVIDIA's official drivers are closed source and not typically bundled with many distributions. This document outlines the technical steps required to install NVIDIA GPU drivers on NixOS, factoring in both the unique nature of NixOS and the proprietary status of NVIDIA's drivers.


== Enable Unfree Software Repositories ==  
== Enable unfree software repositories ==  


Make sure to allow 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 ==
== Determining the correct driver version ==


You will next need to determine the appropriate driver version for your card. The following options are available:
You will next need to determine the appropriate driver version for your card. The following options are available:
Line 27: Line 27:


{{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.
{{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]]}}
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.
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 ==


Ensure that the following is in your NixOS configuration file (customizing as you prefer):  
Ensure that the following is in your NixOS configuration file (customizing as you prefer):  
Line 90: Line 90:
</nowiki>}}
</nowiki>}}


== Laptop Configuration: Hybrid Graphics (Nvidia Optimus PRIME) ==
== Laptop configuration: hybrid graphics (Nvidia 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 from 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.


'''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) ===
=== Configuring Optimus PRIME: bus ID values (mandatory) ===


Before we can continue, we must mandatorily first determine the Bus ID values for both your Nvidia and Intel 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 GPUs. This step will be essential regardless of which configuration you later adopt.


First, install the <code>lshw</code> package in order to be able to use the <code>lshw</code> command, then run:
First, install the <code>lshw</code> package in order to be able to use the <code>lshw</code> command, then run:
Line 107: Line 107:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
*-display                
*-display
description: i915drmfb
description: i915drmfb
physical id: 0
physical id: 0
Line 144: Line 144:
</nowiki>}}
</nowiki>}}


=== Optimus PRIME Option A: Offload Mode ===
=== Optimus PRIME option A: offload mode ===


''Offload Mode is available in NixOS 20.09 and higher, and requires an Nvidia card of the Turing generation or newer, and an Intel chipset from the Coffee Lake generation or newer.''
''Offload mode is available in NixOS 20.09 and higher, and requires an Nvidia card of the Turing generation or newer, and an Intel chipset from the Coffee Lake generation or newer.''


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 176: Line 176:
</nowiki>}}
</nowiki>}}


=== Optimus PRIME Option B: Sync Mode ===
=== Optimus PRIME option B: 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 194: Line 194:
</nowiki>}}
</nowiki>}}


=== Optimus Option C: Reverse Sync Mode (Experimental) ===
=== Optimus PRIME option C: 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 also only available on driver 460.39 or newer. Reverse sync also 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).


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
Line 212: Line 212:
</nowiki>}}
</nowiki>}}


== Useful Tips ==
== Useful tips ==


=== Check NixosHardware ===
=== Check nixos-hardware ===
You should check the [https://github.com/NixOS/nixos-hardware nixoshardware] GitHub repository. It is possible that someone already wrote a hardware configuration for your device and that usually takes care of drivers. If so, follow the upstream documentation to enable the required modules.   
You should check the [https://github.com/NixOS/nixos-hardware nixos-hardware] GitHub repository. It is possible that someone already wrote a hardware configuration for your device and that usually takes care of drivers. If so, follow the upstream documentation to enable the required modules.   


=== Multiple Boot Configurations ===
=== Multiple boot configurations ===
Imagine you have a laptop that you mostly use in clamshell mode (docked, connected to an external display and plugged into a charger) but that you sometimes use on the go.
Imagine you have a laptop that you mostly use in clamshell mode (docked, connected to an external display and plugged into a charger) but that you sometimes use on the go.


Line 253: Line 253:
See the [[CUDA]] wiki page.
See the [[CUDA]] wiki page.


=== Using Steam in Offload Mode ===
=== Using Steam in offload mode ===
In order to automatically launch Steam in offload mode, you need to add the following to your <code>~/.bashrc</code>:
In order to automatically launch Steam in offload mode, you need to add the following to your <code>~/.bashrc</code>:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 275: Line 275:
Then restart your graphical environment session (or simply reboot).
Then restart your graphical environment session (or simply reboot).


=== Running the new RTX SUPER on nixos stable ===
=== Running the new RTX SUPER on NixOS stable ===


The new RTX Super are not supported by the 545 driver. On Nixos stable, you want to use the 535 driver that come from unstable branch or the 550 (beta).
The new RTX Super cards are not supported by the 545 driver. On NixOS stable, you want to use the 535 driver that come from unstable branch or the 550 (beta).
To do that you need to manually call the driver you want in your config.
To do that you need to manually call the driver you want in your config.
Check on this link to choose the driver you want and change your config accordingly :
Check on this link to choose the driver you want and change your config accordingly :
Line 330: Line 330:
== Troubleshooting ==
== Troubleshooting ==


=== Booting to Text Mode ===
=== Booting to text mode ===
If you encounter the problem of booting to text mode you might try adding the Nvidia kernel module manually with:
If you encounter the problem of booting to text mode you might try adding the Nvidia kernel module manually with:


Line 338: Line 338:
</syntaxHighlight>
</syntaxHighlight>


=== Screen Tearing Issues ===
=== Screen tearing issues ===


First, try to switch to PRIME Sync Mode, as described above. If that doesn't work, try forcing a composition pipeline.
First, try to switch to PRIME sync mode, as described above. If that doesn't work, try forcing a composition pipeline.


{{note|Forcing a full composition pipeline has been reported to reduce the performance of some OpenGL applications and may produce issues in WebGL. It also drastically increases the time the driver needs to clock down after load.}}
{{note|Forcing a full composition pipeline has been reported to reduce the performance of some OpenGL applications and may produce issues in WebGL. It also drastically increases the time the driver needs to clock down after load.}}
Line 348: Line 348:
</nowiki>}}
</nowiki>}}


=== Flickering Issues with Picom  ===
=== Flickering with Picom  ===
{{file|~/.config/picom/picom.conf|conf|<nowiki>
{{file|~/.config/picom/picom.conf|conf|<nowiki>
unredir-if-possible = false;
unredir-if-possible = false;
Line 355: Line 355:
</nowiki>}}
</nowiki>}}


=== Graphical Corruption and System Crashes on Suspend/Resume ===
=== Graphical corruption and system crashes on suspend/resume ===
<code>powerManagement.enable = true</code> can sometimes fix this, but is itself unstable and is known to cause suspend issues.
<code>powerManagement.enable = true</code> can sometimes fix this, but is itself unstable and is known to cause suspend issues.


If you have a modern Nvidia GPU (Turing [https://en.wikipedia.org/wiki/Turing_(microarchitecture)#Products_using_Turing] or later), you may also want to investigate the <code>hardware.nvidia.powerManagement.finegrained</code> option: [https://download.nvidia.com/XFree86/Linux-x86_64/460.73.01/README/dynamicpowermanagement.html]
If you have a modern Nvidia GPU (Turing [https://en.wikipedia.org/wiki/Turing_(microarchitecture)#Products_using_Turing] or later), you may also want to investigate the <code>hardware.nvidia.powerManagement.finegrained</code> option: [https://download.nvidia.com/XFree86/Linux-x86_64/460.73.01/README/dynamicpowermanagement.html]


=== Black Screen or Nothing Works on Laptops ===
=== Black screen or 'nothing works' on laptops ===
The kernel module <code>i915</code> for intel or <code>amdgpu</code> for AMD may interfere with the Nvidia driver. This may result in a black screen when switching to the virtual terminal, or when exiting the X session. A possible workaround is to disable the integrated GPU by blacklisting the module, using the following configuration option (see also [https://discourse.nixos.org/t/nvidia-gpu-and-i915-kernel-module/21307/3]):
The kernel module<code>i915</code>for Intel or<code>amdgpu</code>for AMD may interfere with the Nvidia driver. This may result in a black screen when switching to the virtual terminal, or when exiting the X session. A possible workaround is to disable the integrated GPU by blacklisting the module, using the following configuration option (see also [https://discourse.nixos.org/t/nvidia-gpu-and-i915-kernel-module/21307/3]):


<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
Line 372: Line 372:
= Disable Nvidia dGPU completely =
= Disable Nvidia dGPU completely =


completely disable dGPU, saving battery. Probably not all configurations and module blacklists are required but this worked successfully
It's possible to completely disable the dGPU, saving battery. Probably not all configurations and module blacklists are required but this worked successfully:


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>