From 33d083f55bab2d3ce5b02666630860038e9867fb Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Thu, 13 Mar 2025 11:53:24 +0000 Subject: [PATCH] feat(nvidia-prime): automatic battery-saver specialisation This enables a boot option that switches off NVIDIA GPU. Allows for battery saving. @moduon MT-9339 --- common/gpu/nvidia/prime.nix | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/common/gpu/nvidia/prime.nix b/common/gpu/nvidia/prime.nix index e54f942c..cf3e7d45 100644 --- a/common/gpu/nvidia/prime.nix +++ b/common/gpu/nvidia/prime.nix @@ -3,11 +3,35 @@ { imports = [ ./. ]; - hardware.nvidia.prime = { - offload = { - enable = lib.mkOverride 990 true; - enableOffloadCmd = lib.mkIf config.hardware.nvidia.prime.offload.enable true; # Provides `nvidia-offload` command. + options = { + hardware.nvidia.primeBatterySaverSpecialisation = lib.mkEnableOption "configure a specialisation which turns on NVIDIA Prime battery saver"; + }; + + config = { + + hardware.nvidia.prime = { + offload = { + enable = lib.mkOverride 990 true; + enableOffloadCmd = lib.mkIf config.hardware.nvidia.prime.offload.enable true; # Provides `nvidia-offload` command. + }; + # Hardware should specify the bus ID for intel/nvidia devices + }; + + specialisation = lib.mkIf config.hardware.nvidia.primeBatterySaverSpecialisation { + battery-saver.configuration = { + system.nixos.tags = ["battery-saver"]; + imports = [ + # Leave only the integrated GPU enabled + ./disable.nix + ]; + hardware.nvidia = { + prime.offload.enable = lib.mkForce false; + powerManagement = { + enable = lib.mkForce false; + finegrained = lib.mkForce false; + }; + }; + }; }; - # Hardware should specify the bus ID for intel/nvidia devices }; }