2014-04-29 13:16:34 +01:00
|
|
|
# This module provides the proprietary NVIDIA X11 / OpenGL drivers.
|
|
|
|
|
2019-06-16 20:59:06 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-04-29 13:16:34 +01:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2018-11-03 18:50:12 +00:00
|
|
|
nvidia_x11 = let
|
|
|
|
drivers = config.services.xserver.videoDrivers;
|
|
|
|
isDeprecated = str: (hasPrefix "nvidia" str) && (str != "nvidia");
|
|
|
|
hasDeprecated = drivers: any isDeprecated drivers;
|
|
|
|
in if (hasDeprecated drivers) then
|
|
|
|
throw ''
|
|
|
|
Selecting an nvidia driver has been modified for NixOS 19.03. The version is now set using `hardware.nvidia.package`.
|
|
|
|
''
|
|
|
|
else if (elem "nvidia" drivers) then cfg.package else null;
|
2014-04-29 13:16:34 +01:00
|
|
|
|
2015-02-21 15:29:36 +00:00
|
|
|
enabled = nvidia_x11 != null;
|
2018-06-30 08:33:45 +01:00
|
|
|
cfg = config.hardware.nvidia;
|
2020-03-09 08:47:57 +00:00
|
|
|
|
2019-08-14 13:18:28 +01:00
|
|
|
pCfg = cfg.prime;
|
|
|
|
syncCfg = pCfg.sync;
|
2019-08-14 17:41:15 +01:00
|
|
|
offloadCfg = pCfg.offload;
|
|
|
|
primeEnabled = syncCfg.enable || offloadCfg.enable;
|
2020-03-09 08:47:57 +00:00
|
|
|
nvidiaPersistencedEnabled = cfg.nvidiaPersistenced;
|
2021-09-01 13:57:33 +01:00
|
|
|
nvidiaSettings = cfg.nvidiaSettings;
|
2014-04-29 13:16:34 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2019-08-14 13:15:43 +01:00
|
|
|
imports =
|
|
|
|
[
|
|
|
|
(mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "enable" ] [ "hardware" "nvidia" "prime" "sync" "enable" ])
|
|
|
|
(mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "allowExternalGpu" ] [ "hardware" "nvidia" "prime" "sync" "allowExternalGpu" ])
|
2019-08-14 13:18:28 +01:00
|
|
|
(mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "nvidiaBusId" ] [ "hardware" "nvidia" "prime" "nvidiaBusId" ])
|
|
|
|
(mkRenamedOptionModule [ "hardware" "nvidia" "optimus_prime" "intelBusId" ] [ "hardware" "nvidia" "prime" "intelBusId" ])
|
2019-08-14 13:15:43 +01:00
|
|
|
];
|
|
|
|
|
2018-06-30 08:33:45 +01:00
|
|
|
options = {
|
2019-11-16 19:27:16 +00:00
|
|
|
hardware.nvidia.powerManagement.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Experimental power management through systemd. For more information, see
|
|
|
|
the NVIDIA docs, on Chapter 21. Configuring Power Management Support.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-10-14 16:17:53 +01:00
|
|
|
hardware.nvidia.powerManagement.finegrained = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Experimental power management of PRIME offload. For more information, see
|
|
|
|
the NVIDIA docs, chapter 22. PCI-Express runtime power management.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-08-14 03:39:26 +01:00
|
|
|
hardware.nvidia.modesetting.enable = mkOption {
|
|
|
|
type = types.bool;
|
2018-06-30 08:33:45 +01:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable kernel modesetting when using the NVIDIA proprietary driver.
|
|
|
|
|
|
|
|
Enabling this fixes screen tearing when using Optimus via PRIME (see
|
2019-08-14 13:15:43 +01:00
|
|
|
<option>hardware.nvidia.prime.sync.enable</option>. This is not enabled
|
2018-06-30 08:33:45 +01:00
|
|
|
by default because it is not officially supported by NVIDIA and would not
|
|
|
|
work with SLI.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-08-14 13:18:28 +01:00
|
|
|
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".
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-10-14 15:24:48 +01:00
|
|
|
hardware.nvidia.prime.amdgpuBusId = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "PCI:4:0:0";
|
|
|
|
description = ''
|
|
|
|
Bus ID of the AMD APU. You can find it using lspci; for example if lspci
|
2021-06-09 00:46:45 +01:00
|
|
|
shows the AMD APU at "04:00.0", set this option to "PCI:4:0:0".
|
2020-10-14 15:24:48 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-08-14 13:15:43 +01:00
|
|
|
hardware.nvidia.prime.sync.enable = mkOption {
|
2019-08-14 03:39:26 +01:00
|
|
|
type = types.bool;
|
2018-06-30 08:33:45 +01:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable NVIDIA Optimus support using the NVIDIA proprietary driver via PRIME.
|
|
|
|
If enabled, the NVIDIA GPU will be always on and used for all rendering,
|
|
|
|
while enabling output to displays attached only to the integrated Intel GPU
|
|
|
|
without a multiplexer.
|
|
|
|
|
|
|
|
Note that this option only has any effect if the "nvidia" driver is specified
|
|
|
|
in <option>services.xserver.videoDrivers</option>, and it should preferably
|
|
|
|
be the only driver there.
|
|
|
|
|
|
|
|
If this is enabled, then the bus IDs of the NVIDIA and Intel GPUs have to be
|
2019-08-14 13:18:28 +01:00
|
|
|
specified (<option>hardware.nvidia.prime.nvidiaBusId</option> and
|
|
|
|
<option>hardware.nvidia.prime.intelBusId</option>).
|
2018-06-30 08:33:45 +01:00
|
|
|
|
|
|
|
If you enable this, you may want to also enable kernel modesetting for the
|
|
|
|
NVIDIA driver (<option>hardware.nvidia.modesetting.enable</option>) in order
|
|
|
|
to prevent tearing.
|
|
|
|
|
|
|
|
Note that this configuration will only be successful when a display manager
|
|
|
|
for which the <option>services.xserver.displayManager.setupCommands</option>
|
2019-11-11 21:18:23 +00:00
|
|
|
option is supported is used.
|
2018-06-30 08:33:45 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-08-14 13:15:43 +01:00
|
|
|
hardware.nvidia.prime.sync.allowExternalGpu = mkOption {
|
2019-08-14 03:39:26 +01:00
|
|
|
type = types.bool;
|
2019-04-18 23:51:35 +01:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Configure X to allow external NVIDIA GPUs when using optimus.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-08-14 17:41:15 +01:00
|
|
|
hardware.nvidia.prime.offload.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2018-06-30 08:33:45 +01:00
|
|
|
description = ''
|
2019-08-14 17:41:15 +01:00
|
|
|
Enable render offload support using the NVIDIA proprietary driver via PRIME.
|
2018-06-30 08:33:45 +01:00
|
|
|
|
2019-08-14 17:41:15 +01:00
|
|
|
If this is enabled, then the bus IDs of the NVIDIA and Intel GPUs have to be
|
|
|
|
specified (<option>hardware.nvidia.prime.nvidiaBusId</option> and
|
|
|
|
<option>hardware.nvidia.prime.intelBusId</option>).
|
2018-06-30 08:33:45 +01:00
|
|
|
'';
|
|
|
|
};
|
2020-03-09 08:47:57 +00:00
|
|
|
|
2021-08-31 00:23:57 +01:00
|
|
|
hardware.nvidia.nvidiaSettings = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to add nvidia-settings, NVIDIA's GUI configuration tool, to
|
|
|
|
systemPackages.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-03-09 08:47:57 +00:00
|
|
|
hardware.nvidia.nvidiaPersistenced = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Update for NVIDA GPU headless mode, i.e. nvidia-persistenced. It ensures all
|
|
|
|
GPUs stay awake even during headless mode.
|
|
|
|
'';
|
|
|
|
};
|
2018-11-03 18:50:12 +00:00
|
|
|
|
|
|
|
hardware.nvidia.package = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
|
|
|
default = config.boot.kernelPackages.nvidiaPackages.stable;
|
|
|
|
defaultText = "config.boot.kernelPackages.nvidiaPackages.stable";
|
|
|
|
description = ''
|
|
|
|
The NVIDIA X11 derivation to use.
|
|
|
|
'';
|
2021-06-09 00:46:45 +01:00
|
|
|
example = "config.boot.kernelPackages.nvidiaPackages.legacy_340";
|
2018-11-03 18:50:12 +00:00
|
|
|
};
|
2018-06-30 08:33:45 +01:00
|
|
|
};
|
2014-04-29 13:16:34 +01:00
|
|
|
|
2020-10-14 15:24:48 +01:00
|
|
|
config = let
|
|
|
|
igpuDriver = if pCfg.intelBusId != "" then "modesetting" else "amdgpu";
|
|
|
|
igpuBusId = if pCfg.intelBusId != "" then pCfg.intelBusId else pCfg.amdgpuBusId;
|
|
|
|
in mkIf enabled {
|
2017-05-07 21:27:02 +01:00
|
|
|
assertions = [
|
2019-10-03 01:07:19 +01:00
|
|
|
{
|
|
|
|
assertion = with config.services.xserver.displayManager; gdm.nvidiaWayland -> cfg.modesetting.enable;
|
|
|
|
message = "You cannot use wayland with GDM without modesetting enabled for NVIDIA drivers, set `hardware.nvidia.modesetting.enable = true`";
|
|
|
|
}
|
|
|
|
|
2018-06-30 08:33:45 +01:00
|
|
|
{
|
2020-10-14 15:24:48 +01:00
|
|
|
assertion = primeEnabled -> pCfg.intelBusId == "" || pCfg.amdgpuBusId == "";
|
|
|
|
message = ''
|
|
|
|
You cannot configure both an Intel iGPU and an AMD APU. Pick the one corresponding to your processor.
|
|
|
|
'';
|
|
|
|
}
|
2021-07-26 21:48:50 +01:00
|
|
|
|
2020-10-14 15:24:48 +01:00
|
|
|
{
|
|
|
|
assertion = primeEnabled -> pCfg.nvidiaBusId != "" && (pCfg.intelBusId != "" || pCfg.amdgpuBusId != "");
|
2018-06-30 08:33:45 +01:00
|
|
|
message = ''
|
2019-08-14 17:41:15 +01:00
|
|
|
When NVIDIA PRIME is enabled, the GPU bus IDs must configured.
|
2018-06-30 08:33:45 +01:00
|
|
|
'';
|
|
|
|
}
|
2021-07-26 21:48:50 +01:00
|
|
|
|
2019-08-14 17:41:15 +01:00
|
|
|
{
|
|
|
|
assertion = offloadCfg.enable -> versionAtLeast nvidia_x11.version "435.21";
|
|
|
|
message = "NVIDIA PRIME render offload is currently only supported on versions >= 435.21.";
|
|
|
|
}
|
2021-07-26 21:48:50 +01:00
|
|
|
|
2019-08-14 17:41:15 +01:00
|
|
|
{
|
|
|
|
assertion = !(syncCfg.enable && offloadCfg.enable);
|
|
|
|
message = "Only one NVIDIA PRIME solution may be used at a time.";
|
|
|
|
}
|
2021-07-26 21:48:50 +01:00
|
|
|
|
2020-10-14 16:17:53 +01:00
|
|
|
{
|
|
|
|
assertion = !(syncCfg.enable && cfg.powerManagement.finegrained);
|
|
|
|
message = "Sync precludes powering down the NVIDIA GPU.";
|
|
|
|
}
|
2021-07-26 21:48:50 +01:00
|
|
|
|
2020-10-14 16:17:53 +01:00
|
|
|
{
|
|
|
|
assertion = cfg.powerManagement.enable -> offloadCfg.enable;
|
|
|
|
message = "Fine-grained power management requires offload to be enabled.";
|
|
|
|
}
|
2021-07-26 21:48:50 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
assertion = cfg.powerManagement.enable -> (
|
|
|
|
builtins.pathExists (cfg.package.out + "/bin/nvidia-sleep.sh") &&
|
|
|
|
builtins.pathExists (cfg.package.out + "/lib/systemd/system-sleep/nvidia")
|
|
|
|
);
|
|
|
|
message = "Required files for driver based power management don't exist.";
|
|
|
|
}
|
2017-05-07 21:27:02 +01:00
|
|
|
];
|
2014-04-29 13:16:34 +01:00
|
|
|
|
2018-06-30 08:33:45 +01:00
|
|
|
# If Optimus/PRIME is enabled, we:
|
|
|
|
# - Specify the configured NVIDIA GPU bus ID in the Device section for the
|
|
|
|
# "nvidia" driver.
|
|
|
|
# - Add the AllowEmptyInitialConfiguration option to the Screen section for the
|
|
|
|
# "nvidia" driver, in order to allow the X server to start without any outputs.
|
|
|
|
# - Add a separate Device section for the Intel GPU, using the "modesetting"
|
|
|
|
# driver and with the configured BusID.
|
2020-10-14 15:24:48 +01:00
|
|
|
# - OR add a separate Device section for the AMD APU, using the "amdgpu"
|
|
|
|
# driver and with the configures BusID.
|
2018-06-30 08:33:45 +01:00
|
|
|
# - Reference that Device section from the ServerLayout section as an inactive
|
|
|
|
# device.
|
|
|
|
# - Configure the display manager to run specific `xrandr` commands which will
|
2020-10-14 15:24:48 +01:00
|
|
|
# configure/enable displays connected to the Intel iGPU / AMD APU.
|
2018-06-30 08:33:45 +01:00
|
|
|
|
2019-08-14 17:41:15 +01:00
|
|
|
services.xserver.useGlamor = mkDefault offloadCfg.enable;
|
|
|
|
|
2020-10-14 15:24:48 +01:00
|
|
|
services.xserver.drivers = let
|
|
|
|
in optional primeEnabled {
|
|
|
|
name = igpuDriver;
|
2019-08-14 17:41:15 +01:00
|
|
|
display = offloadCfg.enable;
|
2020-10-14 15:24:48 +01:00
|
|
|
modules = optional (igpuDriver == "amdgpu") [ pkgs.xorg.xf86videoamdgpu ];
|
2019-08-14 17:37:03 +01:00
|
|
|
deviceSection = ''
|
2020-10-14 15:24:48 +01:00
|
|
|
BusID "${igpuBusId}"
|
2019-08-14 17:41:15 +01:00
|
|
|
${optionalString syncCfg.enable ''Option "AccelMethod" "none"''}
|
2019-08-14 17:37:03 +01:00
|
|
|
'';
|
|
|
|
} ++ singleton {
|
2018-06-30 08:33:45 +01:00
|
|
|
name = "nvidia";
|
|
|
|
modules = [ nvidia_x11.bin ];
|
2019-08-14 17:41:15 +01:00
|
|
|
display = !offloadCfg.enable;
|
|
|
|
deviceSection = optionalString primeEnabled
|
2018-06-30 08:33:45 +01:00
|
|
|
''
|
2019-08-14 13:18:28 +01:00
|
|
|
BusID "${pCfg.nvidiaBusId}"
|
2019-08-14 13:15:43 +01:00
|
|
|
${optionalString syncCfg.allowExternalGpu "Option \"AllowExternalGpus\""}
|
2020-10-14 16:17:53 +01:00
|
|
|
${optionalString cfg.powerManagement.finegrained "Option \"NVreg_DynamicPowerManagement=0x02\""}
|
2018-06-30 08:33:45 +01:00
|
|
|
'';
|
|
|
|
screenSection =
|
|
|
|
''
|
|
|
|
Option "RandRRotation" "on"
|
2019-08-14 13:15:43 +01:00
|
|
|
${optionalString syncCfg.enable "Option \"AllowEmptyInitialConfiguration\""}
|
2018-06-30 08:33:45 +01:00
|
|
|
'';
|
|
|
|
};
|
2014-04-29 13:16:34 +01:00
|
|
|
|
2019-08-14 17:37:03 +01:00
|
|
|
services.xserver.serverLayoutSection = optionalString syncCfg.enable ''
|
2020-10-14 15:24:48 +01:00
|
|
|
Inactive "Device-${igpuDriver}[0]"
|
2019-08-14 17:41:15 +01:00
|
|
|
'' + optionalString offloadCfg.enable ''
|
|
|
|
Option "AllowNVIDIAGPUScreens"
|
2019-08-14 17:37:03 +01:00
|
|
|
'';
|
2014-04-29 13:16:34 +01:00
|
|
|
|
2019-08-14 13:15:43 +01:00
|
|
|
services.xserver.displayManager.setupCommands = optionalString syncCfg.enable ''
|
2018-06-30 08:33:45 +01:00
|
|
|
# Added by nvidia configuration module for Optimus/PRIME.
|
2020-10-14 15:24:48 +01:00
|
|
|
${pkgs.xorg.xrandr}/bin/xrandr --setprovideroutputsource ${igpuDriver} NVIDIA-0
|
2018-06-30 08:33:45 +01:00
|
|
|
${pkgs.xorg.xrandr}/bin/xrandr --auto
|
|
|
|
'';
|
|
|
|
|
2017-02-11 14:11:18 +00:00
|
|
|
environment.etc."nvidia/nvidia-application-profiles-rc" = mkIf nvidia_x11.useProfiles {
|
|
|
|
source = "${nvidia_x11.bin}/share/nvidia/nvidia-application-profiles-rc";
|
|
|
|
};
|
|
|
|
|
2019-08-14 17:41:15 +01:00
|
|
|
hardware.opengl.package = mkIf (!offloadCfg.enable) nvidia_x11.out;
|
2018-11-03 18:50:12 +00:00
|
|
|
hardware.opengl.package32 = mkIf (!offloadCfg.enable) nvidia_x11.lib32;
|
2019-08-14 17:41:15 +01:00
|
|
|
hardware.opengl.extraPackages = optional offloadCfg.enable nvidia_x11.out;
|
2018-11-03 18:50:12 +00:00
|
|
|
hardware.opengl.extraPackages32 = optional offloadCfg.enable nvidia_x11.lib32;
|
2014-04-29 13:16:34 +01:00
|
|
|
|
2021-08-31 00:23:57 +01:00
|
|
|
environment.systemPackages = [ nvidia_x11.bin ]
|
|
|
|
++ optionals nvidiaSettings [ nvidia_x11.settings ]
|
2020-10-18 19:42:05 +01:00
|
|
|
++ optionals nvidiaPersistencedEnabled [ nvidia_x11.persistenced ];
|
2014-04-29 13:16:34 +01:00
|
|
|
|
2019-11-16 19:27:16 +00:00
|
|
|
systemd.packages = optional cfg.powerManagement.enable nvidia_x11.out;
|
|
|
|
|
|
|
|
systemd.services = let
|
|
|
|
baseNvidiaService = state: {
|
|
|
|
description = "NVIDIA system ${state} actions";
|
|
|
|
|
|
|
|
path = with pkgs; [ kbd ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
ExecStart = "${nvidia_x11.out}/bin/nvidia-sleep.sh '${state}'";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
nvidiaService = sleepState: (baseNvidiaService sleepState) // {
|
|
|
|
before = [ "systemd-${sleepState}.service" ];
|
|
|
|
requiredBy = [ "systemd-${sleepState}.service" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
services = (builtins.listToAttrs (map (t: nameValuePair "nvidia-${t}" (nvidiaService t)) ["hibernate" "suspend"]))
|
|
|
|
// {
|
|
|
|
nvidia-resume = (baseNvidiaService "resume") // {
|
|
|
|
after = [ "systemd-suspend.service" "systemd-hibernate.service" ];
|
|
|
|
requiredBy = [ "systemd-suspend.service" "systemd-hibernate.service" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in optionalAttrs cfg.powerManagement.enable services
|
|
|
|
// optionalAttrs nvidiaPersistencedEnabled {
|
|
|
|
"nvidia-persistenced" = mkIf nvidiaPersistencedEnabled {
|
|
|
|
description = "NVIDIA Persistence Daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
Restart = "always";
|
|
|
|
PIDFile = "/var/run/nvidia-persistenced/nvidia-persistenced.pid";
|
|
|
|
ExecStart = "${nvidia_x11.persistenced}/bin/nvidia-persistenced --verbose";
|
|
|
|
ExecStopPost = "${pkgs.coreutils}/bin/rm -rf /var/run/nvidia-persistenced";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-02-27 08:44:37 +00:00
|
|
|
systemd.tmpfiles.rules = optional config.virtualisation.docker.enableNvidia
|
|
|
|
"L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin"
|
|
|
|
++ optional (nvidia_x11.persistenced != null && config.virtualisation.docker.enableNvidia)
|
|
|
|
"L+ /run/nvidia-docker/extras/bin/nvidia-persistenced - - - - ${nvidia_x11.persistenced}/origBin/nvidia-persistenced";
|
|
|
|
|
2017-01-29 21:29:39 +00:00
|
|
|
boot.extraModulePackages = [ nvidia_x11.bin ];
|
2014-04-29 13:16:34 +01:00
|
|
|
|
2015-03-03 19:15:38 +00:00
|
|
|
# nvidia-uvm is required by CUDA applications.
|
2017-05-07 20:37:56 +01:00
|
|
|
boot.kernelModules = [ "nvidia-uvm" ] ++
|
2019-08-14 03:39:26 +01:00
|
|
|
optionals config.services.xserver.enable [ "nvidia" "nvidia_modeset" "nvidia_drm" ];
|
2017-05-07 20:37:56 +01:00
|
|
|
|
2018-06-30 08:33:45 +01:00
|
|
|
# If requested enable modesetting via kernel parameter.
|
2019-11-16 19:27:16 +00:00
|
|
|
boot.kernelParams = optional (offloadCfg.enable || cfg.modesetting.enable) "nvidia-drm.modeset=1"
|
|
|
|
++ optional cfg.powerManagement.enable "nvidia.NVreg_PreserveVideoMemoryAllocations=1";
|
2015-03-03 19:15:38 +00:00
|
|
|
|
|
|
|
services.udev.extraRules =
|
|
|
|
''
|
2020-10-14 16:17:53 +01:00
|
|
|
# Create /dev/nvidia-uvm when the nvidia-uvm module is loaded.
|
2019-12-26 17:52:03 +00:00
|
|
|
KERNEL=="nvidia", RUN+="${pkgs.runtimeShell} -c 'mknod -m 666 /dev/nvidiactl c $$(grep nvidia-frontend /proc/devices | cut -d \ -f 1) 255'"
|
|
|
|
KERNEL=="nvidia_modeset", RUN+="${pkgs.runtimeShell} -c 'mknod -m 666 /dev/nvidia-modeset c $$(grep nvidia-frontend /proc/devices | cut -d \ -f 1) 254'"
|
|
|
|
KERNEL=="card*", SUBSYSTEM=="drm", DRIVERS=="nvidia", RUN+="${pkgs.runtimeShell} -c 'mknod -m 666 /dev/nvidia%n c $$(grep nvidia-frontend /proc/devices | cut -d \ -f 1) %n'"
|
|
|
|
KERNEL=="nvidia_uvm", RUN+="${pkgs.runtimeShell} -c 'mknod -m 666 /dev/nvidia-uvm c $$(grep nvidia-uvm /proc/devices | cut -d \ -f 1) 0'"
|
2019-12-30 18:15:10 +00:00
|
|
|
KERNEL=="nvidia_uvm", RUN+="${pkgs.runtimeShell} -c 'mknod -m 666 /dev/nvidia-uvm-tools c $$(grep nvidia-uvm /proc/devices | cut -d \ -f 1) 0'"
|
2020-10-14 16:17:53 +01:00
|
|
|
'' + optionalString cfg.powerManagement.finegrained ''
|
|
|
|
# Remove NVIDIA USB xHCI Host Controller devices, if present
|
|
|
|
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c0330", ATTR{remove}="1"
|
|
|
|
|
|
|
|
# Remove NVIDIA USB Type-C UCSI devices, if present
|
|
|
|
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c8000", ATTR{remove}="1"
|
|
|
|
|
|
|
|
# Remove NVIDIA Audio devices, if present
|
|
|
|
ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", ATTR{remove}="1"
|
|
|
|
|
|
|
|
# Enable runtime PM for NVIDIA VGA/3D controller devices on driver bind
|
|
|
|
ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="auto"
|
|
|
|
ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030200", TEST=="power/control", ATTR{power/control}="auto"
|
|
|
|
|
|
|
|
# Disable runtime PM for NVIDIA VGA/3D controller devices on driver unbind
|
|
|
|
ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="on"
|
|
|
|
ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030200", TEST=="power/control", ATTR{power/control}="on"
|
2015-03-03 19:15:38 +00:00
|
|
|
'';
|
|
|
|
|
2020-10-14 16:17:53 +01:00
|
|
|
boot.extraModprobeConfig = mkIf cfg.powerManagement.finegrained ''
|
|
|
|
options nvidia "NVreg_DynamicPowerManagement=0x02"
|
|
|
|
'';
|
|
|
|
|
2014-04-29 13:16:34 +01:00
|
|
|
boot.blacklistedKernelModules = [ "nouveau" "nvidiafb" ];
|
|
|
|
|
|
|
|
services.acpid.enable = true;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|