https://github.com/jmgilman/nix-pre-commit
Generate pre-commit configurations with your flake.nix
https://github.com/jmgilman/nix-pre-commit
nix pre-commit pre-commit-hooks
Last synced: 8 months ago
JSON representation
Generate pre-commit configurations with your flake.nix
- Host: GitHub
- URL: https://github.com/jmgilman/nix-pre-commit
- Owner: jmgilman
- License: mit
- Created: 2022-05-21T18:26:04.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-25T13:34:46.000Z (about 2 years ago)
- Last Synced: 2025-03-29T13:52:09.251Z (9 months ago)
- Topics: nix, pre-commit, pre-commit-hooks
- Language: Nix
- Homepage:
- Size: 7.81 KB
- Stars: 21
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nix-pre-commit
> Generate [pre-commit][1] configurations with your flake.nix
## Usage
Add it as an input to your flake and define the pre-commit configuration:
```nix
{
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:
```yaml
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][2] of the `.pre-commit-config.yaml` file. A small
bootstrapping script is supplied via a [shellHook][3] which links the generated
config into the local directory and installs the hooks.
## Contributing
Check out the [issues][4] for items needing attention or submit your own and
then:
1. Fork the repo ()
2. Create your feature branch (git checkout -b feature/fooBar)
3. Commit your changes (git commit -am 'Add some fooBar')
4. Push to the branch (git push origin feature/fooBar)
5. Create a new Pull Request
[1]: https://pre-commit.com/
[2]: https://pre-commit.com/#pre-commit-configyaml---hooks
[3]: https://nixos.org/manual/nix/stable/command-ref/nix-shell.html#description
[4]: https://github.com/jmgilman/nix-pre-commit/issues