Skip to content

HariAmoor-professional/treefmt-nix

 
 

Repository files navigation

treefmt nix configuration

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.

Quick Usage

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"];
}

flake-parts

This flake exposes a flake-parts module as well. To use it:

  1. Add inputs.treefmt-nix.flakeModule to the "imports" list of your flake-parts call.
  2. Add treefmt = { .. } (containing the configuration above) to your "perSystem" section.
  3. Add config.treefmt.build.wrapper to the nativeBuildInputs of your devShell. This will make the treefmt 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.

For an example, see haskell-template's flake.nix.

Supported programs

  • alejandra
  • black
  • cabal-fmt
  • elm-format
  • gofmt
  • gofumpt
  • nixpkgs-fmt
  • ormolu
  • prettier
  • rufo
  • rustfmt
  • shellcheck
  • shfmt
  • stylua
  • stylish-haskell
  • terraform

License

MIT

About

treefmt nix configuration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Nix 99.4%
  • Shell 0.6%