git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #44919 from Vodurden/init-undervolt

undervolt: init at 0.2.8

commit05310e3172fb0e5524a649ee31f3a9fecb95769e authorSamuel Dionne-Riel <samuel@dionne-riel.com> dateWed 22 Aug 2018, 10:13 (8 years ago) parent899e19a4142020
4 files changed+164
nixos/modules/module-list.nix+1 nixos/modules/services/hardware/undervolt.nix+134 pkgs/os-specific/linux/undervolt/default.nix+27 pkgs/top-level/all-packages.nix+2
nixos/modules/module-list.nix+1
@@ -281,6 +281,7 @@
281281 ./services/hardware/upower.nix
282282 ./services/hardware/usbmuxd.nix
283283 ./services/hardware/thermald.nix
284+ ./services/hardware/undervolt.nix
284285 ./services/logging/SystemdJournal2Gelf.nix
285286 ./services/logging/awstats.nix
286287 ./services/logging/fluentd.nix
nixos/modules/services/hardware/undervolt.nixnew file+134
@@ -0,0 +1,134 @@
1+{ config, pkgs, lib, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.undervolt;
7+in {
8+ options.services.undervolt = {
9+ enable = mkOption {
10+ type = types.bool;
11+ default = false;
12+ description = ''
13+ Whether to undervolt intel cpus.
14+ '';
15+ };
16+
17+ verbose = mkOption {
18+ type = types.bool;
19+ default = false;
20+ description = ''
21+ Whether to enable verbose logging.
22+ '';
23+ };
24+
25+ package = mkOption {
26+ type = types.package;
27+ default = pkgs.undervolt;
28+ defaultText = "pkgs.undervolt";
29+ description = ''
30+ undervolt derivation to use.
31+ '';
32+ };
33+
34+ coreOffset = mkOption {
35+ type = types.nullOr types.str;
36+ default = null;
37+ description = ''
38+ The amount of voltage to offset the CPU cores by. Accepts a floating point number.
39+ '';
40+ };
41+
42+ gpuOffset = mkOption {
43+ type = types.nullOr types.str;
44+ default = null;
45+ description = ''
46+ The amount of voltage to offset the GPU by. Accepts a floating point number.
47+ '';
48+ };
49+
50+ uncoreOffset = mkOption {
51+ type = types.nullOr types.str;
52+ default = null;
53+ description = ''
54+ The amount of voltage to offset uncore by. Accepts a floating point number.
55+ '';
56+ };
57+
58+ analogioOffset = mkOption {
59+ type = types.nullOr types.str;
60+ default = null;
61+ description = ''
62+ The amount of voltage to offset analogio by. Accepts a floating point number.
63+ '';
64+ };
65+
66+ temp = mkOption {
67+ type = types.nullOr types.str;
68+ default = null;
69+ description = ''
70+ The temperature target. Accepts a floating point number.
71+ '';
72+ };
73+
74+ tempAc = mkOption {
75+ type = types.nullOr types.str;
76+ default = null;
77+ description = ''
78+ The temperature target on AC power. Accepts a floating point number.
79+ '';
80+ };
81+
82+ tempBat = mkOption {
83+ type = types.nullOr types.str;
84+ default = null;
85+ description = ''
86+ The temperature target on battery power. Accepts a floating point number.
87+ '';
88+ };
89+ };
90+
91+ config = mkIf cfg.enable {
92+ boot.kernelModules = [ "msr" ];
93+
94+ environment.systemPackages = [ cfg.package ];
95+
96+ systemd.services.undervolt = {
97+ path = [ pkgs.undervolt ];
98+
99+ description = "Intel Undervolting Service";
100+ serviceConfig = {
101+ Type = "oneshot";
102+ Restart = "no";
103+
104+ # `core` and `cache` are both intentionally set to `cfg.coreOffset` as according to the undervolt docs:
105+ #
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.
109+ ExecStart = ''
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}"}
120+ '';
121+ };
122+ };
123+
124+ systemd.timers.undervolt = {
125+ description = "Undervolt timer to ensure voltage settings are always applied";
126+ partOf = [ "undervolt.service" ];
127+ wantedBy = [ "multi-user.target" ];
128+ timerConfig = {
129+ OnBootSec = "2min";
130+ OnUnitActiveSec = "30";
131+ };
132+ };
133+ };
134+}
pkgs/os-specific/linux/undervolt/default.nixnew file+27
@@ -0,0 +1,27 @@
1+{ stdenv, fetchFromGitHub, python3Packages }:
2+
3+python3Packages.buildPythonApplication rec {
4+ version = "0.2.8";
5+ pname = "undervolt";
6+
7+ src = fetchFromGitHub {
8+ owner = "georgewhewell";
9+ repo = "undervolt";
10+ rev = "${version}";
11+ sha256 = "0crkqc5zq0gpyg031hfwdxymfc2gc1h8b6m0axzlh7gvnxlf5hra";
12+ };
13+
14+ meta = with stdenv.lib; {
15+ homepage = https://github.com/georgewhewell/undervolt/;
16+ description = "A program for undervolting Intel CPUs on Linux";
17+
18+ longDescription = ''
19+ Undervolt is a program for undervolting Intel CPUs under Linux. It works in a similar
20+ manner to the Windows program ThrottleStop (i.e, MSR 0x150). You can apply a fixed
21+ voltage offset to one of 5 voltage planes, and override your systems temperature
22+ target (CPU will throttle when this temperature is reached).
23+ '';
24+ license = licenses.gpl2;
25+ platforms = [ "x86_64-linux" ];
26+ };
27+}
pkgs/top-level/all-packages.nix+2
@@ -22195,4 +22195,6 @@ with pkgs;
2219522195 powershell = callPackage ../shells/powershell { };
2219622196
2219722197 doing = callPackage ../applications/misc/doing { };
22198+
22199+ undervolt = callPackage ../os-specific/linux/undervolt { };
2219822200}