-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build(nix): Introduce flake.formatter for nix fmt
#5687
Conversation
f6c4aa8
to
2559f5f
Compare
flake.nix
Outdated
@@ -131,6 +135,11 @@ | |||
... | |||
}: | |||
{ | |||
# For standardised reproducible formatting with `nix fmt` | |||
# HELP: why does the per system formatter not work? | |||
# formatter = inputs.nixfmt.packages.${system}.nixfmt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work, and I couldn't quite figure out why. From the error message it appears to try building the aarch_64 darwin build in x86_64-linux.
error: a 'aarch64-darwin' with features {} is required to build '/nix/store/apv47ywrf96wyiy5cd9l9grz0kmg1y1y-cabal2nix-nixfmt.drv', but I am a 'x86_64-linux' with features {benchmark,
big-parallel, kvm, nixos-test, uid-range}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I suspect we have maybe flake-parts
partially evaluate other systems' attributes? I also just noticed that the nixfmt flake uses IFD (which would also explain why your system might try to build something darwin)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. Do you see a solution that does not require changes in nixfmt
's flake? Else maybe we can use nixfmt from nixpkgs, plus point being we get the builds cached for free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(sorry, can't suggest anything rn, but can review your proposals; I'm more available next week)
/cc @SomeoneSerge |
What about alejandra as the nix formatter? It opts for "tall" layouts, which helps git diff. |
I quite like alejandra's style, personally. This repo has been already using nixfmt's rfc101 branch, but if the consensus is with a switch to alejandra we could do that here. |
I think there are many similarities between alejandra and rfc101, and both aim to optimize git diffs. Personally, I dislike them both, and we only had chosen the experimental nixfmt in @philiptaron's rewrite because it has a chance of wider adoption (nixpkgs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the RFC 166 by pulling it from nixpkgs, rather than the flake. See this discourse post from @piegamesde.
The name of the package is nixfmt-rfc-style
.
As this PR notes, the flake.nix in piegamesde/nixfmt/rfc101-style has multiple issues. Let's side-step those by relying on nixpkgs.
668c4e8
to
a0f4cdd
Compare
Thank you, pulling in from nixpkgs is so much better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I intend to merge when CI passes.
* build(nix): Introduce flake.formatter for `nix fmt` * chore: Switch to pkgs.nixfmt-rfc-style
* build(nix): Introduce flake.formatter for `nix fmt` * chore: Switch to pkgs.nixfmt-rfc-style
* build(nix): Introduce flake.formatter for `nix fmt` * chore: Switch to pkgs.nixfmt-rfc-style
What and why
Introduces a
formatter
in the repo's Nix flake. This enables the usage ofnix fmt
to format the Nix files in the repo reproducibly.