nixos/nvidia: use kernel suspend notifiers if available

This commit is contained in:
ccicnce113424
2026-03-06 20:46:49 +08:00
parent e99215c1a2
commit 2e727397a6
+28 -2
View File
@@ -93,6 +93,20 @@ in
the NVIDIA docs, on Chapter 22. PCI-Express Runtime D3 (RTD3) Power Management
'';
powerManagement.kernelSuspendNotifier =
lib.mkEnableOption ''
NVIDIA driver support for kernel suspend notifiers, which allows the driver
to be notified of suspend and resume events by the kernel, rather than
relying on systemd services.
Requires NVIDIA driver version 595 or newer, and the open source kernel modules.
''
// {
default = useOpenModules && lib.versionAtLeast nvidia_x11.version "595";
defaultText = lib.literalExpression ''
config.hardware.nvidia.open == true && lib.versionAtLeast config.hardware.nvidia.package.version "595"
'';
};
dynamicBoost.enable = lib.mkEnableOption ''
dynamic Boost balances power between the CPU and the GPU for improved
performance on supported laptops using the nvidia-powerd daemon. For more
@@ -465,6 +479,13 @@ in
assertion = cfg.dynamicBoost.enable -> lib.versionAtLeast nvidia_x11.version "510.39.01";
message = "NVIDIA's Dynamic Boost feature only exists on versions >= 510.39.01";
}
{
assertion =
cfg.powerManagement.kernelSuspendNotifier
-> (useOpenModules && lib.versionAtLeast nvidia_x11.version "595");
message = "NVIDIA driver support for kernel suspend notifiers requires NVIDIA driver version 595 or newer, and the open source kernel modules.";
}
];
# If Optimus/PRIME is enabled, we:
@@ -576,7 +597,9 @@ in
''
);
systemd.packages = lib.optional cfg.powerManagement.enable nvidia_x11.out;
systemd.packages = lib.optional (
cfg.powerManagement.enable && !cfg.powerManagement.kernelSuspendNotifier
) nvidia_x11.out;
systemd.services =
let
@@ -592,7 +615,7 @@ in
};
in
lib.mkMerge [
(lib.mkIf cfg.powerManagement.enable {
(lib.mkIf (cfg.powerManagement.enable && !cfg.powerManagement.kernelSuspendNotifier) {
nvidia-suspend = nvidiaService "suspend";
nvidia-hibernate = nvidiaService "hibernate";
nvidia-resume = (nvidiaService "resume") // {
@@ -669,6 +692,9 @@ in
++ lib.optional (
(offloadCfg.enable || cfg.modesetting.enable) && lib.versionAtLeast nvidia_x11.version "545"
) "nvidia-drm.fbdev=1"
++ lib.optional (
cfg.powerManagement.enable && cfg.powerManagement.kernelSuspendNotifier
) "nvidia.NVreg_UseKernelSuspendNotifiers=1"
++ lib.optional cfg.powerManagement.enable "nvidia.NVreg_PreserveVideoMemoryAllocations=1"
++ lib.optional useOpenModules "nvidia.NVreg_OpenRmEnableUnsupportedGpus=1"
++ lib.optional (config.boot.kernelPackages.kernel.kernelAtLeast "6.2" && !ibtSupport) "ibt=off";