summary refs log tree commit diff
path: root/lib/generators.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-09-17 18:14:18 +0200
committerSilvan Mosberger <contact@infinisil.com>2020-09-17 18:20:39 +0200
commit05e4d371ef5c3819b969d34eb76ed7e4b3c99027 (patch)
treebc93a039bb312d685153000223c9f060a08f665a /lib/generators.nix
parentd0be9e98109428e67e4b7fab3e49728cc6633073 (diff)
downloadnixpkgs-05e4d371ef5c3819b969d34eb76ed7e4b3c99027.tar
nixpkgs-05e4d371ef5c3819b969d34eb76ed7e4b3c99027.tar.gz
nixpkgs-05e4d371ef5c3819b969d34eb76ed7e4b3c99027.tar.bz2
nixpkgs-05e4d371ef5c3819b969d34eb76ed7e4b3c99027.tar.lz
nixpkgs-05e4d371ef5c3819b969d34eb76ed7e4b3c99027.tar.xz
nixpkgs-05e4d371ef5c3819b969d34eb76ed7e4b3c99027.tar.zst
nixpkgs-05e4d371ef5c3819b969d34eb76ed7e4b3c99027.zip
lib/generators.toPretty: Print [] and {} compactly
Diffstat (limited to 'lib/generators.nix')
-rw-r--r--lib/generators.nix7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/generators.nix b/lib/generators.nix
index 205092a2681..716ae77973f 100644
--- a/lib/generators.nix
+++ b/lib/generators.nix
@@ -230,13 +230,16 @@ rec {
     else if false ==   v then "false"
     else if null  ==   v then "null"
     else if isPath     v then toString v
-    else if isList     v then "[" + introSpace
+    else if isList     v then
+      if v == [] then "[ ]"
+      else "[" + introSpace
         + libStr.concatMapStringsSep introSpace (go (indent + "  ")) v
-      + outroSpace + "]"
+        + outroSpace + "]"
     else if isAttrs    v then
       # apply pretty values if allowed
       if attrNames v == [ "__pretty" "val" ] && allowPrettyValues
          then v.__pretty v.val
+      else if v == {} then "{ }"
       else if v ? type && v.type == "derivation" then
         "<derivation ${v.drvPath}>"
       else "{" + introSpace