2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.undervolt;
|
2020-06-15 15:56:04 +00:00
|
|
|
cliArgs = lib.cli.toGNUCommandLineShell {} {
|
|
|
|
inherit (cfg)
|
|
|
|
verbose
|
|
|
|
temp
|
|
|
|
;
|
|
|
|
# `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.
|
|
|
|
core = cfg.coreOffset;
|
|
|
|
cache = cfg.coreOffset;
|
|
|
|
gpu = cfg.gpuOffset;
|
|
|
|
uncore = cfg.uncoreOffset;
|
|
|
|
analogio = cfg.analogioOffset;
|
|
|
|
|
|
|
|
temp-bat = cfg.tempBat;
|
|
|
|
temp-ac = cfg.tempAc;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2020-04-24 23:36:52 +00:00
|
|
|
options.services.undervolt = {
|
2020-07-18 16:06:22 +00:00
|
|
|
enable = mkEnableOption ''
|
|
|
|
Undervolting service for Intel CPUs.
|
|
|
|
|
|
|
|
Warning: This service is not endorsed by Intel and may permanently damage your hardware. Use at your own risk!
|
|
|
|
'';
|
2020-04-24 23:36:52 +00: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-15 15:56:04 +00:00
|
|
|
type = types.nullOr types.int;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-15 15:56:04 +00:00
|
|
|
The amount of voltage in mV to offset the CPU cores by.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
gpuOffset = mkOption {
|
2020-06-15 15:56:04 +00:00
|
|
|
type = types.nullOr types.int;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-15 15:56:04 +00:00
|
|
|
The amount of voltage in mV to offset the GPU by.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
uncoreOffset = mkOption {
|
2020-06-15 15:56:04 +00:00
|
|
|
type = types.nullOr types.int;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-15 15:56:04 +00:00
|
|
|
The amount of voltage in mV to offset uncore by.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
analogioOffset = mkOption {
|
2020-06-15 15:56:04 +00:00
|
|
|
type = types.nullOr types.int;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-15 15:56:04 +00:00
|
|
|
The amount of voltage in mV to offset analogio by.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
temp = mkOption {
|
2020-06-15 15:56:04 +00:00
|
|
|
type = types.nullOr types.int;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-15 15:56:04 +00:00
|
|
|
The temperature target in Celsius degrees.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tempAc = mkOption {
|
2020-06-15 15:56:04 +00:00
|
|
|
type = types.nullOr types.int;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-15 15:56:04 +00:00
|
|
|
The temperature target on AC power in Celsius degrees.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tempBat = mkOption {
|
2020-06-15 15:56:04 +00:00
|
|
|
type = types.nullOr types.int;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-06-15 15:56:04 +00:00
|
|
|
The temperature target on battery power in Celsius degrees.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
useTimer = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to set a timer that applies the undervolt settings every 30s.
|
|
|
|
This will cause spam in the journal but might be required for some
|
|
|
|
hardware under specific conditions.
|
|
|
|
Enable this if your undervolt settings don't hold.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
boot.kernelModules = [ "msr" ];
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
systemd.services.undervolt = {
|
|
|
|
path = [ pkgs.undervolt ];
|
|
|
|
|
|
|
|
description = "Intel Undervolting Service";
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
# Apply undervolt on boot, nixos generation switch and resume
|
|
|
|
wantedBy = [ "multi-user.target" "post-resume.target" ];
|
|
|
|
after = [ "post-resume.target" ]; # Not sure why but it won't work without this
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
Restart = "no";
|
2020-06-15 15:56:04 +00:00
|
|
|
ExecStart = "${pkgs.undervolt}/bin/undervolt ${cliArgs}";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
systemd.timers.undervolt = mkIf cfg.useTimer {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Undervolt timer to ensure voltage settings are always applied";
|
|
|
|
partOf = [ "undervolt.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnBootSec = "2min";
|
|
|
|
OnUnitActiveSec = "30";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|