Documentation Index
Fetch the complete documentation index at: https://mintlify.com/cachix/devenv/llms.txt
Use this file to discover all available pages before exploring further.
devenv has first-class integration for pre-commit via git-hooks.nix. This lets you automatically run linters and formatters at commit time, keeping your codebase consistently formatted and free of common errors — without any manual setup beyond a few lines in devenv.nix.
The git-hooks integration requires the git-hooks input in your devenv.yaml. Add it using the CLI:
$ devenv inputs add git-hooks github:cachix/git-hooks.nix
Or insert it manually into devenv.yaml:
inputs:
git-hooks:
url: github:cachix/git-hooks.nix
Enabling Hooks
Once the input is added, enable hooks in devenv.nix under git-hooks.hooks:
{ inputs, ... }:
{
git-hooks.hooks = {
# lint shell scripts
shellcheck.enable = true;
# execute example shell from Markdown files
mdsh.enable = true;
# format Python code
black.enable = true;
# override a package with a different version
ormolu.enable = true;
ormolu.package = pkgs.haskellPackages.ormolu;
# some hooks have more than one package, like clippy:
clippy.enable = true;
clippy.packageOverrides.cargo = pkgs.cargo;
clippy.packageOverrides.clippy = pkgs.clippy;
# some hooks provide settings
clippy.settings.allFeatures = true;
};
}
When you enter the shell, devenv installs the pre-commit hook automatically:
$ devenv shell
Building shell ...
Entering shell ...
pre-commit installed at .git/hooks/pre-commit
If you commit a Python or Markdown file or a script, these hooks will run at commit time.
Running Hooks in CI
To verify formatting in CI, run:
This builds your environment and runs all hooks against the repository, making it easy to catch formatting and linting issues in pull requests.
The .pre-commit-config.yaml File
The .pre-commit-config.yaml file is a symlink to an autogenerated file in your devenv Nix store. It is not necessary to commit this file to your repository and can safely be ignored. This file name is added to your .gitignore by default when you run devenv init.
Adding Custom Hooks
If you’d like to define your own hook:
{
git-hooks.hooks.unit-tests = {
enable = true;
# The name of the hook (appears on the report table):
name = "Unit tests";
# The command to execute (mandatory):
entry = "make check";
# The pattern of files to run on (default: "" (all))
# see also https://pre-commit.com/#hooks-files
files = "\\.(c|h)$";
# List of file types to run on (default: [ "file" ] (all files))
# see also https://pre-commit.com/#filtering-files-with-types
# You probably only need to specify one of `files` or `types`:
types = [ "text" "c" ];
# Exclude files that were matched by these patterns (default: [ ] (none)):
excludes = [ "irrelevant\\.c" ];
# The language of the hook - tells pre-commit
# how to install the hook (default: "system")
# see also https://pre-commit.com/#supported-languages
language = "system";
# Set this to false to not pass the changed files
# to the command (default: true):
pass_filenames = false;
};
}
The full list of all available pre-built hooks can be found in the options reference.