NVIDIA: Difference between revisions

imported>Qmuki
fix typo that results in path not found
imported>Gerg-L
No edit summary
Line 3: Line 3:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
{
  # Make sure opengl is enabled
  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };
   # NVIDIA drivers are unfree.
   # NVIDIA drivers are unfree.
   nixpkgs.config.allowUnfree = true;
   nixpkgs.config.allowUnfreePredicate = pkg:
    builtins.elem (lib.getName pkg) [
      "nvidia-x11"
    ];
 
  # Tell Xorg to use the nvidia driver
  services.xserver.videoDrivers = ["nvidia"];
 
  hardware.nvidia = {
 
    # Modesetting is needed for most wayland compositors
    modesetting.enable = true;


  services.xserver.videoDrivers = [ "nvidia" ];
    # Use the open source version of the kernel module
  hardware.opengl.enable = true;
    open = true;


  # Optionally, you may need to select the appropriate driver version for your specific GPU.
    # Enable the nvidia settings menu
  hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;
    nvidiaSettings = true;


  # nvidia-drm.modeset=1 is required for some wayland compositors, e.g. sway
    # Optionally, you may need to select the appropriate driver version for your specific GPU.
   hardware.nvidia.modesetting.enable = true;
    package = config.boot.kernelPackages.nvidiaPackages.stable;
   };
   ...
   ...
}
}
Line 55: Line 75:
=== Nvidia PRIME ===
=== Nvidia PRIME ===


Official solution by nvidia.  Currently, reverse PRIME does not work. The consequence of this is that if you have a special laptop configuration where external display ports are only exposed to the dedicated GPU, then running in offload mode  [https://archived.forum.manjaro.org/t/nvidia-render-offloading-help-getting-external-monitor-working/99430/23 will not allow you to use those display ports for external monitors].  If you wish to use the external monitors in that particular case, you have to use sync mode.
The Official solution by nvidia.


==== offload mode ====
==== offload mode ====
Line 150: Line 170:


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{ pkgs, ... }:
let
  nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" ''
    export __NV_PRIME_RENDER_OFFLOAD=1
    export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
    export __GLX_VENDOR_LIBRARY_NAME=nvidia
    export __VK_LAYER_NV_optimus=NVIDIA_only
    exec "$@"
  '';
in
{
{
   environment.systemPackages = [ nvidia-offload ];
   services.xserver.videoDrivers = ["nvidia"];


  services.xserver.videoDrivers = [ "nvidia" ];
   hardware.nvidia.prime = {
   hardware.nvidia.prime = {
     offload.enable = true;
     offload = {
      enable = true;
      enableOffloadCmd = true;
    };


    # Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA
     intelBusId = "PCI:0:2:0";
     intelBusId = "PCI:0:2:0";
    # Bus ID of the NVIDIA GPU. You can find it using lspci, either under 3D or VGA
     nvidiaBusId = "PCI:1:0:0";
     nvidiaBusId = "PCI:1:0:0";
   };
   };
Line 185: Line 193:
     external-display.configuration = {
     external-display.configuration = {
       system.nixos.tags = [ "external-display" ];
       system.nixos.tags = [ "external-display" ];
       hardware.nvidia.prime.offload.enable = lib.mkForce false;
       hardware.nvidia = {
      hardware.nvidia.powerManagement.enable = lib.mkForce false;
        prime.offload.enable = lib.mkForce false;
        powerManagement.enable = lib.mkForce false;
      };
     };
     };
   };
   };
Line 231: Line 241:
* Black screen after system upgrade (e.g. <code>nixos-rebuild switch</code>; use <code>nixos-rebuild boot</code> instead and reboot)
* Black screen after system upgrade (e.g. <code>nixos-rebuild switch</code>; use <code>nixos-rebuild boot</code> instead and reboot)
* No video playback acceleration available (vaapi)
* No video playback acceleration available (vaapi)
===== Example for NixOS 20.03 =====


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
Line 238: Line 246:
   hardware.nvidia.modesetting.enable = true;
   hardware.nvidia.modesetting.enable = true;
   services.xserver.videoDrivers = [ "nvidia" ];
   services.xserver.videoDrivers = [ "nvidia" ];
   hardware.nvidia.optimus_prime = {
   hardware.nvidia.prime = {
     enable = true;
     sync.enable = true;


    # Bus ID of the NVIDIA GPU. You can find it using lspci, either under 3D or VGA
     nvidiaBusId = "PCI:1:0:0";
     nvidiaBusId = "PCI:1:0:0";
    # Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA
     intelBusId = "PCI:0:2:0";
     intelBusId = "PCI:0:2:0";
   };
   };
Line 250: Line 255:
</nowiki>}}
</nowiki>}}


===== Example for NixOS 20.09/unstable =====
==== reverse sync mode ====
Warning: This feature is relatively new, depending on your system this might work poorly. AMD support, especially so. See: https://forums.developer.nvidia.com/t/the-all-new-outputsink-feature-aka-reverse-prime/129828
 
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>
{
{
   services.xserver.videoDrivers = [ "nvidia" ];
   services.xserver.videoDrivers = ["nvidia"];
 
  hardware.nvidia = {
    # Modesetting should be enabled to prevent screen tearing
    modesetting.enable = true;
 
    # Reverse sync is not compatible with the open source kernel module
    open = false;
 
    prime = {
      reverseSync.enable = true;


  hardware.nvidia.prime = {
      #enable if using an external GPU
    sync.enable = true;
      allowExternalGpu = false;


    # Bus ID of the NVIDIA GPU. You can find it using lspci, either under 3D or VGA
      intelBusId = "PCI:0:2:0";
    nvidiaBusId = "PCI:1:0:0";


    # Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA
      nvidiaBusId = "PCI:1:0:0";
    intelBusId = "PCI:0:2:0";
    };
   };
   };
}
}