git.iko.soy/typeable/nixpkgs
on master help sign in
nixpkgs.lib: Add escapeNixString
commit6281eb123bcdefcaebbd973600f4d33772012025 authorRyan Trinkle <ryan.trinkle@gmail.com> dateSat 2 Dec 2017, 13:03 (9 years ago) parent7d27f25
1 file changed+8
lib/strings.nix+8
lib/strings.nix+8
@@ -219,6 +219,14 @@ rec {
219219 */
220220 escapeShellArgs = concatMapStringsSep " " escapeShellArg;
221221
222+ /* Turn a string into a Nix expression representing that string
223+
224+ Example:
225+ escapeNixString "hello\${}\n"
226+ => "\"hello\\\${}\\n\""
227+ */
228+ escapeNixString = s: escape ["$"] (builtins.toJSON s);
229+
222230 /* Obsolete - use replaceStrings instead. */
223231 replaceChars = builtins.replaceStrings or (
224232 del: new: s: