在nix中开发时,我通常使用 builtins.trace
进行调试:
代码
a = { foo = "bar"; ... more complex nested attrset ...};
builtins.trace a a;
在nix-repl中
在复杂的数据结构上使用 :p a
也很难阅读 .
问题
但是,输出只是一行而没有任何格式化,对于复杂的数据结构,这几乎不可用于调试 .
这个问题
在nix中是否有一个漂亮的打印功能,它会做一些缩进并添加换行符?甚至更好的彩色输出?
理想输出
我想看到这样的事情:
default = {
active = {
check_ssl = [
{
tags = [ "mycustomtag" ];
host = "kotalla.de";
ipv6 = false;
name = "ssl11";
}
{
tags = [ "mycustomtag" ];
host = "kotalla.de";
ipv6 = false;
name = "ssl2";
}
];
check_http = [
{
host = "kotalla.de";
port = 80;
url = "/foo";
contains = "Labor";
name = "http";
}
];
check_ssh = [
{
host = "mail.lastlog.de";
port = 20202;
name = "ssh";
}
];
};
2 回答
我们现在编写了自己的格式化程序:
https://github.com/nixcloud/nix-beautify
Nixfmt是一个流行的Nix代码格式化程序:https://github.com/Gabriel439/nixfmt