summaryrefslogtreecommitdiffstats
path: root/lib/generators.nix
diff options
context:
space:
mode:
authorRobert Helgesson <robert@rycee.net>2023-09-11 23:44:42 +0200
committerGitHub <noreply@github.com>2023-09-11 23:44:42 +0200
commit54bc9b45a386d3450475ccfdd0e5ae35240430cf (patch)
tree7ac4ff75661126aaa43821d18849c2d7318ceaa7 /lib/generators.nix
parent804d0108a8ddfca27534ba696c058bc0fa5dd82a (diff)
parent147560180c5b39266d10c6a6b8f54110d9667b99 (diff)
Merge pull request #250220
lib.generators.toGitINI: escape string values in configuration
Diffstat (limited to 'lib/generators.nix')
-rw-r--r--lib/generators.nix14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/generators.nix b/lib/generators.nix
index 0368577d5a51..8e93ed04916e 100644
--- a/lib/generators.nix
+++ b/lib/generators.nix
@@ -189,10 +189,10 @@ rec {
* }
*
*> [url "ssh://git@github.com/"]
- *> insteadOf = https://github.com/
+ *> insteadOf = "https://github.com"
*>
*> [user]
- *> name = edolstra
+ *> name = "edolstra"
*/
toGitINI = attrs:
with builtins;
@@ -209,9 +209,17 @@ rec {
else
''${section} "${subsection}"'';
+ mkValueString = v:
+ let
+ escapedV = ''
+ "${
+ replaceStrings [ "\n" " " ''"'' "\\" ] [ "\\n" "\\t" ''\"'' "\\\\" ] v
+ }"'';
+ in mkValueStringDefault { } (if isString v then escapedV else v);
+
# generation for multiple ini values
mkKeyValue = k: v:
- let mkKeyValue = mkKeyValueDefault { } " = " k;
+ let mkKeyValue = mkKeyValueDefault { inherit mkValueString; } " = " k;
in concatStringsSep "\n" (map (kv: "\t" + mkKeyValue kv) (lib.toList v));
# converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI