【问题标题】:pretty print of nix attrsetsnix attrsets 的漂亮打印
【发布时间】:2018-01-16 16:38:30
【问题描述】:

在 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";
      }
    ];
  };

我的秘诀

我知道的:

【问题讨论】:

    标签: nix nixos


    【解决方案1】:

    我们现在已经编写了自己的格式化程序:

    https://github.com/nixcloud/nix-beautify

    【讨论】:

      【解决方案2】:

      Nixfmt 是一种流行的 Nix 代码格式化程序: https://github.com/Gabriel439/nixfmt

      【讨论】:

        【解决方案3】:

        https://github.com/haskell-nix/hnix/tree/50e63f80afa8323b25b692533e731eea641e56af#parse--print

        使用 hnix 解析文件并漂亮地打印结果:

        hnix file.nix

        【讨论】:

          猜你喜欢
          • 2021-06-22
          • 1970-01-01
          • 2016-07-07
          • 2014-05-19
          • 1970-01-01
          • 2014-08-13
          • 1970-01-01
          • 2011-09-08
          • 2015-03-22
          相关资源
          最近更新 更多