Skip to content

Conversation

@DockterTeagle
Copy link
Contributor

As mentioned in my issue, while the check for treefmt.toml makes sense, it fails when the toml file is not there, leading to undesired behavior(as is the case in nix, using either treefmt-nix or nixpkgs.treefmt.withConfig). Marking as draft so that me and @zivarah can discuss over what we should do

@github-actions github-actions bot requested a review from stevearc October 23, 2025 12:38
@DockterTeagle DockterTeagle changed the title fix(for me): revert the previous PR fix: treefmt Oct 23, 2025
@zivarah
Copy link
Contributor

zivarah commented Oct 23, 2025

I don't see a link to your issue anywhere so adding one for convenience: #793

I've replied there with some thoughts on the issue itself -- if we decide an upstream change is appropriate then we can discuss further on this PR?

@stevearc
Copy link
Owner

My understanding is that treefmt-nix is a separate package that installs a treefmt command that does normal treefmt things but integrated with nix. For treefmt-nix, it doesn't require a toml config file because it gets its config from nix. Is that about the shape of the problem?

If that's correct, then I'd either recommend overriding the treefmt formatter in your user config with require_cwd = false, or I could potentially see the case for making another formatter configuration for treefmt_nix.

@zivarah
Copy link
Contributor

zivarah commented Oct 24, 2025

My understanding is that treefmt-nix is a separate package that installs a treefmt command that does normal treefmt things but integrated with nix. For treefmt-nix, it doesn't require a toml config file because it gets its config from nix. Is that about the shape of the problem?

Yes -- specifically, treefmt-nix makes an executable called treefmt that is actually just a shell script that calls out into the real treefmt with a generated config file specified as an argument.

If that's correct, then I'd either recommend overriding the treefmt formatter in your user config with require_cwd = false, or I could potentially see the case for making another formatter configuration for treefmt_nix.

Note that any such treefmt_nix formatter would need to use flake.nix as the root marker but also would need something else to understand if treefmt-nix is actually in use. In practice that may involve some flake evaluation depending on the implementation.

I could see a case for some more generic handling in the base treefmt formatter definition based on whether a treefmt executable exists and can be invoked without erroring. My response to #793 does give an example of how I've worked around this in my own config, though as noted there I don't know that it's upstream-ready. I'm curious for your thoughts on that.

@stevearc
Copy link
Owner

That workaround seems a bit inelegant and I generally don't want to proliferate that kind of logic within conform. If there's really no easy way to tell if treefmt-nix should be used in a directory or not I might suggest that this would best be solved with :help 'exrc'. You can set some directory-specific logic to wire up the formatter the way you need.

@zivarah
Copy link
Contributor

zivarah commented Oct 27, 2025

Yeah, I think that makes sense. I'd be in favor of closing the PR and closing #793 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants