[Nix-dev] A nix pretty-printer and a trace function you can tell how deep it should go

Profpatsch mail at profpatsch.de
Mon Jun 12 17:33:40 CEST 2017


https://github.com/NixOS/nixpkgs/pull/26433

Pretty Printing:

nix-repl> lib.generators.toPretty {} { foo = [ 2 3 netcat-openbsd ]; bar = lib.id; x = {args, def ? 42}: args; }
"{ \"bar\" = <λ>; \"foo\" = [ 2 3 <δ> ]; \"x\" = <λ:{args,(def)}>; }"

nix-repl> lib.generators.toPretty {} (import <nixpkgs>)
"<λ:{(config),(crossSystem),(localSystem),(overlays),(platform),(system)}>"


Trace Folding:

nix-repl> foo = { a = [ 1 [ 2 3 ] ]; b = { c.d.e = "yip yip"; }; }

nix-repl> lib.traceValSeqN 10 foo
trace: { "a" = [ 1 [ 2 3 ] ]; "b" = { "c" = { "d" = { "e" = "yip yip"; }; }; }; }
{ a = [ ... ]; b = { ... }; }

nix-repl> lib.traceValSeqN 3 foo
trace: { "a" = [ 1 [ 2 3 ] ]; "b" = { "c" = { "d" = {…}; }; }; }
{ a = [ ... ]; b = { ... }; }

nix-repl> lib.traceValSeqN 1 foo
trace: { "a" = […]; "b" = {…}; }
{ a = [ ... ]; b = { ... }; }

nix-repl> lib.traceValSeqN 0 foo
trace: {…}
{ a = [ ... ]; b = { ... }; }


https://twitter.com/Profpatsch/status/874127956884566016

I hope this helps some people.
Please review the code.


-- 
Proudly written in Mutt with Vim on NixOS.
Q: Why is this email five sentences or less?
A: http://five.sentenc.es
May take up to five days to read your message. If it’s urgent, call me.


More information about the nix-dev mailing list