···
1
+
{ config, pkgs, lib, ... }:
6
+
cfg = config.services.undervolt;
8
+
options.services.undervolt = {
13
+
Whether to undervolt intel cpus.
17
+
verbose = mkOption {
21
+
Whether to enable verbose logging.
25
+
package = mkOption {
26
+
type = types.package;
27
+
default = pkgs.undervolt;
28
+
defaultText = "pkgs.undervolt";
30
+
undervolt derivation to use.
34
+
coreOffset = mkOption {
35
+
type = types.nullOr types.str;
38
+
The amount of voltage to offset the CPU cores by. Accepts a floating point number.
42
+
gpuOffset = mkOption {
43
+
type = types.nullOr types.str;
46
+
The amount of voltage to offset the GPU by. Accepts a floating point number.
50
+
uncoreOffset = mkOption {
51
+
type = types.nullOr types.str;
54
+
The amount of voltage to offset uncore by. Accepts a floating point number.
58
+
analogioOffset = mkOption {
59
+
type = types.nullOr types.str;
62
+
The amount of voltage to offset analogio by. Accepts a floating point number.
67
+
type = types.nullOr types.str;
70
+
The temperature target. Accepts a floating point number.
75
+
type = types.nullOr types.str;
78
+
The temperature target on AC power. Accepts a floating point number.
82
+
tempBat = mkOption {
83
+
type = types.nullOr types.str;
86
+
The temperature target on battery power. Accepts a floating point number.
91
+
config = mkIf cfg.enable {
92
+
boot.kernelModules = [ "msr" ];
94
+
environment.systemPackages = [ cfg.package ];
96
+
systemd.services.undervolt = {
97
+
path = [ pkgs.undervolt ];
99
+
description = "Intel Undervolting Service";
104
+
# `core` and `cache` are both intentionally set to `cfg.coreOffset` as according to the undervolt docs:
106
+
# Core or Cache offsets have no effect. It is not possible to set different offsets for
107
+
# CPU Core and Cache. The CPU will take the smaller of the two offsets, and apply that to
108
+
# both CPU and Cache. A warning message will be displayed if you attempt to set different offsets.
110
+
${pkgs.undervolt}/bin/undervolt \
111
+
${optionalString cfg.verbose "--verbose"} \
112
+
${optionalString (cfg.coreOffset != null) "--core ${cfg.coreOffset}"} \
113
+
${optionalString (cfg.coreOffset != null) "--cache ${cfg.coreOffset}"} \
114
+
${optionalString (cfg.gpuOffset != null) "--gpu ${cfg.gpuOffset}"} \
115
+
${optionalString (cfg.uncoreOffset != null) "--uncore ${cfg.uncoreOffset}"} \
116
+
${optionalString (cfg.analogioOffset != null) "--analogio ${cfg.analogioOffset}"} \
117
+
${optionalString (cfg.temp != null) "--temp ${cfg.temp}"} \
118
+
${optionalString (cfg.tempAc != null) "--temp-ac ${cfg.tempAc}"} \
119
+
${optionalString (cfg.tempBat != null) "--temp-bat ${cfg.tempBat}"}
124
+
systemd.timers.undervolt = {
125
+
description = "Undervolt timer to ensure voltage settings are always applied";
126
+
partOf = [ "undervolt.service" ];
127
+
wantedBy = [ "multi-user.target" ];
129
+
OnBootSec = "2min";
130
+
OnUnitActiveSec = "30";