How to format 'nix eval' output with «» - double angle quotation marks

Hello, I am having difficulties in the way of debugging nix config.

For nix eval, --json isn’t applicable for outputs that contain functions (error: cannot convert a function to JSON). So manually piping to nixfmt is an option, but nixfmt can’t handle «» ( guillemets/double angle quotation marks). I tried using a simple to string conversion sed --null-data -E 's/«([^»]*?)»/"«\1»"/g' | nixfmt, but then nested guillemets (««»») stop it.

For example:

nix eval github:nix-community/emacs-overlay#overlay 
# => «lambda default @ «github:nix-community/emacs-overlay/74cb2e9f130bba564295453b8a19eef53af202c5»/flake.nix:53:19»

None of that is a nix expression so nixfmt can’t format it (nor should you need to format that).

Instead, it’s a file position within a flake, following it gets you here:

It’s just one example among the possibilities. My actual thing:

{

  # each attr is in a different file, using import-tree

  options.flake.my-options = {
    # bunch of sub options with some types
  };

  options.flake.my-options.pkgs-overlay-attach-list = (lib.mkOption { default = [ ]; });

  config.flake.my-options.pkgs-overlay-attach-list = [
    (import inputs.emacs-overlay)
  ];

}

nix eval .#my-options => prints an attr set, some are functions so I’m looking for a formatter that works regardless

Or… this is an XY problem and I was using them wrong?

Isn’t nix eval pretty printing the output already?

I didn’t know that, but curiously nix eval never prettified for me by default.

flake.nix example:

{
  inputs.emacs-overlay.url = "github:nix-community/emacs-overlay";
  outputs = (
    inputs: {
      foo = {
        a = (import inputs.emacs-overlay);
        b = 1;
        c = false;
        d = "str";
        e = [0 1 2];
      };
    }
  );
}
nix eval .#foo

Observed:
{ a = «lambda @ «github:nix-community/emacs-overlay/74cb2e9f130bba564295453b8a19eef53af202c5?narHash=sha256-TeI6bJI/AOaIG2Q0u9emJRt5EkWD0vwp9pVC2/yJMTs%3D»/default.nix:1:1»; b = 1; c = false; d = "str"; e = [ 0 1 2 ]; }
Expected:

{
  a = "«lambda @ «github:nix-community/emacs-overlay/74cb2e9f130bba564295453b8a19eef53af202c5?narHash=sha256-TeI6bJI/AOaIG2Q0u9emJRt5EkWD0vwp9pVC2/yJMTs%3D»/default.nix:1:1»";
  b = 1;
  c = false;
  d = "str";
  e = [
    0
    1
    2
  ];
}

Sorry, I misremembered, nix eval does indeed not pretty print, only the REPL does…

$ nix repl .
Nix 2.36.0pre20260916_7f8603a
Type :? for help.
Loading installable 'path:/home/nmelzer/tmp/asdasdadasdasd#'...
Added 1 variables.
foo
nix-repl> foo
{
  a = «lambda @ /nix/store/hcsncvmm9v7kjmwmpzq98flksf2ymzbx-source/default.nix:1:1»;
  b = 1;
  c = false;
  d = "str";
  e = [ ... ];
}

nix-repl> :p foo
{
  a = «lambda @ /nix/store/hcsncvmm9v7kjmwmpzq98flksf2ymzbx-source/default.nix:1:1»;
  b = 1;
  c = false;
  d = "str";
  e = [
    0
    1
    2
  ];
}