Merge pull request #95011 from Atemu/undervolt-pl

undervolt: expose power limits as Nixopts
This commit is contained in:
Timo Kaufmann 2020-10-30 09:32:50 +01:00 committed by GitHub
commit 83f48e8348
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,12 @@
with lib; with lib;
let let
cfg = config.services.undervolt; cfg = config.services.undervolt;
cliArgs = lib.cli.toGNUCommandLineShell {} {
mkPLimit = limit: window:
if (isNull limit && isNull window) then null
else assert asserts.assertMsg (!isNull limit && !isNull window) "Both power limit and window must be set";
"${toString limit} ${toString window}";
cliArgs = lib.cli.toGNUCommandLine {} {
inherit (cfg) inherit (cfg)
verbose verbose
temp temp
@ -21,6 +26,9 @@ let
temp-bat = cfg.tempBat; temp-bat = cfg.tempBat;
temp-ac = cfg.tempAc; temp-ac = cfg.tempAc;
power-limit-long = mkPLimit cfg.p1.limit cfg.p1.window;
power-limit-short = mkPLimit cfg.p2.limit cfg.p2.window;
}; };
in in
{ {
@ -104,6 +112,40 @@ in
''; '';
}; };
p1.limit = mkOption {
type = with types; nullOr int;
default = null;
description = ''
The P1 Power Limit in Watts.
Both limit and window must be set.
'';
};
p1.window = mkOption {
type = with types; nullOr (oneOf [ float int ]);
default = null;
description = ''
The P1 Time Window in seconds.
Both limit and window must be set.
'';
};
p2.limit = mkOption {
type = with types; nullOr int;
default = null;
description = ''
The P2 Power Limit in Watts.
Both limit and window must be set.
'';
};
p2.window = mkOption {
type = with types; nullOr (oneOf [ float int ]);
default = null;
description = ''
The P2 Time Window in seconds.
Both limit and window must be set.
'';
};
useTimer = mkOption { useTimer = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
@ -133,7 +175,7 @@ in
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
Restart = "no"; Restart = "no";
ExecStart = "${pkgs.undervolt}/bin/undervolt ${cliArgs}"; ExecStart = "${pkgs.undervolt}/bin/undervolt ${toString cliArgs}";
}; };
}; };