Can you give some more details, like how to actually run this? I figured it out by copy pasting the flake command above, and the PR has some references, but probably more people will test it if they have an easy way to do it.
Anyway, I had a quick glance and it mostly looks pretty good, except function pattern match arguments get unwrapped in a way that looks pretty bad. This:
let
function1 =
{ arg1
, arg2
# comment on arg3
, arg3
, arg4
}: arg1 + arg2;
function2 =
{ deps
, srcs ? [ ]
# comment
, outputs ? [ "out "]
# comment
, moreArgs
# comment
, blah
}: 1;
in 1
becomes
let
function1 = { arg1, arg2
# comment on arg3
, arg3, arg4 }:
arg1 + arg2;
function2 = { deps, srcs ? [ ]
# comment
, outputs ? [
"out "
]
# comment
, moreArgs
# comment
, blah }:
1;
in 1
The RFC seems to favor a trailing commas style, but this doesn’t fare very well either:
let
function1 = {
arg1,
arg2,
# comment on arg3
arg3,
arg4,
}: arg1 + arg2;
function2 = {
deps,
srcs ? [ ],
# comment
outputs ? [ "out "],
# comment
moreArgs,
# comment
blah,
}: 1;
in 1
becomes
let
function1 = { arg1, arg2,
# comment on arg3
arg3, arg4, }:
arg1 + arg2;
function2 = { deps, srcs ? [ ],
# comment
outputs ? [ "out " ],
# comment
moreArgs,
# comment
blah, }:
1;
in 1
Presumably it should notice that the whole {...}: syntax doesn’t fit on one line, and then wrap each element consistently, rather than trying to fit as many as possible on each line.
The other major issue is that lists get unwrapped when they shouldn’t be. Unfortunately it’s impossible for a formatter to know which lists are small and will remain small, and which ones will be frequently added to and removed from, so should be one-per-line, that’s domain knowledge. As a workaround, I’ve taken to putting in a comment to disable the unwrap, e.g.:
deps = [
# don't unwrap me nixfmt
"a"
"b"
];
So this isn’t anything nixfmt could fix, just a note of a workaround.