diff options
author | Profpatsch <mail@profpatsch.de> | 2018-03-26 17:26:20 +0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2018-03-29 16:53:06 +0200 |
commit | 219ba583b269b1adc8f2bf57604f9204acb2cf56 (patch) | |
tree | 7ba6a16df46db97bbfd73fe88fb1ca6f91d0f2b1 | |
parent | e0ae89007bad6e6b9c9fbf1fee1a5304be18f277 (diff) |
lib/generators: improve toPretty
* properly escape strings * remove one check for booleans * improve error message
-rw-r--r-- | lib/generators.nix | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/generators.nix b/lib/generators.nix index 73017f2c67968..64399ddd50a5a 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -98,6 +98,7 @@ rec { */ toYAML = {}@args: toJSON args; + /* Pretty print a value, akin to `builtins.trace`. * Should probably be a builtin as well. */ @@ -108,8 +109,9 @@ rec { allowPrettyValues ? false }@args: v: with builtins; if isInt v then toString v - else if isBool v then (if v == true then "true" else "false") - else if isString v then "\"" + v + "\"" + else if isString v then ''"${libStr.escape [''"''] v}"'' + else if true == v then "true" + else if false == v then "false" else if null == v then "null" else if isFunction v then let fna = lib.functionArgs v; @@ -132,6 +134,6 @@ rec { (name: value: "${toPretty args name} = ${toPretty args value};") v) + " }" - else abort "toPretty: should never happen (v = ${v})"; + else abort "generators.toPretty: should never happen (v = ${v})"; } |