From 6fb11e5227ec84acee9ac9e28694583783ce0b61 Mon Sep 17 00:00:00 2001 From: Piotr Bogdan Date: Thu, 11 Jun 2020 14:42:40 +0100 Subject: [PATCH 1/4] nixos/undervolt: add a warning for the `enable` option Also use the convenience `mkEnableOption` function for simplicity. --- nixos/modules/services/hardware/undervolt.nix | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/nixos/modules/services/hardware/undervolt.nix b/nixos/modules/services/hardware/undervolt.nix index e5ef0601de3..284440975fe 100644 --- a/nixos/modules/services/hardware/undervolt.nix +++ b/nixos/modules/services/hardware/undervolt.nix @@ -1,18 +1,13 @@ { config, pkgs, lib, ... }: with lib; - let cfg = config.services.undervolt; -in { +in +{ options.services.undervolt = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Whether to undervolt intel cpus. - ''; - }; + enable = mkEnableOption + "Intel CPU undervolting service (WARNING: may permanently damage your hardware!)"; verbose = mkOption { type = types.bool; From f224b243db40b79d8d6bc65916cc7b419c555c12 Mon Sep 17 00:00:00 2001 From: Piotr Bogdan Date: Thu, 11 Jun 2020 14:51:35 +0100 Subject: [PATCH 2/4] nixos/undervolt: fix up options' descriptions The default `undervolt` package does not accept floating point numbers for any of its numeric arguments. This also mentions in what units are the values expressed. --- nixos/modules/services/hardware/undervolt.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/hardware/undervolt.nix b/nixos/modules/services/hardware/undervolt.nix index 284440975fe..1e89e74cad0 100644 --- a/nixos/modules/services/hardware/undervolt.nix +++ b/nixos/modules/services/hardware/undervolt.nix @@ -30,7 +30,7 @@ in type = types.nullOr types.str; default = null; description = '' - The amount of voltage to offset the CPU cores by. Accepts a floating point number. + The amount of voltage in mV to offset the CPU cores by. ''; }; @@ -38,7 +38,7 @@ in type = types.nullOr types.str; default = null; description = '' - The amount of voltage to offset the GPU by. Accepts a floating point number. + The amount of voltage in mV to offset the GPU by. ''; }; @@ -46,7 +46,7 @@ in type = types.nullOr types.str; default = null; description = '' - The amount of voltage to offset uncore by. Accepts a floating point number. + The amount of voltage in mV to offset uncore by. ''; }; @@ -54,7 +54,7 @@ in type = types.nullOr types.str; default = null; description = '' - The amount of voltage to offset analogio by. Accepts a floating point number. + The amount of voltage in mV to offset analogio by. ''; }; @@ -62,7 +62,7 @@ in type = types.nullOr types.str; default = null; description = '' - The temperature target. Accepts a floating point number. + The temperature target in Celsius degrees. ''; }; @@ -70,7 +70,7 @@ in type = types.nullOr types.str; default = null; description = '' - The temperature target on AC power. Accepts a floating point number. + The temperature target on AC power in Celsius degrees. ''; }; @@ -78,7 +78,7 @@ in type = types.nullOr types.str; default = null; description = '' - The temperature target on battery power. Accepts a floating point number. + The temperature target on battery power in Celsius degrees. ''; }; }; From 24e0e056541369dd8559c74bdf0f5060eb518b8c Mon Sep 17 00:00:00 2001 From: Piotr Bogdan Date: Thu, 11 Jun 2020 14:55:14 +0100 Subject: [PATCH 3/4] nixos/undervolt: use `int` type for numeric options --- nixos/modules/services/hardware/undervolt.nix | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/nixos/modules/services/hardware/undervolt.nix b/nixos/modules/services/hardware/undervolt.nix index 1e89e74cad0..2e6fadc26fc 100644 --- a/nixos/modules/services/hardware/undervolt.nix +++ b/nixos/modules/services/hardware/undervolt.nix @@ -27,7 +27,7 @@ in }; coreOffset = mkOption { - type = types.nullOr types.str; + type = types.nullOr types.int; default = null; description = '' The amount of voltage in mV to offset the CPU cores by. @@ -35,7 +35,7 @@ in }; gpuOffset = mkOption { - type = types.nullOr types.str; + type = types.nullOr types.int; default = null; description = '' The amount of voltage in mV to offset the GPU by. @@ -43,7 +43,7 @@ in }; uncoreOffset = mkOption { - type = types.nullOr types.str; + type = types.nullOr types.int; default = null; description = '' The amount of voltage in mV to offset uncore by. @@ -51,7 +51,7 @@ in }; analogioOffset = mkOption { - type = types.nullOr types.str; + type = types.nullOr types.int; default = null; description = '' The amount of voltage in mV to offset analogio by. @@ -59,7 +59,7 @@ in }; temp = mkOption { - type = types.nullOr types.str; + type = types.nullOr types.int; default = null; description = '' The temperature target in Celsius degrees. @@ -67,7 +67,7 @@ in }; tempAc = mkOption { - type = types.nullOr types.str; + type = types.nullOr types.int; default = null; description = '' The temperature target on AC power in Celsius degrees. @@ -75,7 +75,7 @@ in }; tempBat = mkOption { - type = types.nullOr types.str; + type = types.nullOr types.int; default = null; description = '' The temperature target on battery power in Celsius degrees. @@ -104,14 +104,14 @@ in ExecStart = '' ${pkgs.undervolt}/bin/undervolt \ ${optionalString cfg.verbose "--verbose"} \ - ${optionalString (cfg.coreOffset != null) "--core ${cfg.coreOffset}"} \ - ${optionalString (cfg.coreOffset != null) "--cache ${cfg.coreOffset}"} \ - ${optionalString (cfg.gpuOffset != null) "--gpu ${cfg.gpuOffset}"} \ - ${optionalString (cfg.uncoreOffset != null) "--uncore ${cfg.uncoreOffset}"} \ - ${optionalString (cfg.analogioOffset != null) "--analogio ${cfg.analogioOffset}"} \ - ${optionalString (cfg.temp != null) "--temp ${cfg.temp}"} \ - ${optionalString (cfg.tempAc != null) "--temp-ac ${cfg.tempAc}"} \ - ${optionalString (cfg.tempBat != null) "--temp-bat ${cfg.tempBat}"} + ${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}"} ''; }; }; From afae933693b8909caf758fed6e90f3d61c503dd6 Mon Sep 17 00:00:00 2001 From: Piotr Bogdan Date: Thu, 11 Jun 2020 15:16:28 +0100 Subject: [PATCH 4/4] nixos/undervolt: simplify CLI args generation --- nixos/modules/services/hardware/undervolt.nix | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/nixos/modules/services/hardware/undervolt.nix b/nixos/modules/services/hardware/undervolt.nix index 2e6fadc26fc..da627af73bc 100644 --- a/nixos/modules/services/hardware/undervolt.nix +++ b/nixos/modules/services/hardware/undervolt.nix @@ -3,6 +3,25 @@ with lib; let cfg = config.services.undervolt; + 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 { options.services.undervolt = { @@ -95,24 +114,7 @@ in 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"} \ - ${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}"} - ''; + ExecStart = "${pkgs.undervolt}/bin/undervolt ${cliArgs}"; }; };