summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorPiotr Bogdan <ppbogdan@gmail.com>2020-06-11 15:16:28 +0100
committerPiotr Bogdan <ppbogdan@gmail.com>2020-06-11 15:24:28 +0100
commitafae933693b8909caf758fed6e90f3d61c503dd6 (patch)
tree1e10bab6757e7cb70a29ae3be32e5d6bb1968e5f /nixos
parent24e0e056541369dd8559c74bdf0f5060eb518b8c (diff)
downloadnixpkgs-afae933693b8909caf758fed6e90f3d61c503dd6.tar
nixpkgs-afae933693b8909caf758fed6e90f3d61c503dd6.tar.gz
nixpkgs-afae933693b8909caf758fed6e90f3d61c503dd6.tar.bz2
nixpkgs-afae933693b8909caf758fed6e90f3d61c503dd6.tar.lz
nixpkgs-afae933693b8909caf758fed6e90f3d61c503dd6.tar.xz
nixpkgs-afae933693b8909caf758fed6e90f3d61c503dd6.tar.zst
nixpkgs-afae933693b8909caf758fed6e90f3d61c503dd6.zip
nixos/undervolt: simplify CLI args generation
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/hardware/undervolt.nix38
1 files 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}";
       };
     };