From 6281eb123bcdefcaebbd973600f4d33772012025 Mon Sep 17 00:00:00 2001 From: Ryan Trinkle Date: Sat, 2 Dec 2017 13:03:40 -0500 Subject: [PATCH] nixpkgs.lib: Add escapeNixString --- lib/strings.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/strings.nix b/lib/strings.nix index aca9ef45e615..9cbd1494a2b5 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: