euank / serde-nix

Serialize rust data into nix expressions
Apache License 2.0
0 stars 0 forks source link

Formatting #1

Open euank opened 3 years ago

euank commented 3 years ago

Currently, nix expressions are printed in a mostly somewhat compact representation.

It should be possible to pick between very compact (no excess spacing) and pretty-printed.

euank commented 3 years ago

One approach we could take here is to always generate the most compact representation, and then lean on nixpkgs-fmt to prettify that if desired.

I went back and checked, and that's what I did in yaml2nix.

It does mean re-parsing the generated nix string, which isn't great, but I'm not super worried about performance in this code right now.

That seems like a quite reasonable approach to me.

euank commented 3 years ago

It turns out using nixpkgs-fmt naively isn't enough. I switched yaml2nix to use serde-nix + nixpkgs-fmt, and it ends up with everything on one line still (see https://github.com/euank/yaml2nix/commit/f0b982b25629c23dd8861ea4c5c655d90ccb253c)

It looks like this package either needs to insert newlines, or maybe I'm missing some option in nixpkgs-fmt that will cause it to do what we want