From afae933693b8909caf758fed6e90f3d61c503dd6 Mon Sep 17 00:00:00 2001 From: Piotr Bogdan Date: Thu, 11 Jun 2020 15:16:28 +0100 Subject: [PATCH] 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 2e6fadc26fc1..da627af73bc6 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}"; }; };