summary refs log tree commit diff
path: root/nixos/lib/utils.nix
diff options
context:
space:
mode:
authortalyz <kim.lindberger@gmail.com>2022-09-30 17:02:24 +0200
committerYureka <yuka@yuka.dev>2022-10-09 08:12:19 +0200
commit4df4d2a8eac999e47f973911857b9756281f8273 (patch)
treea49de96238ca7752569a24dc011a3f08184549c9 /nixos/lib/utils.nix
parentde25676c9f0954c9fdbb703cdb9326af9301ad50 (diff)
downloadnixpkgs-4df4d2a8eac999e47f973911857b9756281f8273.tar
nixpkgs-4df4d2a8eac999e47f973911857b9756281f8273.tar.gz
nixpkgs-4df4d2a8eac999e47f973911857b9756281f8273.tar.bz2
nixpkgs-4df4d2a8eac999e47f973911857b9756281f8273.tar.lz
nixpkgs-4df4d2a8eac999e47f973911857b9756281f8273.tar.xz
nixpkgs-4df4d2a8eac999e47f973911857b9756281f8273.tar.zst
nixpkgs-4df4d2a8eac999e47f973911857b9756281f8273.zip
genJqSecretsReplacementSnippet: Allow dots in attribute names...
...and escape quotation marks and backslashes.
Diffstat (limited to 'nixos/lib/utils.nix')
-rw-r--r--nixos/lib/utils.nix14
1 files changed, 9 insertions, 5 deletions
diff --git a/nixos/lib/utils.nix b/nixos/lib/utils.nix
index d7671a37499..f646f70323e 100644
--- a/nixos/lib/utils.nix
+++ b/nixos/lib/utils.nix
@@ -102,7 +102,11 @@ rec {
         if item ? ${attr} then
           nameValuePair prefix item.${attr}
         else if isAttrs item then
-          map (name: recurse (prefix + "." + name) item.${name}) (attrNames item)
+          map (name:
+            let
+              escapedName = ''"${replaceChars [''"'' "\\"] [''\"'' "\\\\"] name}"'';
+            in
+              recurse (prefix + "." + escapedName) item.${name}) (attrNames item)
         else if isList item then
           imap0 (index: item: recurse (prefix + "[${toString index}]") item) item
         else
@@ -182,13 +186,13 @@ rec {
                 '')
                (attrNames secrets))
     + "\n"
-    + "${pkgs.jq}/bin/jq >'${output}' '"
-    + concatStringsSep
+    + "${pkgs.jq}/bin/jq >'${output}' "
+    + lib.escapeShellArg (concatStringsSep
       " | "
       (imap1 (index: name: ''${name} = $ENV.secret${toString index}'')
-             (attrNames secrets))
+             (attrNames secrets)))
     + ''
-      ' <<'EOF'
+       <<'EOF'
       ${builtins.toJSON set}
       EOF
       (( ! $inherit_errexit_enabled )) && shopt -u inherit_errexit