pre-commit-hooks-nix
Configure pre-commit hooks.
Generates a configuration for pre-commit, provides a script to activate it, and adds a check.
Pre-defined hooks are maintained at cachix/pre-commit-hooks.nix
.
Installation
To use these options, add to your flake inputs:
pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix";
and inside the mkFlake
:
imports = [
inputs.pre-commit-hooks-nix.flakeModule
];
Run nix flake lock
and you're set.
Options
perSystem.pre-commit.check.enable
perSystem.pre-commit.installationScript
perSystem.pre-commit.settings.package
perSystem.pre-commit.settings.default_stages
perSystem.pre-commit.settings.excludes
perSystem.pre-commit.settings.hooks
perSystem.pre-commit.settings.hooks.<name>.enable
perSystem.pre-commit.settings.hooks.<name>.description
perSystem.pre-commit.settings.hooks.<name>.entry
perSystem.pre-commit.settings.hooks.<name>.excludes
perSystem.pre-commit.settings.hooks.<name>.files
perSystem.pre-commit.settings.hooks.<name>.language
perSystem.pre-commit.settings.hooks.<name>.name
perSystem.pre-commit.settings.hooks.<name>.pass_filenames
perSystem.pre-commit.settings.hooks.<name>.raw
perSystem.pre-commit.settings.hooks.<name>.stages
perSystem.pre-commit.settings.hooks.<name>.types
perSystem.pre-commit.settings.hooks.<name>.types_or
perSystem.pre-commit.settings.installationScript
perSystem.pre-commit.settings.rootSrc
perSystem.pre-commit.settings.run
perSystem.pre-commit.settings.settings.alejandra.exclude
perSystem.pre-commit.settings.settings.autoflake.binPath
perSystem.pre-commit.settings.settings.autoflake.flags
perSystem.pre-commit.settings.settings.clippy.denyWarnings
perSystem.pre-commit.settings.settings.deadnix.edit
perSystem.pre-commit.settings.settings.deadnix.noLambdaArg
perSystem.pre-commit.settings.settings.deadnix.noLambdaPatternNames
perSystem.pre-commit.settings.settings.deadnix.noUnderscore
perSystem.pre-commit.settings.settings.deadnix.quiet
perSystem.pre-commit.settings.settings.eslint.binPath
perSystem.pre-commit.settings.settings.eslint.extensions
perSystem.pre-commit.settings.settings.flake8.binPath
perSystem.pre-commit.settings.settings.flake8.format
perSystem.pre-commit.settings.settings.hpack.silent
perSystem.pre-commit.settings.settings.markdownlint.config
perSystem.pre-commit.settings.settings.nixfmt.width
perSystem.pre-commit.settings.settings.ormolu.cabalDefaultExtensions
perSystem.pre-commit.settings.settings.ormolu.defaultExtensions
perSystem.pre-commit.settings.settings.php-cs-fixer.binPath
perSystem.pre-commit.settings.settings.phpcbf.binPath
perSystem.pre-commit.settings.settings.phpcs.binPath
perSystem.pre-commit.settings.settings.prettier.binPath
perSystem.pre-commit.settings.settings.prettier.output
perSystem.pre-commit.settings.settings.prettier.write
perSystem.pre-commit.settings.settings.pylint.binPath
perSystem.pre-commit.settings.settings.pylint.reports
perSystem.pre-commit.settings.settings.pylint.score
perSystem.pre-commit.settings.settings.revive.configPath
perSystem.pre-commit.settings.settings.rust.cargoManifestPath
perSystem.pre-commit.settings.settings.statix.format
perSystem.pre-commit.settings.settings.statix.ignore
perSystem.pre-commit.settings.settings.typos.diff
perSystem.pre-commit.settings.settings.typos.format
perSystem.pre-commit.settings.settings.typos.write
perSystem.pre-commit.settings.settings.yamllint.configPath
perSystem.pre-commit.settings.settings.yamllint.relaxed
perSystem.pre-commit.settings.src
perSystem.pre-commit.settings.tools
perSystem.pre-commit.check.enable
Whether to add a derivation to the flake checks
. It will
perform the pre-commit checks in nix flake check
.
You can disable this if one of your hooks do not run properly in the Nix sandbox; for example because it needs network access.
Type: boolean
Default: true
Declared by:
pre-commit-hooks-nix/flake-module.nix
perSystem.pre-commit.installationScript
A bash fragment that sets up pre-commit.
Type: string (read only)
Default: bash statements
Declared by:
pre-commit-hooks-nix/flake-module.nix
perSystem.pre-commit.pkgs
Nixpkgs to use in the pre-commit settings
.
Type: lazy attribute set of raw value
Default: pkgs
(module argument)
Declared by:
pre-commit-hooks-nix/flake-module.nix
perSystem.pre-commit.settings
The pre-commit-hooks.nix configuration.
Type: submodule
Default: { }
Declared by:
pre-commit-hooks-nix/flake-module.nix
perSystem.pre-commit.settings.package
The pre-commit
package to use.
Type: package
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.default_stages
A configuration wide option for the stages property. Installs hooks to the defined stages. See https://pre-commit.com/#confining-hooks-to-run-at-certain-stages.
Type: list of string
Default:
[
"commit"
]
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.excludes
Exclude files that were matched by these patterns.
Type: list of string
Default: [ ]
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks
The hook definitions.
Pre-defined hooks can be enabled by, for example:
-fmt.enable = true; hooks.nixpkgs
The pre-defined hooks are:
actionlint
Static checker for GitHub Actions workflow files.
alejandra
The Uncompromising Nix Code Formatter.
ansible-lint
Ansible linter.
autoflake
Remove unused imports and variables from Python code.
bats
Run bash unit tests.
black
The uncompromising Python code formatter.
cabal-fmt
Format Cabal files
cabal2nix
Run cabal2nix
on all *.cabal
files to
generate corresponding default.nix
files.
cargo-check
Check the cargo package for errors.
chktex
LaTeX semantic checker
clang-format
Format your code using clang-format
.
clippy
Lint Rust code.
commitizen
Check whether the current commit message follows commiting rules.
deadnix
Scan Nix files for dead code (unused variable bindings).
dhall-format
Dhall code formatter.
editorconfig-checker
Verify that the files are in harmony with the
.editorconfig
.
elm-format
Format Elm files.
elm-review
Analyzes Elm projects, to help find mistakes before your users find them.
elm-test
Run unit tests and fuzz tests for Elm code.
eslint
Find and fix problems in your JavaScript code.
flake8
Check the style and quality of Python files.
fourmolu
Haskell code prettifier.
gofmt
A tool that automatically formats Go source code
gotest
Run go tests
govet
Checks correctness of Go programs.
hadolint
Dockerfile linter, validate inline bash.
hindent
Haskell code prettifier.
hlint
HLint gives suggestions on how to improve your source code.
hpack
hpack
converts package definitions in the hpack format
(package.yaml
) to Cabal files.
html-tidy
HTML linter.
hunspell
Spell checker and morphological analyzer.
isort
A Python utility / library to sort imports.
latexindent
Perl script to add indentation to LaTeX files.
luacheck
A tool for linting and static analysis of Lua code.
markdownlint
Style checker and linter for markdown files.
mdsh
Markdown shell pre-processor.
nixfmt
Nix code prettifier.
nixpkgs-fmt
Nix code prettifier.
ormolu
Haskell code prettifier.
php-cs-fixer
Lint PHP files.
phpcbf
Lint PHP files.
phpcs
Lint PHP files.
prettier
Opinionated multi-language code formatter.
purs-tidy
Format purescript files.
purty
Format purescript files.
pylint
Lint Python files.
revive
A linter for Go source code.
ruff
An extremely fast Python linter, written in Rust.
rustfmt
Format Rust code.
shellcheck
Format shell files.
shfmt
Format shell files.
staticcheck
State of the art linter for the Go programming language
statix
Lints and suggestions for the Nix programming language.
stylish-haskell
A simple Haskell code prettifier
stylua
An Opinionated Lua Code Formatter.
terraform-format
Format terraform (.tf
) files.
typos
Source code spell checker
yamllint
Yaml linter.
Type: attribute set of (submodule)
Default: { }
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.enable
Whether to enable this pre-commit hook.
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.description
Description of the hook. used for metadata purposes only.
Type: string
Default: ""
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.entry
The entry point - the executable to run. entry
can also
contain arguments that will not be overridden, such as
entry = "autopep8 -i";
.
Type: string
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.excludes
Exclude files that were matched by these patterns.
Type: list of string
Default: [ ]
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.files
The pattern of files to run on.
Type: string
Default: ""
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.language
The language of the hook - tells pre-commit how to install the hook.
Type: string
Default: "system"
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.name
The name of the hook - shown during hook execution.
Type: string
Default: internal name, same as id
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.pass_filenames
Whether to pass filenames as arguments to the entry point.
Type: boolean
Default: true
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.raw
Raw fields of a pre-commit hook. This is mostly for internal use but exposed in case you need to work around something.
Default: taken from the other hook options.
Type: attribute set of unspecified value
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.stages
Confines the hook to run at a particular stage.
Type: list of string
Default: default_stages
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.types
List of file types to run on. See Filtering files with types.
Type: list of string
Default:
[
"file"
]
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.hooks.<name>.types_or
List of file types to run on, where only a single type needs to match.
Type: list of string
Default: [ ]
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.installationScript
A bash snippet that installs nix-pre-commit-hooks in the current directory
Type: string (read only)
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.rootSrc
The source of the project to be checked.
This is used in the derivation that performs the check.
If you use the flakeModule
, the default is
self.outPath
; the whole flake sources.
Type: path
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.run
A derivation that tests whether the pre-commit hooks run cleanly on the entire project.
Type: package (read only)
Default: "<derivation>"
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.settings.alejandra.exclude
Files or directories to exclude from formatting.
Type: list of string
Default: [ ]
Example:
[
"flake.nix"
"./templates"
]
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.autoflake.binPath
Path to autoflake binary.
Type: string
Default:
"${pkgs.autoflake}/bin/autoflake"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.autoflake.flags
Flags passed to autoflake.
Type: string
Default:
"--in-place --expand-star-imports --remove-duplicate-keys --remove-unused-variables"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.clippy.denyWarnings
Fail when warnings are present
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.deadnix.edit
Remove unused code and write to source file.
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.deadnix.noLambdaArg
Don’t check lambda parameter arguments.
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.deadnix.noLambdaPatternNames
Don’t check lambda pattern names (don’t break nixpkgs
callPackage
).
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.deadnix.noUnderscore
Don’t check any bindings that start with a _
.
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.deadnix.quiet
Don’t print a dead code report.
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.eslint.binPath
eslint
binary path. E.g. if you want to use the
eslint
in node_modules
, use
./node_modules/.bin/eslint
.
Type: path
Default: ${tools.eslint}/bin/eslint
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.eslint.extensions
The pattern of files to run on, see https://pre-commit.com/#hooks-files.
Type: string
Default: "\\.js$"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.flake8.binPath
flake8 binary path. Should be used to specify flake8 binary from your Nix-managed Python environment.
Type: string
Default:
"${pkgs.python39Packages.flake8}/bin/flake8"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.flake8.format
Output format.
Type: string
Default: "default"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.hpack.silent
Whether generation should be silent.
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.markdownlint.config
See https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.jsonc
Type: attribute set
Default: { }
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.nixfmt.width
Line width.
Type: null or signed integer
Default: null
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.ormolu.cabalDefaultExtensions
Use default-extensions
from .cabal
files.
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.ormolu.defaultExtensions
Haskell language extensions to enable.
Type: list of string
Default: [ ]
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.php-cs-fixer.binPath
PHP-CS-Fixer binary path.
Type: string
Default:
"${pkgs.php81Packages.php-cs-fixer}/bin/php-cs-fixer"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.phpcbf.binPath
PHP_CodeSniffer binary path.
Type: string
Default:
"${pkgs.php80Packages.phpcbf}/bin/phpcbf"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.phpcs.binPath
PHP_CodeSniffer binary path.
Type: string
Default:
"${pkgs.php80Packages.phpcs}/bin/phpcs"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.prettier.binPath
prettier
binary path. E.g. if you want to use the
prettier
in node_modules
, use
./node_modules/.bin/prettier
.
Type: path
Default:
"${tools.prettier}/bin/prettier"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.prettier.output
Output format.
Type: null or one of “check”, “list-different”
Default: "list-different"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.prettier.write
Whether to edit files inplace.
Type: boolean
Default: true
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.pylint.binPath
Pylint binary path. Should be used to specify Pylint binary from your Nix-managed Python environment.
Type: string
Default:
"${pkgs.python39Packages.pylint}/bin/pylint"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.pylint.reports
Whether to display a full report.
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.pylint.score
Whether to activate the evaluation score.
Type: boolean
Default: true
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.revive.configPath
Path to the configuration TOML file.
Type: string
Default: ""
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.rust.cargoManifestPath
Path to Cargo.toml
Type: null or string
Default: null
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.statix.format
Error Output format.
Type: one of “stderr”, “errfmt”, “json”
Default: "errfmt"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.statix.ignore
Globs of file patterns to skip.
Type: list of string
Default: [ ]
Example:
[
"flake.nix"
"_*"
]
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.typos.diff
Wheter to print a diff of what would change.
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.typos.format
Output format.
Type: one of “silent”, “brief”, “long”, “json”
Default: "long"
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.typos.write
Whether to write fixes out.
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.yamllint.configPath
path to the configuration YAML file
Type: string
Default: ""
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.settings.yamllint.relaxed
Use the relaxed configuration
Type: boolean
Default: false
Declared by:
pre-commit-hooks-nix/modules/hooks.nix
perSystem.pre-commit.settings.src
Root of the project. By default this will be filtered with the
gitignoreSource
function later, unless rootSrc
is specified.
If you use the flakeModule
, the default is
self.outPath
; the whole flake sources.
Type: path
Declared by:
pre-commit-hooks-nix/modules/pre-commit.nix
perSystem.pre-commit.settings.tools
Tool set from which nix-pre-commit-hooks
will pick
binaries.
nix-pre-commit-hooks
comes with its own set of packages
for this purpose.
Type: lazy attribute set of package
Declared by: