Generate pre-commit configurations with your flake.nix
Add it as an input to your flake and define the pre-commit configuration:
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs";
nix-pre-commit.url = "github:jmgilman/nix-pre-commit";
};
outputs = { self, nixpkgs, flake-utils, nix-pre-commit }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
config = {
repos = [
{
repo = "local";
hooks = [
{
id = "nixpkgs-fmt";
entry = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt";
language = "system";
files = "\\.nix";
}
];
}
];
};
in
{
devShell = pkgs.mkShell {
shellHook = (nix-pre-commit.lib.${system}.mkConfig {
inherit pkgs config;
}).shellHook;
};
}
);
}
This produces a .pre-commit-config.yaml
in the local directory:
default_stages:
- commit
repos:
- hooks:
- entry: /nix/store/l9vwl9yvjmdj3pixlj5i9kc4524bh78r-nixpkgs-fmt-1.2.0/bin/nixpkgs-fmt
files: \.nix
id: nixpkgs-fmt
language: system
name: nixpkgs-fmt
repo: local
The structure for the configuration specified in flake.nix
matches the
defined structure of the .pre-commit-config.yaml
file. A small
bootstrapping script is supplied via a shellHook which links the generated
config into the local directory and installs the hooks.
Check out the issues for items needing attention or submit your own and then:
- Fork the repo (https://github.com/jmgilman/dev-container/fork)
- Create your feature branch (git checkout -b feature/fooBar)
- Commit your changes (git commit -am 'Add some fooBar')
- Push to the branch (git push origin feature/fooBar)
- Create a new Pull Request