-
-
Couldn't load subscription status.
- Fork 1.8k
fix(nix fmt): remove the default "." argument #11438
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
Conversation
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.
I think this is a good idea.
|
Could you add a brief release note, documentation and a test case? |
f4e5697 to
7827779
Compare
|
thanks, updated the tests and added a release note |
7827779 to
12473be
Compare
When `nix fmt` is called without an argument, Nix appends the "." argument before calling the formatter. The comment in the code is: > Format the current flake out of the box This also happens when formatting sub-folders. This means that the formatter is now unable to distinguish, as an interface, whether the "." argument is coming from the flake or the user's intent to format the current folder. This decision should be up to the formatter. Treefmt, for example, will automatically look up the project's root and format all the files. This is the desired behaviour. But because the "." argument is passed, it cannot function as expected.
12473be to
c4766d7
Compare
|
Was also discussed in Formatter team meeting. |
|
Thanks, I didn't expect this to be merged so quickly! For visitors: nixfmt, nixpkgs-fmt and alejandra are currently formatting stdin when no arguments are passed, so this change will cause some back-compat issues. I would recommend those projects change their default to format the current folder instead (and format stdin on For visitors hitting this, here is a small wrapper example that will restore the previous behaviour: {
outputs = { self, nixpkgs, systems }:
let
eachSystem = nixpkgs.lib.genAttrs (import systems) (system: nixpkgs.legacyPackages.${system});
in
{
formatter = eachSystem (pkgs:
pkgs.writeShellScriptBin "formatter" ''
if [[ $# = 0 ]]; then set -- .; fi
exec "${pkgs.nixfmt-rfc-style}/bin/nixfmt" "$@"
'');
};
} |
The common case is to format folders, not stdin. This changes the default to format the current directory, and introduces a `--stdin` flag for users that want to wrap `nixfmt` into editors and other tools. See also NixOS/nix#11438
When `nix fmt` is called without an argument, Nix appends the "." argument before calling the formatter. The comment in the code is: > Format the current flake out of the box This also happens when formatting sub-folders. This means that the formatter is now unable to distinguish, as an interface, whether the "." argument is coming from the flake or the user's intent to format the current folder. This decision should be up to the formatter. Treefmt, for example, will automatically look up the project's root and format all the files. This is the desired behaviour. But because the "." argument is passed, it cannot function as expected. Upstream-PR: NixOS/nix#11438 Change-Id: I60fb6b3ed4ec1b24f81b5f0d76c0be98470817ce
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
The new version of Nix no longer provides path to the source to the formatter and thus alejandra uses stdin instead and thus run fails. NixOS/nix#11438
The new version of Nix no longer provides path to the source to the formatter and thus alejandra uses stdin instead and thus run fails. NixOS/nix#11438
This is now possible thanks to <NixOS/nix#11438> In older versions of Nix, "." is still passed as a default argument.
Nix 2.25 changes the args passed to the formatter, so we now need to handle an empty args. See NixOS/nix#11438
The new version of Nix no longer provides path to the source to the formatter and thus alehandra uses stdin instead and thus run fails. The Nix functionality change: NixOS/nix#11438
The new version of Nix no longer provides path to the source to the formatter and thus alehandra uses stdin instead and thus run fails. The Nix functionality change: NixOS/nix#11438
The new version of Nix no longer provides path to the source to the formatter and thus alehandra uses stdin instead and thus run fails. The Nix functionality change: NixOS/nix#11438
as of nix 2.25.0, `nix fmt` will not automatically recurse through nix files so nixfmt-rfc-style` will format from stdin instead. see: NixOS/nix#11438 this issue NixOS/nixfmt#273 recommends that we use `nixfmt-tree` which calls `treefmt` in the backend with a minimal configuration for nix
as of nix 2.25.0, `nix fmt` will not automatically recurse through nix files so `nixfmt-rfc-style` will format from stdin instead. see: NixOS/nix#11438 this issue NixOS/nixfmt#273 recommends that we use `nixfmt-tree` which calls `treefmt` in the backend with a minimal configuration for nix
as of nix 2.25.0, `nix fmt` will not automatically recurse through nix files so `nixfmt-rfc-style` will format from stdin instead. see: NixOS/nix#11438 this issue NixOS/nixfmt#273 recommends that we use `nixfmt-tree` which calls `treefmt` in the backend with a minimal configuration for nix
The new version of Nix no longer provides path to the source to the formatter and thus alehandra uses stdin instead and thus run fails. The Nix functionality change: NixOS/nix#11438
|
@zimbatm there's a missing if [[ $# = 0 ]]; then set -- .; fi
exec "${pkgs.nixfmt-rfc-style}/bin/nixfmt" "$@"But anyway So this is working great for me: formatter."${system}" = nixpkgs.legacyPackages.x86_64-linux.nixfmt-tree; |
The new version of Nix no longer provides path to the source to the formatter and thus alehandra uses stdin instead and thus run fails. The Nix functionality change: NixOS/nix#11438
Motivation
Allow treefmt to function as expected.
Context
When
nix fmtis called without an argument, Nix appends the "." argument before calling the formatter. The comment in the code is:This also happens when formatting sub-folders.
This means that the formatter is now unable to distinguish, as an interface, whether the "." argument is coming from the flake or the user's intent to format the current folder. This decision should be up to the formatter.
Treefmt, for example, will automatically look up the project's root and format all the files. This is the desired behaviour. But because the "." argument is passed, it cannot function as expected.
Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.