about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--lib/cli.nix11
-rw-r--r--lib/tests/misc.nix21
-rw-r--r--nixos/modules/services/home-automation/ebusd.nix2
3 files changed, 32 insertions, 2 deletions
diff --git a/lib/cli.nix b/lib/cli.nix
index fcffacb5ea996..311037c519a65 100644
--- a/lib/cli.nix
+++ b/lib/cli.nix
@@ -90,7 +90,16 @@ rec {
     mkOption ?
       k: v: if v == null
             then []
-            else [ (mkOptionName k) (lib.generators.mkValueStringDefault {} v) ]
+            else if optionValueSeparator == null then
+              [ (mkOptionName k) (lib.generators.mkValueStringDefault {} v) ]
+            else
+              [ "${mkOptionName k}${optionValueSeparator}${lib.generators.mkValueStringDefault {} v}" ],
+
+    # how to separate an option from its flag;
+    # by default, there is no separator, so option `-c` and value `5`
+    # would become ["-c" "5"].
+    # This is useful if the command requires equals, for example, `-c=5`.
+    optionValueSeparator ? null
     }:
     options:
       let
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index 6774939023d20..408ea54162938 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -1639,6 +1639,27 @@ runTests {
     ];
   };
 
+  testToGNUCommandLineSeparator = {
+    expr = cli.toGNUCommandLine { optionValueSeparator = "="; } {
+      data = builtins.toJSON { id = 0; };
+      X = "PUT";
+      retry = 3;
+      retry-delay = null;
+      url = [ "https://example.com/foo" "https://example.com/bar" ];
+      silent = false;
+      verbose = true;
+    };
+
+    expected = [
+      "-X=PUT"
+      "--data={\"id\":0}"
+      "--retry=3"
+      "--url=https://example.com/foo"
+      "--url=https://example.com/bar"
+      "--verbose"
+    ];
+  };
+
   testToGNUCommandLineShell = {
     expr = cli.toGNUCommandLineShell {} {
       data = builtins.toJSON { id = 0; };
diff --git a/nixos/modules/services/home-automation/ebusd.nix b/nixos/modules/services/home-automation/ebusd.nix
index ac9ec06639c13..f5c5479e8eaff 100644
--- a/nixos/modules/services/home-automation/ebusd.nix
+++ b/nixos/modules/services/home-automation/ebusd.nix
@@ -138,7 +138,7 @@ in
       after = [ "network.target" ];
       serviceConfig = {
         ExecStart = let
-          args = cli.toGNUCommandLineShell { } (foldr (a: b: a // b) { } [
+          args = cli.toGNUCommandLineShell { optionValueSeparator = "="; } (foldr (a: b: a // b) { } [
             {
               inherit (cfg) device port configpath scanconfig readonly;
               foreground = true;