2018-08-12 04:02:08 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.undervolt;
|
2020-06-11 15:42:40 +02:00
|
|
|
in
|
|
|
|
{
|
2018-08-12 04:02:08 +02:00
|
|
|
options.services.undervolt = {
|
2020-06-11 15:42:40 +02:00
|
|
|
enable = mkEnableOption
|
|
|
|
"Intel CPU undervolting service (WARNING: may permanently damage your hardware!)";
|
2018-08-12 04:02:08 +02:00
|
|
|
|
|
|
|
verbose = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable verbose logging.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.undervolt;
|
|
|
|
defaultText = "pkgs.undervolt";
|
|
|
|
description = ''
|
|
|
|
undervolt derivation to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
coreOffset = mkOption {
|
2020-06-11 15:55:14 +02:00
|
|
|
type = types.nullOr types.int;
|
2018-08-12 04:02:08 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-11 15:51:35 +02:00
|
|
|
The amount of voltage in mV to offset the CPU cores by.
|
2018-08-12 04:02:08 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
gpuOffset = mkOption {
|
2020-06-11 15:55:14 +02:00
|
|
|
type = types.nullOr types.int;
|
2018-08-12 04:02:08 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-11 15:51:35 +02:00
|
|
|
The amount of voltage in mV to offset the GPU by.
|
2018-08-12 04:02:08 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
uncoreOffset = mkOption {
|
2020-06-11 15:55:14 +02:00
|
|
|
type = types.nullOr types.int;
|
2018-08-12 04:02:08 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-11 15:51:35 +02:00
|
|
|
The amount of voltage in mV to offset uncore by.
|
2018-08-12 04:02:08 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
analogioOffset = mkOption {
|
2020-06-11 15:55:14 +02:00
|
|
|
type = types.nullOr types.int;
|
2018-08-12 04:02:08 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-11 15:51:35 +02:00
|
|
|
The amount of voltage in mV to offset analogio by.
|
2018-08-12 04:02:08 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
temp = mkOption {
|
2020-06-11 15:55:14 +02:00
|
|
|
type = types.nullOr types.int;
|
2018-08-12 04:02:08 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-11 15:51:35 +02:00
|
|
|
The temperature target in Celsius degrees.
|
2018-08-12 04:02:08 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tempAc = mkOption {
|
2020-06-11 15:55:14 +02:00
|
|
|
type = types.nullOr types.int;
|
2018-08-12 04:02:08 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-11 15:51:35 +02:00
|
|
|
The temperature target on AC power in Celsius degrees.
|
2018-08-12 04:02:08 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tempBat = mkOption {
|
2020-06-11 15:55:14 +02:00
|
|
|
type = types.nullOr types.int;
|
2018-08-12 04:02:08 +02:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-11 15:51:35 +02:00
|
|
|
The temperature target on battery power in Celsius degrees.
|
2018-08-12 04:02:08 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
boot.kernelModules = [ "msr" ];
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
systemd.services.undervolt = {
|
|
|
|
path = [ pkgs.undervolt ];
|
|
|
|
|
|
|
|
description = "Intel Undervolting Service";
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
Restart = "no";
|
|
|
|
|
|
|
|
# `core` and `cache` are both intentionally set to `cfg.coreOffset` as according to the undervolt docs:
|
|
|
|
#
|
|
|
|
# Core or Cache offsets have no effect. It is not possible to set different offsets for
|
|
|
|
# CPU Core and Cache. The CPU will take the smaller of the two offsets, and apply that to
|
|
|
|
# both CPU and Cache. A warning message will be displayed if you attempt to set different offsets.
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.undervolt}/bin/undervolt \
|
|
|
|
${optionalString cfg.verbose "--verbose"} \
|
2020-06-11 15:55:14 +02:00
|
|
|
${optionalString (cfg.coreOffset != null) "--core ${toString cfg.coreOffset}"} \
|
|
|
|
${optionalString (cfg.coreOffset != null) "--cache ${toString cfg.coreOffset}"} \
|
|
|
|
${optionalString (cfg.gpuOffset != null) "--gpu ${toString cfg.gpuOffset}"} \
|
|
|
|
${optionalString (cfg.uncoreOffset != null) "--uncore ${toString cfg.uncoreOffset}"} \
|
|
|
|
${optionalString (cfg.analogioOffset != null) "--analogio ${toString cfg.analogioOffset}"} \
|
|
|
|
${optionalString (cfg.temp != null) "--temp ${toString cfg.temp}"} \
|
|
|
|
${optionalString (cfg.tempAc != null) "--temp-ac ${toString cfg.tempAc}"} \
|
|
|
|
${optionalString (cfg.tempBat != null) "--temp-bat ${toString cfg.tempBat}"}
|
2018-08-12 04:02:08 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers.undervolt = {
|
|
|
|
description = "Undervolt timer to ensure voltage settings are always applied";
|
|
|
|
partOf = [ "undervolt.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnBootSec = "2min";
|
|
|
|
OnUnitActiveSec = "30";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|