From 4ca2a16390d73d68d4262a45d892ffab6e28f6bc Mon Sep 17 00:00:00 2001 From: Gerg-L Date: Mon, 17 Jul 2023 17:17:29 -0400 Subject: [PATCH] nixos/nvidia: add Dynamic Boost support --- nixos/modules/hardware/video/nvidia.nix | 27 +++++++++++++++++++ pkgs/os-specific/linux/nvidia-x11/builder.sh | 5 +++- pkgs/os-specific/linux/nvidia-x11/generic.nix | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index eef85953a911..67c3afcf320a 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -31,6 +31,12 @@ in { the NVIDIA docs, on Chapter 22. PCI-Express Runtime D3 (RTD3) Power Management. ''); + dynamicBoost.enable = lib.mkEnableOption (lib.mdDoc '' + dynamic Boost balances power between the CPU and the GPU for improved + performance on supported laptops using the nvidia-powerd daemon. For more + information, see the NVIDIA docs, on Chapter 23. Dynamic Boost on Linux. + ''); + modesetting.enable = lib.mkEnableOption (lib.mdDoc '' kernel modesetting when using the NVIDIA proprietary driver. @@ -238,6 +244,11 @@ in { assertion = cfg.open -> (cfg.package ? open && cfg.package ? firmware); message = "This version of NVIDIA driver does not provide a corresponding opensource kernel driver"; } + + { + 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"; + } ]; # If Optimus/PRIME is enabled, we: @@ -394,10 +405,26 @@ in { }; }; }) + (lib.mkIf cfg.dynamicBoost.enable { + "nvidia-powerd" = { + description = "nvidia-powerd service"; + path = [ + pkgs.util-linux # nvidia-powerd wants lscpu + ]; + wantedBy = ["multi-user.target"]; + serviceConfig = { + Type = "dbus"; + BusName = "nvidia.powerd.server"; + ExecStart = "${nvidia_x11.bin}/bin/nvidia-powerd"; + }; + }; + }) ]; services.acpid.enable = true; + services.dbus.packages = lib.optional cfg.dynamicBoost.enable nvidia_x11.bin; + hardware.firmware = lib.optional cfg.open nvidia_x11.firmware; systemd.tmpfiles.rules = diff --git a/pkgs/os-specific/linux/nvidia-x11/builder.sh b/pkgs/os-specific/linux/nvidia-x11/builder.sh index 2b0f55c03879..07a9961a1bab 100755 --- a/pkgs/os-specific/linux/nvidia-x11/builder.sh +++ b/pkgs/os-specific/linux/nvidia-x11/builder.sh @@ -196,9 +196,12 @@ installPhase() { mkdir -p $bin/share/man/man1 cp -p *.1.gz $bin/share/man/man1 rm -f $bin/share/man/man1/{nvidia-xconfig,nvidia-settings,nvidia-persistenced}.1.gz + if [ -e "nvidia-dbus.conf" ]; then + install -Dm644 nvidia-dbus.conf $bin/share/dbus-1/system.d/nvidia-dbus.conf + fi # Install the programs. - for i in nvidia-cuda-mps-control nvidia-cuda-mps-server nvidia-smi nvidia-debugdump; do + for i in nvidia-cuda-mps-control nvidia-cuda-mps-server nvidia-smi nvidia-debugdump nvidia-powerd; do if [ -e "$i" ]; then install -Dm755 $i $bin/bin/$i # unmodified binary backup for mounting in containers diff --git a/pkgs/os-specific/linux/nvidia-x11/generic.nix b/pkgs/os-specific/linux/nvidia-x11/generic.nix index 2571812b9645..792fda42ca9c 100644 --- a/pkgs/os-specific/linux/nvidia-x11/generic.nix +++ b/pkgs/os-specific/linux/nvidia-x11/generic.nix @@ -51,6 +51,7 @@ let libdrm xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr xorg.libxcb zlib stdenv.cc.cc wayland mesa libGL openssl + dbus # for nvidia-powerd ]); self = stdenv.mkDerivation {