@ -28,6 +28,30 @@ rec {
## -- HELPER FUNCTIONS & DEFAULTS --
/* C o n v e r t a v a l u e t o a s e n s i b l e d e f a u l t s t r i n g r e p r e s e n t a t i o n .
* The builtin ` toString ` function has some strange defaults ,
* suitable for bash scripts but not much else .
* /
mkValueStringDefault = { }: v : with builtins ;
let err = t : v : abort
( " g e n e r a t o r s . m k V a l u e S t r i n g D e f a u l t : " +
" ${ t } n o t s u p p o r t e d : ${ toPretty { } v } " ) ;
in if isInt v then toString v
# we default to not quoting strings
else if isString v then v
# isString returns "1", which is not a good default
else if true == v then " t r u e "
# here it returns to "", which is even less of a good default
else if false == v then " f a l s e "
else if null == v then " n u l l "
# if you have lists you probably want to replace this
else if isList v then err " l i s t s " v
# same as for lists, might want to replace
else if isAttrs v then err " a t t r s e t s " v
else if isFunction v then err " f u n c t i o n s " v
else err " t h i s v a l u e i s " ( toString v ) ;
/* G e n e r a t e a l i n e o f k e y k a n d v a l u e v , s e p a r a t e d b y
* character sep . If sep appears in k , it is escaped .
* Helper for synaxes with different separators .
@ -38,7 +62,7 @@ rec {
* > " f \: o o : b a r "
* /
mkKeyValueDefault = {
mkValueString ? toString
mkValueString ? mkValueStringDefault { }
} : sep : k : v :
" ${ libStr . escape [ sep ] k } ${ sep } ${ mkValueString v } " ;