I’m trying to make services to switch the power limit of my Nvidia deivce, by using sudo nvidia-smi -pl <POWER_NUMBER>
. Here’s my flake file.
/etc/nixos/modules/nvidia.nix
{ config, lib, pkgs, ... }:
{
config = {
# environment.systemPackages = with pkgs; [
# (config.boot.kernelPackages.nvidiaPackages.beta)
# ];
systemd.timers."nvidia-power-limit-high" = {
wantedBy = [ "timers.target" ];
timerConfig = {
Unit = "nvidia-power-limit-high.service";
OnCalendar = "*-*-* 1:50:00";
};
};
systemd.services."nvidia-power-limit-high" = {
script = ''
nvidia-smi -pl 280
'';
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
systemd.timers."nvidia-power-limit-low" = {
wantedBy = [ "timers.target" ];
timerConfig = {
Unit = "nvidia-power-limit-low.service";
OnCalendar = "*-*-* 6:00:00";
Persistent = true;
};
};
systemd.services."nvidia-power-limit-low" = {
script = ''
nvidia-smi -pl 120
'';
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
};
}
But it says nvidia-smi command not found
. (Ignore that mismatch of time, it’s just for tests.)
systemctl status nvidia-power-limit-high.service (ai)
○ nvidia-power-limit-high.service
Loaded: loaded (/etc/systemd/system/nvidia-power-limit-high.service; linked; preset: ignored)
Active: inactive (dead) since Sat 2025-02-22 18:48:00 CST; 55min ago
Invocation: 442663f238b341e1b921a80c8f088816
TriggeredBy: ● nvidia-power-limit-high.timer
Main PID: 1003678 (code=exited, status=127)
IO: 0B read, 0B written
Mem peak: 1.8M
CPU: 5ms
Feb 22 18:48:00 nixos systemd[1]: Starting nvidia-power-limit-high.service...
Feb 22 18:48:00 nixos nvidia-power-limit-high-start[1003679]: /nix/store/pynlrbqmlm93ld223n48h91kj3k7dj78-unit-script-nvidia-power-limit-high-start/bin/nvidia-power-limit-high-start: line 4: nvidia-smi: command not found
Feb 22 18:48:00 nixos systemd[1]: nvidia-power-limit-high.service: Main process exited, code=exited, status=127/n/a
Feb 22 18:48:00 nixos systemd[1]: nvidia-power-limit-high.service: Failed with result 'exit-code'.
Feb 22 18:48:00 nixos systemd[1]: Failed to start nvidia-power-limit-high.service.
I did read the wiki, it says an executable binary file should be referenced by a ${pkgs.???}
path, such as ${pkgs.git}/bin/git
. But I can’t find which package that starts with “pkgs.
” contains nvidia-smi
. Do I miss something important? Thanks for your help.