From 5d21e8c92b1afc3f6521d5190ea7b8ed748f805a Mon Sep 17 00:00:00 2001 From: Edmund Wu Date: Tue, 13 Aug 2019 22:39:26 -0400 Subject: [PATCH 1/7] nixos/nvidia: remove lib references --- nixos/modules/hardware/video/nvidia.nix | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index fcb30187fa2fb..b365ff62d5090 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -39,8 +39,8 @@ in { options = { - hardware.nvidia.modesetting.enable = lib.mkOption { - type = lib.types.bool; + hardware.nvidia.modesetting.enable = mkOption { + type = types.bool; default = false; description = '' Enable kernel modesetting when using the NVIDIA proprietary driver. @@ -52,8 +52,8 @@ in ''; }; - hardware.nvidia.optimus_prime.enable = lib.mkOption { - type = lib.types.bool; + hardware.nvidia.optimus_prime.enable = mkOption { + type = types.bool; default = false; description = '' Enable NVIDIA Optimus support using the NVIDIA proprietary driver via PRIME. @@ -79,16 +79,16 @@ in ''; }; - hardware.nvidia.optimus_prime.allowExternalGpu = lib.mkOption { - type = lib.types.bool; + hardware.nvidia.optimus_prime.allowExternalGpu = mkOption { + type = types.bool; default = false; description = '' Configure X to allow external NVIDIA GPUs when using optimus. ''; }; - hardware.nvidia.optimus_prime.nvidiaBusId = lib.mkOption { - type = lib.types.str; + hardware.nvidia.optimus_prime.nvidiaBusId = mkOption { + type = types.str; default = ""; example = "PCI:1:0:0"; description = '' @@ -97,8 +97,8 @@ in ''; }; - hardware.nvidia.optimus_prime.intelBusId = lib.mkOption { - type = lib.types.str; + hardware.nvidia.optimus_prime.intelBusId = mkOption { + type = types.str; default = ""; example = "PCI:0:2:0"; description = '' @@ -179,7 +179,7 @@ in hardware.opengl.package32 = nvidia_libs32; environment.systemPackages = [ nvidia_x11.bin nvidia_x11.settings ] - ++ lib.filter (p: p != null) [ nvidia_x11.persistenced ]; + ++ filter (p: p != null) [ nvidia_x11.persistenced ]; systemd.tmpfiles.rules = optional config.virtualisation.docker.enableNvidia "L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin" @@ -190,7 +190,7 @@ in # nvidia-uvm is required by CUDA applications. boot.kernelModules = [ "nvidia-uvm" ] ++ - lib.optionals config.services.xserver.enable [ "nvidia" "nvidia_modeset" "nvidia_drm" ]; + optionals config.services.xserver.enable [ "nvidia" "nvidia_modeset" "nvidia_drm" ]; # If requested enable modesetting via kernel parameter. boot.kernelParams = optional cfg.modesetting.enable "nvidia-drm.modeset=1"; From aca9ffe893bd7346c32b38c50eaee3022668c998 Mon Sep 17 00:00:00 2001 From: Edmund Wu Date: Wed, 14 Aug 2019 08:15:43 -0400 Subject: [PATCH 2/7] nixos/nvidia: optimus_prime -> prime.sync --- nixos/modules/hardware/video/nvidia.nix | 44 +++++++++++++++---------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index b365ff62d5090..88ae088bb28a6 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -34,10 +34,18 @@ let enabled = nvidia_x11 != null; cfg = config.hardware.nvidia; - optimusCfg = cfg.optimus_prime; + syncCfg = cfg.prime.sync; in { + imports = + [ + (mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "enable" ] [ "hardware" "nvidia" "prime" "sync" "enable" ]) + (mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "allowExternalGpu" ] [ "hardware" "nvidia" "prime" "sync" "allowExternalGpu" ]) + (mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "nvidiaBusId" ] [ "hardware" "nvidia" "prime" "sync" "nvidiaBusId" ]) + (mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "intelBusId" ] [ "hardware" "nvidia" "prime" "sync" "intelBusId" ]) + ]; + options = { hardware.nvidia.modesetting.enable = mkOption { type = types.bool; @@ -46,13 +54,13 @@ in Enable kernel modesetting when using the NVIDIA proprietary driver. Enabling this fixes screen tearing when using Optimus via PRIME (see - . This is not enabled + . This is not enabled by default because it is not officially supported by NVIDIA and would not work with SLI. ''; }; - hardware.nvidia.optimus_prime.enable = mkOption { + hardware.nvidia.prime.sync.enable = mkOption { type = types.bool; default = false; description = '' @@ -66,8 +74,8 @@ in be the only driver there. If this is enabled, then the bus IDs of the NVIDIA and Intel GPUs have to be - specified ( and - ). + specified ( and + ). If you enable this, you may want to also enable kernel modesetting for the NVIDIA driver () in order @@ -79,7 +87,7 @@ in ''; }; - hardware.nvidia.optimus_prime.allowExternalGpu = mkOption { + hardware.nvidia.prime.sync.allowExternalGpu = mkOption { type = types.bool; default = false; description = '' @@ -87,7 +95,7 @@ in ''; }; - hardware.nvidia.optimus_prime.nvidiaBusId = mkOption { + hardware.nvidia.prime.sync.nvidiaBusId = mkOption { type = types.str; default = ""; example = "PCI:1:0:0"; @@ -97,7 +105,7 @@ in ''; }; - hardware.nvidia.optimus_prime.intelBusId = mkOption { + hardware.nvidia.prime.sync.intelBusId = mkOption { type = types.str; default = ""; example = "PCI:0:2:0"; @@ -116,8 +124,8 @@ in } { - assertion = !optimusCfg.enable || - (optimusCfg.nvidiaBusId != "" && optimusCfg.intelBusId != ""); + assertion = !syncCfg.enable || + (syncCfg.nvidiaBusId != "" && syncCfg.intelBusId != ""); message = '' When NVIDIA Optimus via PRIME is enabled, the GPU bus IDs must configured. ''; @@ -139,33 +147,33 @@ in services.xserver.drivers = singleton { name = "nvidia"; modules = [ nvidia_x11.bin ]; - deviceSection = optionalString optimusCfg.enable + deviceSection = optionalString syncCfg.enable '' - BusID "${optimusCfg.nvidiaBusId}" - ${optionalString optimusCfg.allowExternalGpu "Option \"AllowExternalGpus\""} + BusID "${syncCfg.nvidiaBusId}" + ${optionalString syncCfg.allowExternalGpu "Option \"AllowExternalGpus\""} ''; screenSection = '' Option "RandRRotation" "on" - ${optionalString optimusCfg.enable "Option \"AllowEmptyInitialConfiguration\""} + ${optionalString syncCfg.enable "Option \"AllowEmptyInitialConfiguration\""} ''; }; - services.xserver.extraConfig = optionalString optimusCfg.enable + services.xserver.extraConfig = optionalString syncCfg.enable '' Section "Device" Identifier "nvidia-optimus-intel" Driver "modesetting" - BusID "${optimusCfg.intelBusId}" + BusID "${syncCfg.intelBusId}" Option "AccelMethod" "none" EndSection ''; - services.xserver.serverLayoutSection = optionalString optimusCfg.enable + services.xserver.serverLayoutSection = optionalString syncCfg.enable '' Inactive "nvidia-optimus-intel" ''; - services.xserver.displayManager.setupCommands = optionalString optimusCfg.enable '' + services.xserver.displayManager.setupCommands = optionalString syncCfg.enable '' # Added by nvidia configuration module for Optimus/PRIME. ${pkgs.xorg.xrandr}/bin/xrandr --setprovideroutputsource modesetting NVIDIA-0 ${pkgs.xorg.xrandr}/bin/xrandr --auto From e8daa1e35ca120c52f38fb08505f7f716073ead7 Mon Sep 17 00:00:00 2001 From: Edmund Wu Date: Wed, 14 Aug 2019 08:18:28 -0400 Subject: [PATCH 3/7] nixos/nvidia: prime.sync.{intel,nvidia}BusId -> prime.{intel,nvidia}BusId --- nixos/modules/hardware/video/nvidia.nix | 57 +++++++++++++------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index 88ae088bb28a6..295180d2b64e4 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -34,7 +34,8 @@ let enabled = nvidia_x11 != null; cfg = config.hardware.nvidia; - syncCfg = cfg.prime.sync; + pCfg = cfg.prime; + syncCfg = pCfg.sync; in { @@ -42,8 +43,8 @@ in [ (mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "enable" ] [ "hardware" "nvidia" "prime" "sync" "enable" ]) (mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "allowExternalGpu" ] [ "hardware" "nvidia" "prime" "sync" "allowExternalGpu" ]) - (mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "nvidiaBusId" ] [ "hardware" "nvidia" "prime" "sync" "nvidiaBusId" ]) - (mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "intelBusId" ] [ "hardware" "nvidia" "prime" "sync" "intelBusId" ]) + (mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "nvidiaBusId" ] [ "hardware" "nvidia" "prime" "nvidiaBusId" ]) + (mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "intelBusId" ] [ "hardware" "nvidia" "prime" "intelBusId" ]) ]; options = { @@ -60,6 +61,26 @@ in ''; }; + hardware.nvidia.prime.nvidiaBusId = mkOption { + type = types.str; + default = ""; + example = "PCI:1:0:0"; + description = '' + Bus ID of the NVIDIA GPU. You can find it using lspci; for example if lspci + shows the NVIDIA GPU at "01:00.0", set this option to "PCI:1:0:0". + ''; + }; + + hardware.nvidia.prime.intelBusId = mkOption { + type = types.str; + default = ""; + example = "PCI:0:2:0"; + description = '' + Bus ID of the Intel GPU. You can find it using lspci; for example if lspci + shows the Intel GPU at "00:02.0", set this option to "PCI:0:2:0". + ''; + }; + hardware.nvidia.prime.sync.enable = mkOption { type = types.bool; default = false; @@ -74,8 +95,8 @@ in be the only driver there. If this is enabled, then the bus IDs of the NVIDIA and Intel GPUs have to be - specified ( and - ). + specified ( and + ). If you enable this, you may want to also enable kernel modesetting for the NVIDIA driver () in order @@ -94,26 +115,6 @@ in Configure X to allow external NVIDIA GPUs when using optimus. ''; }; - - hardware.nvidia.prime.sync.nvidiaBusId = mkOption { - type = types.str; - default = ""; - example = "PCI:1:0:0"; - description = '' - Bus ID of the NVIDIA GPU. You can find it using lspci; for example if lspci - shows the NVIDIA GPU at "01:00.0", set this option to "PCI:1:0:0". - ''; - }; - - hardware.nvidia.prime.sync.intelBusId = mkOption { - type = types.str; - default = ""; - example = "PCI:0:2:0"; - description = '' - Bus ID of the Intel GPU. You can find it using lspci; for example if lspci - shows the Intel GPU at "00:02.0", set this option to "PCI:0:2:0". - ''; - }; }; config = mkIf enabled { @@ -125,7 +126,7 @@ in { assertion = !syncCfg.enable || - (syncCfg.nvidiaBusId != "" && syncCfg.intelBusId != ""); + (pCfg.nvidiaBusId != "" && pCfg.intelBusId != ""); message = '' When NVIDIA Optimus via PRIME is enabled, the GPU bus IDs must configured. ''; @@ -149,7 +150,7 @@ in modules = [ nvidia_x11.bin ]; deviceSection = optionalString syncCfg.enable '' - BusID "${syncCfg.nvidiaBusId}" + BusID "${pCfg.nvidiaBusId}" ${optionalString syncCfg.allowExternalGpu "Option \"AllowExternalGpus\""} ''; screenSection = @@ -164,7 +165,7 @@ in Section "Device" Identifier "nvidia-optimus-intel" Driver "modesetting" - BusID "${syncCfg.intelBusId}" + BusID "${pCfg.intelBusId}" Option "AccelMethod" "none" EndSection ''; From 632a8a7bb27b5e852becf0c4cd451cde18237f1b Mon Sep 17 00:00:00 2001 From: Edmund Wu Date: Wed, 14 Aug 2019 12:37:03 -0400 Subject: [PATCH 4/7] nixos/xserver: introduce attr display to xserver.drivers Specifically for NVIDIA so that only the device section would be created --- nixos/modules/hardware/video/amdgpu-pro.nix | 2 +- nixos/modules/hardware/video/ati.nix | 2 +- nixos/modules/hardware/video/nvidia.nix | 29 ++++---- nixos/modules/services/x11/xserver.nix | 76 +++++++++++---------- 4 files changed, 54 insertions(+), 55 deletions(-) diff --git a/nixos/modules/hardware/video/amdgpu-pro.nix b/nixos/modules/hardware/video/amdgpu-pro.nix index 8e91e9d2baa93..ec1c8c2d57a1a 100644 --- a/nixos/modules/hardware/video/amdgpu-pro.nix +++ b/nixos/modules/hardware/video/amdgpu-pro.nix @@ -30,7 +30,7 @@ in nixpkgs.config.xorg.abiCompat = "1.19"; services.xserver.drivers = singleton - { name = "amdgpu"; modules = [ package ]; }; + { name = "amdgpu"; modules = [ package ]; display = true; }; hardware.opengl.package = package; hardware.opengl.package32 = package32; diff --git a/nixos/modules/hardware/video/ati.nix b/nixos/modules/hardware/video/ati.nix index 0aab7bd6b92c9..06d3ea324d8d5 100644 --- a/nixos/modules/hardware/video/ati.nix +++ b/nixos/modules/hardware/video/ati.nix @@ -21,7 +21,7 @@ in nixpkgs.config.xorg.abiCompat = "1.17"; services.xserver.drivers = singleton - { name = "fglrx"; modules = [ ati_x11 ]; }; + { name = "fglrx"; modules = [ ati_x11 ]; display = true; }; hardware.opengl.package = ati_x11; hardware.opengl.package32 = pkgs.pkgsi686Linux.linuxPackages.ati_drivers_x11.override { libsOnly = true; kernel = null; }; diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index 295180d2b64e4..e3ef0e7a846b7 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -125,8 +125,7 @@ in } { - assertion = !syncCfg.enable || - (pCfg.nvidiaBusId != "" && pCfg.intelBusId != ""); + assertion = syncCfg.enable -> pCfg.nvidiaBusId != "" && pCfg.intelBusId != ""; message = '' When NVIDIA Optimus via PRIME is enabled, the GPU bus IDs must configured. ''; @@ -145,9 +144,17 @@ in # - Configure the display manager to run specific `xrandr` commands which will # configure/enable displays connected to the Intel GPU. - services.xserver.drivers = singleton { + services.xserver.drivers = optional syncCfg.enable { + name = "modesetting"; + display = false; + deviceSection = '' + BusID "${pCfg.intelBusId}" + Option "AccelMethod" "none" + ''; + } ++ singleton { name = "nvidia"; modules = [ nvidia_x11.bin ]; + display = true; deviceSection = optionalString syncCfg.enable '' BusID "${pCfg.nvidiaBusId}" @@ -160,19 +167,9 @@ in ''; }; - services.xserver.extraConfig = optionalString syncCfg.enable - '' - Section "Device" - Identifier "nvidia-optimus-intel" - Driver "modesetting" - BusID "${pCfg.intelBusId}" - Option "AccelMethod" "none" - EndSection - ''; - services.xserver.serverLayoutSection = optionalString syncCfg.enable - '' - Inactive "nvidia-optimus-intel" - ''; + services.xserver.serverLayoutSection = optionalString syncCfg.enable '' + Inactive "Device-modesetting[0]" + ''; services.xserver.displayManager.setupCommands = optionalString syncCfg.enable '' # Added by nvidia configuration module for Optimus/PRIME. diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix index 1f6ee7cfffda7..acf240ca5adee 100644 --- a/nixos/modules/services/x11/xserver.nix +++ b/nixos/modules/services/x11/xserver.nix @@ -574,7 +574,7 @@ in then { modules = [xorg.${"xf86video" + name}]; } else null) knownVideoDrivers; - in optional (driver != null) ({ inherit name; modules = []; driverName = name; } // driver)); + in optional (driver != null) ({ inherit name; modules = []; driverName = name; display = true; } // driver)); assertions = [ { assertion = config.security.polkit.enable; @@ -749,7 +749,7 @@ in ${cfg.serverLayoutSection} # Reference the Screen sections for each driver. This will # cause the X server to try each in turn. - ${flip concatMapStrings cfg.drivers (d: '' + ${flip concatMapStrings (filter (d: d.display) cfg.drivers) (d: '' Screen "Screen-${d.name}[0]" '')} EndSection @@ -773,42 +773,44 @@ in ${driver.deviceSection or ""} ${xrandrDeviceSection} EndSection + ${optionalString driver.display '' + + Section "Screen" + Identifier "Screen-${driver.name}[0]" + Device "Device-${driver.name}[0]" + ${optionalString (cfg.monitorSection != "") '' + Monitor "Monitor[0]" + ''} + + ${cfg.screenSection} + ${driver.screenSection or ""} + + ${optionalString (cfg.defaultDepth != 0) '' + DefaultDepth ${toString cfg.defaultDepth} + ''} + + ${optionalString + (driver.name != "virtualbox" && + (cfg.resolutions != [] || + cfg.extraDisplaySettings != "" || + cfg.virtualScreen != null)) + (let + f = depth: + '' + SubSection "Display" + Depth ${toString depth} + ${optionalString (cfg.resolutions != []) + "Modes ${concatMapStrings (res: ''"${toString res.x}x${toString res.y}"'') cfg.resolutions}"} + ${cfg.extraDisplaySettings} + ${optionalString (cfg.virtualScreen != null) + "Virtual ${toString cfg.virtualScreen.x} ${toString cfg.virtualScreen.y}"} + EndSubSection + ''; + in concatMapStrings f [8 16 24] + )} - Section "Screen" - Identifier "Screen-${driver.name}[0]" - Device "Device-${driver.name}[0]" - ${optionalString (cfg.monitorSection != "") '' - Monitor "Monitor[0]" - ''} - - ${cfg.screenSection} - ${driver.screenSection or ""} - - ${optionalString (cfg.defaultDepth != 0) '' - DefaultDepth ${toString cfg.defaultDepth} - ''} - - ${optionalString - (driver.name != "virtualbox" && - (cfg.resolutions != [] || - cfg.extraDisplaySettings != "" || - cfg.virtualScreen != null)) - (let - f = depth: - '' - SubSection "Display" - Depth ${toString depth} - ${optionalString (cfg.resolutions != []) - "Modes ${concatMapStrings (res: ''"${toString res.x}x${toString res.y}"'') cfg.resolutions}"} - ${cfg.extraDisplaySettings} - ${optionalString (cfg.virtualScreen != null) - "Virtual ${toString cfg.virtualScreen.x} ${toString cfg.virtualScreen.y}"} - EndSubSection - ''; - in concatMapStrings f [8 16 24] - )} - - EndSection + EndSection + ''} '')} ${xrandrMonitorSections} From 026b6010efb33462865bc4ab3004d82bcd0b49ac Mon Sep 17 00:00:00 2001 From: Edmund Wu Date: Wed, 14 Aug 2019 12:41:15 -0400 Subject: [PATCH 5/7] nixos/nvidia: implement prime render offload --- nixos/modules/hardware/video/nvidia.nix | 48 +++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index e3ef0e7a846b7..a75e6961b64c4 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -36,6 +36,8 @@ let cfg = config.hardware.nvidia; pCfg = cfg.prime; syncCfg = pCfg.sync; + offloadCfg = pCfg.offload; + primeEnabled = syncCfg.enable || offloadCfg.enable; in { @@ -115,6 +117,18 @@ in Configure X to allow external NVIDIA GPUs when using optimus. ''; }; + + hardware.nvidia.prime.offload.enable = mkOption { + type = types.bool; + default = false; + description = '' + Enable render offload support using the NVIDIA proprietary driver via PRIME. + + If this is enabled, then the bus IDs of the NVIDIA and Intel GPUs have to be + specified ( and + ). + ''; + }; }; config = mkIf enabled { @@ -125,11 +139,19 @@ in } { - assertion = syncCfg.enable -> pCfg.nvidiaBusId != "" && pCfg.intelBusId != ""; + assertion = primeEnabled -> pCfg.nvidiaBusId != "" && pCfg.intelBusId != ""; message = '' - When NVIDIA Optimus via PRIME is enabled, the GPU bus IDs must configured. + When NVIDIA PRIME is enabled, the GPU bus IDs must configured. ''; } + { + assertion = offloadCfg.enable -> versionAtLeast nvidia_x11.version "435.21"; + message = "NVIDIA PRIME render offload is currently only supported on versions >= 435.21."; + } + { + assertion = !(syncCfg.enable && offloadCfg.enable); + message = "Only one NVIDIA PRIME solution may be used at a time."; + } ]; # If Optimus/PRIME is enabled, we: @@ -144,18 +166,20 @@ in # - Configure the display manager to run specific `xrandr` commands which will # configure/enable displays connected to the Intel GPU. - services.xserver.drivers = optional syncCfg.enable { + services.xserver.useGlamor = mkDefault offloadCfg.enable; + + services.xserver.drivers = optional primeEnabled { name = "modesetting"; - display = false; + display = offloadCfg.enable; deviceSection = '' BusID "${pCfg.intelBusId}" - Option "AccelMethod" "none" + ${optionalString syncCfg.enable ''Option "AccelMethod" "none"''} ''; } ++ singleton { name = "nvidia"; modules = [ nvidia_x11.bin ]; - display = true; - deviceSection = optionalString syncCfg.enable + display = !offloadCfg.enable; + deviceSection = optionalString primeEnabled '' BusID "${pCfg.nvidiaBusId}" ${optionalString syncCfg.allowExternalGpu "Option \"AllowExternalGpus\""} @@ -169,6 +193,8 @@ in services.xserver.serverLayoutSection = optionalString syncCfg.enable '' Inactive "Device-modesetting[0]" + '' + optionalString offloadCfg.enable '' + Option "AllowNVIDIAGPUScreens" ''; services.xserver.displayManager.setupCommands = optionalString syncCfg.enable '' @@ -181,8 +207,10 @@ in source = "${nvidia_x11.bin}/share/nvidia/nvidia-application-profiles-rc"; }; - hardware.opengl.package = nvidia_x11.out; - hardware.opengl.package32 = nvidia_libs32; + hardware.opengl.package = mkIf (!offloadCfg.enable) nvidia_x11.out; + hardware.opengl.package32 = mkIf (!offloadCfg.enable) nvidia_libs32; + hardware.opengl.extraPackages = optional offloadCfg.enable nvidia_x11.out; + hardware.opengl.extraPackages32 = optional offloadCfg.enable nvidia_libs32; environment.systemPackages = [ nvidia_x11.bin nvidia_x11.settings ] ++ filter (p: p != null) [ nvidia_x11.persistenced ]; @@ -199,7 +227,7 @@ in optionals config.services.xserver.enable [ "nvidia" "nvidia_modeset" "nvidia_drm" ]; # If requested enable modesetting via kernel parameter. - boot.kernelParams = optional cfg.modesetting.enable "nvidia-drm.modeset=1"; + boot.kernelParams = optional (offloadCfg.enable || cfg.modesetting.enable) "nvidia-drm.modeset=1"; # Create /dev/nvidia-uvm when the nvidia-uvm module is loaded. services.udev.extraRules = From d48ed3b9e55b1ffa9cbdf343d01a6fabfee87263 Mon Sep 17 00:00:00 2001 From: gnidorah Date: Fri, 6 Sep 2019 22:00:18 +0300 Subject: [PATCH 6/7] nvidia_x11: fix *nvidia*.so* references --- pkgs/os-specific/linux/nvidia-x11/builder.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/os-specific/linux/nvidia-x11/builder.sh b/pkgs/os-specific/linux/nvidia-x11/builder.sh index b4c6952d44d30..30e5d16b60f3b 100755 --- a/pkgs/os-specific/linux/nvidia-x11/builder.sh +++ b/pkgs/os-specific/linux/nvidia-x11/builder.sh @@ -75,11 +75,18 @@ installPhase() { fi install -Dm644 nvidia_icd.json.fixed $i/share/vulkan/icd.d/nvidia.json fi + if [ -e nvidia_layers.json ]; then + sed -E "s#(libGLX_nvidia)#$i/lib/\\1#" nvidia_layers.json > nvidia_layers.json.fixed + install -Dm644 nvidia_layers.json.fixed $i/share/vulkan/implicit_layer.d/nvidia_layers.json + fi # EGL if [ "$useGLVND" = "1" ]; then sed -E "s#(libEGL_nvidia)#$i/lib/\\1#" 10_nvidia.json > 10_nvidia.json.fixed + sed -E "s#(libnvidia-egl-wayland)#$i/lib/\\1#" 10_nvidia_wayland.json > 10_nvidia_wayland.json.fixed + install -Dm644 10_nvidia.json.fixed $i/share/glvnd/egl_vendor.d/nvidia.json + install -Dm644 10_nvidia_wayland.json.fixed $i/share/glvnd/egl_vendor.d/nvidia_wayland.json fi done From 3b3876649d963fcc473bae2a04da22a3296ba99a Mon Sep 17 00:00:00 2001 From: Edmund Wu Date: Mon, 23 Sep 2019 17:52:47 -0400 Subject: [PATCH 7/7] nvidia_x11: include libdrm in rpath Needed for PRIME render offload specifically --- pkgs/os-specific/linux/nvidia-x11/generic.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/nvidia-x11/generic.nix b/pkgs/os-specific/linux/nvidia-x11/generic.nix index eeb7b99bbaae9..9e2ee6e834c24 100644 --- a/pkgs/os-specific/linux/nvidia-x11/generic.nix +++ b/pkgs/os-specific/linux/nvidia-x11/generic.nix @@ -32,7 +32,7 @@ let pkgSuffix = optionalString (versionOlder version "304") "-pkg0"; i686bundled = versionAtLeast version "391"; - libPathFor = pkgs: pkgs.lib.makeLibraryPath [ pkgs.xorg.libXext pkgs.xorg.libX11 + libPathFor = pkgs: pkgs.lib.makeLibraryPath [ pkgs.libdrm pkgs.xorg.libXext pkgs.xorg.libX11 pkgs.xorg.libXv pkgs.xorg.libXrandr pkgs.xorg.libxcb pkgs.zlib pkgs.stdenv.cc.cc ]; self = stdenv.mkDerivation {