cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.74k stars 277 forks source link

Integrate treefmt-nix #533

Open bobvanderlinden opened 1 year ago

bobvanderlinden commented 1 year ago

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 commented 1 year ago

@zimbatm do you think this is a good idea?

zimbatm commented 1 year ago

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

I-Want-ToBelieve commented 9 months ago

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 commented 2 weeks ago

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