@ -195,6 +195,30 @@ rec {
* /
toYAML = { } @ args : toJSON args ;
withRecursion =
args @ {
/* I f t h i s o p t i o n i s n o t n u l l , ` t o P r e t t y ` w i l l s t o p e v a l u a t i n g a t a c e r t a i n d e p t h */
depthLimit
/* I f t h i s o p t i o n i s t r u e , a n e r r o r w i l l b e t h r o w n , i f a c e r t a i n g i v e n d e p t h i s e x c e e d e d */
, throwOnDepthLimit ? true
} :
assert builtins . isInt depthLimit ;
let
transform = depth :
if depthLimit != null && depth > depthLimit then
if throwOnDepthLimit
then throw " E x c e e d e d m a x i m u m e v a l - d e p t h l i m i t o f ${ toString depthLimit } w h i l e t r y i n g t o p r e t t y - p r i n t w i t h ` g e n e r a t o r s . w i t h R e c u r s i o n ' ! "
else const " < u n e v a l u a t e d > "
else id ;
mapAny = with builtins ; depth : v :
let
evalNext = x : mapAny ( depth + 1 ) ( transform ( depth + 1 ) x ) ;
in
if isAttrs v then mapAttrs ( const evalNext ) v
else if isList v then map evalNext v
else transform ( depth + 1 ) v ;
in
mapAny 0 ;
/* P r e t t y p r i n t a v a l u e , a k i n t o ` b u i l t i n s . t r a c e ` .
* Should probably be a builtin as well .
@ -205,23 +229,14 @@ rec {
( This means fn is type Val -> String . ) * /
allowPrettyValues ? false ,
/* I f t h i s o p t i o n i s t r u e , t h e o u t p u t i s i n d e n t e d w i t h n e w l i n e s f o r a t t r i b u t e s e t s a n d l i s t s */
multiline ? true ,
/* I f t h i s o p t i o n i s n o t n u l l , ` t o P r e t t y ` w i l l s t o p e v a l u a t i n g a t a c e r t a i n d e p t h */
depthLimit ? null ,
/* I f t h i s o p t i o n i s t r u e , a n e r r o r w i l l b e t h r o w n , i f a c e r t a i n g i v e n d e p t h i s e x c e e d e d */
throwOnDepthLimit ? false
multiline ? true
} @ args :
assert depthLimit != null -> builtins . isInt depthLimit ;
assert throwOnDepthLimit -> depthLimit != null ;
let
go = depth : indent : v : with builtins ;
go = indent : v : with builtins ;
let isPath = v : typeOf v == " p a t h " ;
introSpace = if multiline then " \n ${ indent } " else " " ;
outroSpace = if multiline then " \n ${ indent } " else " " ;
in if depthLimit != null && depth > depthLimit then
if throwOnDepthLimit then throw " E x c e e d e d m a x i m u m e v a l - d e p t h l i m i t o f ${ toString depthLimit } w h i l e t r y i n g t o p r e t t y - p r i n t w i t h ` g e n e r a t o r s . t o P r e t t y ' ! "
else " < u n e v a l u a t e d > "
else if isInt v then toString v
in if isInt v then toString v
else if isFloat v then " ~ ${ toString v } "
else if isString v then
let
@ -243,7 +258,7 @@ rec {
else if isList v then
if v == [ ] then " [ ] "
else " [ " + introSpace
+ libStr . concatMapStringsSep introSpace ( go ( depth + 1 ) ( indent + " " ) ) v
+ libStr . concatMapStringsSep introSpace ( go ( indent + " " ) ) v
+ outroSpace + " ] "
else if isFunction v then
let fna = lib . functionArgs v ;
@ -262,10 +277,10 @@ rec {
else " { " + introSpace
+ libStr . concatStringsSep introSpace ( libAttr . mapAttrsToList
( name : value :
" ${ libStr . escapeNixIdentifier name } = ${ go ( depth + 1 ) ( indent + " " ) value } ; " ) v )
" ${ libStr . escapeNixIdentifier name } = ${ go ( indent + " " ) value } ; " ) v )
+ outroSpace + " } "
else abort " g e n e r a t o r s . t o P r e t t y : s h o u l d n e v e r h a p p e n ( v = ${ v } ) " ;
in go 0 "" ;
in go "" ;
# PLIST handling
toPlist = { }: v : let