Skip to content
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

Integrate treefmt-nix #533

Open
bobvanderlinden opened this issue Apr 17, 2023 · 4 comments · May be fixed by #1317
Open

Integrate treefmt-nix #533

bobvanderlinden opened this issue Apr 17, 2023 · 4 comments · May be fixed by #1317

Comments

@bobvanderlinden
Copy link
Contributor

treefmt is a CLI tool to format all files in a repository. It recurses through a directory and calls the right formatter based on the type of file it finds.

treefmt requires a configuration file that tells it what to execute for each file type. It doesn't include this configuration by default, so it takes some time to get the configuration right and requires knowledge of the different kinds of formatters that you'd like the use. Knowledge like which CLI flags to use.

treefmt-nix is a Nix module system to build a treefmt configuration. It includes options for most of the different formatters and allows just enabling them. The same kind of module system devenv uses.

For instance:

treefmt-nix.mkWrapper nixpkgs {
  # Used to find the project root
  projectRootFile = ".git/config";
  # Enable the terraform formatter
  programs.terraform.enable = true;
  # Override the default package
  programs.terraform.package = nixpkgs.terraform_1;
  # Override the default settings generated by the above option
  settings.formatter.terraform.excludes = [ "hello.tf" ];
}

It would be nice if this could be integrated into devenv, so that you could have options in devenv like:

services.treefmt.enable = true;
services.treefmt.programs.terraform.enable = true;

This probably requires adding treefmt-nix as a Nix flake input to devenv. Is this something we'd want?

@bobvanderlinden
Copy link
Contributor Author

@zimbatm do you think this is a good idea?

@zimbatm
Copy link
Contributor

zimbatm commented Apr 17, 2023

Sounds good! Probably the integration can be done similar to https://github.com/numtide/treefmt-nix/blob/main/flake-module.nix

@I-Want-ToBelieve
Copy link

I-Want-ToBelieve commented Oct 14, 2023

The perfect combination of nix flake + devenv + direnv saves 90% of the development environment configuration time for newcomers who have just entered the project.

After integrating treefmt, it will further increase to 99%.

The last 1% will be implemented in treefmt to "watch file changes and automate formats" obtained after the features.

@use-the-fork
Copy link
Contributor

I took care of this integration in my last PR. Let me know if anything needs to be changed.

@use-the-fork use-the-fork linked a pull request Jul 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants