Last active
July 7, 2025 09:26
-
-
Save Lillecarl/ac39eaf7755320619d9a5df6f0ef71b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Apply function to all strings in an attrset recursively through lists as well. | |
mapStringsDeep = | |
function: value: | |
if builtins.isString value then | |
function value | |
else if builtins.isAttrs value then | |
lib.mapAttrs (name: mapStringsDeep function) value | |
else if builtins.isList value then | |
map (mapStringsDeep function) value | |
else | |
value; | |
# Escapes strings so variables aren't interpolated with ${} and %{} | |
tfEscapeString = | |
value: | |
lib.replaceStrings | |
[ | |
# Nix and tf shares this escape pattern | |
"$$\{" | |
# tf also interpolates %{} | |
"%{" | |
] | |
[ | |
"\${" | |
"%%{" | |
] | |
value; | |
# Escape | |
escapeStringsDeep = attrs: mapStringsDeep tfEscapeString attrs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment