-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Improving flake formatting experience #273
Comments
That one is kinda awkward, since it was already decided that recursively finding nix files to be formatted is a non-trivial issue that is kinda out-of-scope for a tool that just wants to be able to format a nix file. IIRC, the main complexities come from ignoring Maybe this could be worked around by renaming The wrapper package could of course use an existing lib/tool to implement that. And treefmt users should probably be able to use either the wrapped or unwrapped package. |
It seems quite trivial, actually; this decision comes off more like it's just intentionally making it harder to use flakes. Using a random third-party tool just to be able to use the official formatter with official nix is a nonstarter IMO. And there's some irony here that the nix docs still give the example of setting In any case, as amusing as whining about nix* community dysfunction is, since I'd rather just get things done,
I specifically chose To be able to effectively use formatter.x86_64-linux =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in
pkgs.writeShellApplication {
name = "nixfmt-wrapper";
runtimeInputs = [
pkgs.fd
pkgs.nixfmt-rfc-style
];
text = ''
fd "$@" -t f -e nix -x nixfmt '{}'
'';
}; The args that are passed (to the formatter package's executable) appear to be the path(s) that are (im/ex)plicitly passed to |
Yes, the observation behind this issue was that is should be dead simple to format a flake the "official way". |
Sure, I'm not entirely disagreeing that having nixfmt behave differently from the other formatters is surprising; I just wanted to share (with anyone watching this issue) a straightforward workaround that works today and will continue to work even if directory support is removed from nixfmt entirely. |
In order to have your flake formatted with
nixfmt-rfc-style
, one has two options:formatter = pkgs.nixfmt-rfc-style;
. This solution is concise (ignoring the fact that the name "nixfmt-rfc-style" is not really intuitive compared to simply "nixfmt").However, this is not expected to be supported for long as:
Passing directories or non-Nix files (such as ".") is deprecated and will be unsupported soon, please use https://treefmt.com/ instead, e.g. via https://github.com/numtide/treefmt-nix
.I think it should be great to support the existing
formatter = pkgs.nixfmt[-rfc-style];
syntax as it gives a very efficient and user-friendly way to format a flake while keeping it lean code and input wise.In the long term, I could see the benefit of further "officializing" the
nixfmt
formatter and having aformat = true;
flag to automatically format the flake. This would have to be thought more.cc @infinisil
The text was updated successfully, but these errors were encountered: