treefmt-nix

When working on large code trees, it's common to have multiple code formatters run against it. And have one script that loops over all of them. treefmt makes that nicer.

  • A unified CLI and output
  • Run all the formatters in parallel.
  • Cache which files have changed for super fast re-formatting.
  • Just type treefmt in any folder and it reformats the whole code tree.

This module is defined in numtide/treefmt-nix. The treefmt repo is about the tool itself.

Installation

To use these options, add to your flake inputs:

treefmt-nix.url = "github:numtide/treefmt-nix";

and inside the mkFlake:

imports = [
  inputs.treefmt-nix.flakeModule
];

Run nix flake lock and you're set.

Options

perSystem.treefmt

perSystem.treefmt.package

perSystem.treefmt.build.check

perSystem.treefmt.build.configFile

perSystem.treefmt.build.programs

perSystem.treefmt.build.wrapper

perSystem.treefmt.flakeFormatter

perSystem.treefmt.programs.alejandra.enable

perSystem.treefmt.programs.alejandra.package

perSystem.treefmt.programs.black.enable

perSystem.treefmt.programs.black.package

perSystem.treefmt.programs.cabal-fmt.enable

perSystem.treefmt.programs.cabal-fmt.package

perSystem.treefmt.programs.elm-format.enable

perSystem.treefmt.programs.elm-format.package

perSystem.treefmt.programs.gofmt.enable

perSystem.treefmt.programs.gofmt.package

perSystem.treefmt.programs.gofumpt.enable

perSystem.treefmt.programs.gofumpt.package

perSystem.treefmt.programs.hlint.enable

perSystem.treefmt.programs.hlint.package

perSystem.treefmt.programs.nixpkgs-fmt.enable

perSystem.treefmt.programs.nixpkgs-fmt.package

perSystem.treefmt.programs.ocamlformat.enable

perSystem.treefmt.programs.ocamlformat.package

perSystem.treefmt.programs.ormolu.enable

perSystem.treefmt.programs.ormolu.package

perSystem.treefmt.programs.ormolu.ghcOpts

perSystem.treefmt.programs.prettier.enable

perSystem.treefmt.programs.prettier.package

perSystem.treefmt.programs.purs-tidy.enable

perSystem.treefmt.programs.purs-tidy.package

perSystem.treefmt.programs.rufo.enable

perSystem.treefmt.programs.rufo.package

perSystem.treefmt.programs.rustfmt.enable

perSystem.treefmt.programs.rustfmt.package

perSystem.treefmt.programs.rustfmt.edition

perSystem.treefmt.programs.scalafmt.enable

perSystem.treefmt.programs.scalafmt.package

perSystem.treefmt.programs.shellcheck.enable

perSystem.treefmt.programs.shellcheck.package

perSystem.treefmt.programs.shfmt.enable

perSystem.treefmt.programs.shfmt.package

perSystem.treefmt.programs.stylish-haskell.enable

perSystem.treefmt.programs.stylish-haskell.package

perSystem.treefmt.programs.stylua.enable

perSystem.treefmt.programs.stylua.package

perSystem.treefmt.programs.terraform.enable

perSystem.treefmt.programs.terraform.package

perSystem.treefmt.projectRootFile

perSystem.treefmt.settings.excludes

perSystem.treefmt.settings.formatter

perSystem.treefmt.settings.formatter.<name>.command

perSystem.treefmt.settings.formatter.<name>.excludes

perSystem.treefmt.settings.formatter.<name>.includes

perSystem.treefmt.settings.formatter.<name>.options

perSystem.treefmt

Project-level treefmt configuration

Use config.treefmt.build.wrapper to get access to the resulting treefmt package based on this configuration.

By default treefmt-nix will set the formatter.<system> attribute of the flake, used by the nix fmt command.

Type: submodule

Declared by:

treefmt-nix/flake-module.nix

perSystem.treefmt.package

The treefmt package to use.

Type: package

Default: pkgs.treefmt

Declared by:

treefmt-nix/module-options.nix

perSystem.treefmt.build.check

Create a flake check to test that the given project tree is already formatted.

Input argument is the path to the project tree (usually ‘self’).

Type: function that evaluates to a(n) package

Default: Default check implementation

Declared by:

treefmt-nix/module-options.nix

perSystem.treefmt.build.configFile

Contains the generated config file derived from the settings.

Type: path

Declared by:

treefmt-nix/module-options.nix

perSystem.treefmt.build.programs

Attrset of formatter programs enabled in treefmt configuration.

The key of the attrset is the formatter name, with the value being the package used to do the formatting.

Type: attribute set of package

Default: Programs used in configuration

Declared by:

treefmt-nix/module-options.nix

perSystem.treefmt.build.wrapper

The treefmt package, wrapped with the config file.

Type: package

Default: wrapped treefmt command

Declared by:

treefmt-nix/module-options.nix

perSystem.treefmt.flakeFormatter

Enables treefmt the default formatter used by the nix fmt command

Type: boolean

Default: true

Declared by:

treefmt-nix/flake-module.nix

perSystem.treefmt.programs.alejandra.enable

Whether to enable alejandra.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/alejandra.nix

perSystem.treefmt.programs.alejandra.package

The alejandra package to use.

Type: package

Default: pkgs.alejandra

Declared by:

treefmt-nix/programs/alejandra.nix

perSystem.treefmt.programs.black.enable

Whether to enable black.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/black.nix

perSystem.treefmt.programs.black.package

The black package to use.

Type: package

Default: pkgs.black

Declared by:

treefmt-nix/programs/black.nix

perSystem.treefmt.programs.cabal-fmt.enable

Whether to enable cabal-fmt.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/cabal-fmt.nix

perSystem.treefmt.programs.cabal-fmt.package

cabal-fmt derivation to use.

Type: package

Default: pkgs.haskellPackages.cabal-fmt

Declared by:

treefmt-nix/programs/cabal-fmt.nix

perSystem.treefmt.programs.elm-format.enable

Whether to enable elm-format.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/elm-format.nix

perSystem.treefmt.programs.elm-format.package

elm-format derivation to use.

Type: package

Default: pkgs.elmPackages.elm-format

Declared by:

treefmt-nix/programs/elm-format.nix

perSystem.treefmt.programs.gofmt.enable

Whether to enable gofmt.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/gofmt.nix

perSystem.treefmt.programs.gofmt.package

The go package to use.

Type: package

Default: pkgs.go

Declared by:

treefmt-nix/programs/gofmt.nix

perSystem.treefmt.programs.gofumpt.enable

Whether to enable gofumpt.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/gofumpt.nix

perSystem.treefmt.programs.gofumpt.package

The gofumpt package to use.

Type: package

Default: pkgs.gofumpt

Declared by:

treefmt-nix/programs/gofumpt.nix

perSystem.treefmt.programs.hlint.enable

Whether to enable hlint.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/hlint.nix

perSystem.treefmt.programs.hlint.package

The hlint package to use.

Type: package

Default: pkgs.hlint

Declared by:

treefmt-nix/programs/hlint.nix

perSystem.treefmt.programs.nixpkgs-fmt.enable

Whether to enable nixpkgs-fmt.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/nixpkgs-fmt.nix

perSystem.treefmt.programs.nixpkgs-fmt.package

The nixpkgs-fmt package to use.

Type: package

Default: pkgs.nixpkgs-fmt

Declared by:

treefmt-nix/programs/nixpkgs-fmt.nix

perSystem.treefmt.programs.ocamlformat.enable

Whether to enable ocamlformat.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/ocamlformat.nix

perSystem.treefmt.programs.ocamlformat.package

The ocamlformat package to use.

Type: package

Default: pkgs.ocamlformat

Declared by:

treefmt-nix/programs/ocamlformat.nix

perSystem.treefmt.programs.ormolu.enable

Whether to enable ormolu.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/ormolu.nix

perSystem.treefmt.programs.ormolu.package

The ormolu package to use.

Type: package

Default: pkgs.ormolu

Declared by:

treefmt-nix/programs/ormolu.nix

perSystem.treefmt.programs.ormolu.ghcOpts

Which GHC language extensions to enable

Type: unspecified value

Default:

[
  "BangPatterns"
  "PatternSynonyms"
  "TypeApplications"
]

Declared by:

treefmt-nix/programs/ormolu.nix

perSystem.treefmt.programs.prettier.enable

Whether to enable prettier.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/prettier.nix

perSystem.treefmt.programs.prettier.package

prettier derivation to use.

Type: package

Default: pkgs.nodePackages.prettier

Declared by:

treefmt-nix/programs/prettier.nix

perSystem.treefmt.programs.purs-tidy.enable

Whether to enable purs-tidy.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/purs-tidy.nix

perSystem.treefmt.programs.purs-tidy.package

purs-tidy derivation to use.

Type: package

Default: pkgs.nodePackages.purs-tidy

Declared by:

treefmt-nix/programs/purs-tidy.nix

perSystem.treefmt.programs.rufo.enable

Whether to enable rufo.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/rufo.nix

perSystem.treefmt.programs.rufo.package

The rufo package to use.

Type: package

Default: pkgs.rufo

Declared by:

treefmt-nix/programs/rufo.nix

perSystem.treefmt.programs.rustfmt.enable

Whether to enable rustfmt.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/rustfmt.nix

perSystem.treefmt.programs.rustfmt.package

The rustfmt package to use.

Type: package

Default: pkgs.rustfmt

Declared by:

treefmt-nix/programs/rustfmt.nix

perSystem.treefmt.programs.rustfmt.edition

Rust edition to target when formatting

Type: string

Default: "2021"

Declared by:

treefmt-nix/programs/rustfmt.nix

perSystem.treefmt.programs.scalafmt.enable

Whether to enable scalafmt.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/scalafmt.nix

perSystem.treefmt.programs.scalafmt.package

The scalafmt package to use.

Type: package

Default: pkgs.scalafmt

Declared by:

treefmt-nix/programs/scalafmt.nix

perSystem.treefmt.programs.shellcheck.enable

Whether to enable shellcheck.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/shellcheck.nix

perSystem.treefmt.programs.shellcheck.package

The shellcheck package to use.

Type: package

Default: pkgs.shellcheck

Declared by:

treefmt-nix/programs/shellcheck.nix

perSystem.treefmt.programs.shfmt.enable

Whether to enable shfmt.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/shfmt.nix

perSystem.treefmt.programs.shfmt.package

The shfmt package to use.

Type: package

Default: pkgs.shfmt

Declared by:

treefmt-nix/programs/shfmt.nix

perSystem.treefmt.programs.stylish-haskell.enable

Whether to enable stylish-haskell.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/stylish-haskell.nix

perSystem.treefmt.programs.stylish-haskell.package

The stylish-haskell package to use.

Type: package

Default: pkgs.stylish-haskell

Declared by:

treefmt-nix/programs/stylish-haskell.nix

perSystem.treefmt.programs.stylua.enable

Whether to enable stylua.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/stylua.nix

perSystem.treefmt.programs.stylua.package

The stylua package to use.

Type: package

Default: pkgs.stylua

Declared by:

treefmt-nix/programs/stylua.nix

perSystem.treefmt.programs.terraform.enable

Whether to enable terraform.

Type: boolean

Default: false

Example: true

Declared by:

treefmt-nix/programs/terraform.nix

perSystem.treefmt.programs.terraform.package

The terraform package to use.

Type: package

Default: pkgs.terraform

Declared by:

treefmt-nix/programs/terraform.nix

perSystem.treefmt.projectRootFile

File to look for to determine the root of the project in the build.wrapper.

Type: unspecified value

Example: "flake.nix"

Declared by:

treefmt-nix/module-options.nix

perSystem.treefmt.settings.excludes

A global list of paths to exclude. Supports glob.

Type: list of string

Default: [ ]

Example:

[
  "./node_modules/**"
]

Declared by:

treefmt-nix/module-options.nix

perSystem.treefmt.settings.formatter

Set of formatters to use

Type: attribute set of (submodule)

Default: { }

Declared by:

treefmt-nix/module-options.nix

perSystem.treefmt.settings.formatter.<name>.command

Executable obeying the treefmt formatter spec

Type: Path to executable

Declared by:

treefmt-nix/module-options.nix

perSystem.treefmt.settings.formatter.<name>.excludes

List of files to exclude for formatting. Supports globbing. Takes precedence over the includes.

Type: list of string

Default: [ ]

Declared by:

treefmt-nix/module-options.nix

perSystem.treefmt.settings.formatter.<name>.includes

List of files to include for formatting. Supports globbing.

Type: list of string

Declared by:

treefmt-nix/module-options.nix

perSystem.treefmt.settings.formatter.<name>.options

List of arguments to pass to the command

Type: list of string

Default: [ ]

Declared by:

treefmt-nix/module-options.nix