Skip to content

Commit 2e72739

Browse files
committed
nixos/nvidia: use kernel suspend notifiers if available
1 parent e99215c commit 2e72739

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

nixos/modules/hardware/video/nvidia.nix

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ in
9393
the NVIDIA docs, on Chapter 22. PCI-Express Runtime D3 (RTD3) Power Management
9494
'';
9595

96+
powerManagement.kernelSuspendNotifier =
97+
lib.mkEnableOption ''
98+
NVIDIA driver support for kernel suspend notifiers, which allows the driver
99+
to be notified of suspend and resume events by the kernel, rather than
100+
relying on systemd services.
101+
Requires NVIDIA driver version 595 or newer, and the open source kernel modules.
102+
''
103+
// {
104+
default = useOpenModules && lib.versionAtLeast nvidia_x11.version "595";
105+
defaultText = lib.literalExpression ''
106+
config.hardware.nvidia.open == true && lib.versionAtLeast config.hardware.nvidia.package.version "595"
107+
'';
108+
};
109+
96110
dynamicBoost.enable = lib.mkEnableOption ''
97111
dynamic Boost balances power between the CPU and the GPU for improved
98112
performance on supported laptops using the nvidia-powerd daemon. For more
@@ -465,6 +479,13 @@ in
465479
assertion = cfg.dynamicBoost.enable -> lib.versionAtLeast nvidia_x11.version "510.39.01";
466480
message = "NVIDIA's Dynamic Boost feature only exists on versions >= 510.39.01";
467481
}
482+
483+
{
484+
assertion =
485+
cfg.powerManagement.kernelSuspendNotifier
486+
-> (useOpenModules && lib.versionAtLeast nvidia_x11.version "595");
487+
message = "NVIDIA driver support for kernel suspend notifiers requires NVIDIA driver version 595 or newer, and the open source kernel modules.";
488+
}
468489
];
469490

470491
# If Optimus/PRIME is enabled, we:
@@ -576,7 +597,9 @@ in
576597
''
577598
);
578599

579-
systemd.packages = lib.optional cfg.powerManagement.enable nvidia_x11.out;
600+
systemd.packages = lib.optional (
601+
cfg.powerManagement.enable && !cfg.powerManagement.kernelSuspendNotifier
602+
) nvidia_x11.out;
580603

581604
systemd.services =
582605
let
@@ -592,7 +615,7 @@ in
592615
};
593616
in
594617
lib.mkMerge [
595-
(lib.mkIf cfg.powerManagement.enable {
618+
(lib.mkIf (cfg.powerManagement.enable && !cfg.powerManagement.kernelSuspendNotifier) {
596619
nvidia-suspend = nvidiaService "suspend";
597620
nvidia-hibernate = nvidiaService "hibernate";
598621
nvidia-resume = (nvidiaService "resume") // {
@@ -669,6 +692,9 @@ in
669692
++ lib.optional (
670693
(offloadCfg.enable || cfg.modesetting.enable) && lib.versionAtLeast nvidia_x11.version "545"
671694
) "nvidia-drm.fbdev=1"
695+
++ lib.optional (
696+
cfg.powerManagement.enable && cfg.powerManagement.kernelSuspendNotifier
697+
) "nvidia.NVreg_UseKernelSuspendNotifiers=1"
672698
++ lib.optional cfg.powerManagement.enable "nvidia.NVreg_PreserveVideoMemoryAllocations=1"
673699
++ lib.optional useOpenModules "nvidia.NVreg_OpenRmEnableUnsupportedGpus=1"
674700
++ lib.optional (config.boot.kernelPackages.kernel.kernelAtLeast "6.2" && !ibtSupport) "ibt=off";

0 commit comments

Comments
 (0)