This repo is for users that use both Nix and treefmt.
It contains a mapping from programs to treefmt.toml
formatter entries,
maintained by the community.
This returns a treefmt
instance with terraform configured to format *.tf
files:
{ nixpkgs, treefmt-nix, ... }:
treefmt-nix.lib.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_0;
# Override the default settings generated by the above option
settings.formatter.terraform.excludes = ["hello.tf"];
}
This flake exposes a flake-parts module as well. To use it:
- Add
inputs.treefmt-nix.flakeModule
to the "imports" list of yourflake-parts
call. - Add
treefmt = { .. }
(containing the configuration above) to your "perSystem" section. - Add
config.treefmt.build.wrapper
to thenativeBuildInputs
of your devShell. This will make thetreefmt
command available in the shell using the specified configuration.- You can also use
config.treefmt.build.programs
to get access to the individual programs, which could be useful to provide them to your IDE or editor.
- You can also use
For an example, see haskell-template's flake.nix
.
- alejandra
- black
- cabal-fmt
- elm-format
- gofmt
- gofumpt
- nixpkgs-fmt
- ormolu
- prettier
- rufo
- rustfmt
- shellcheck
- shfmt
- stylua
- stylish-haskell
- terraform
MIT