diff options
Diffstat (limited to 'lib/strings.nix')
-rw-r--r-- | lib/strings.nix | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/strings.nix b/lib/strings.nix index aca9ef45e615d..9cbd1494a2b50 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -219,6 +219,14 @@ rec { */ escapeShellArgs = concatMapStringsSep " " escapeShellArg; + /* Turn a string into a Nix expression representing that string + + Example: + escapeNixString "hello\${}\n" + => "\"hello\\\${}\\n\"" + */ + escapeNixString = s: escape ["$"] (builtins.toJSON s); + /* Obsolete - use replaceStrings instead. */ replaceChars = builtins.replaceStrings or ( del: new: s: |