feat: add pre-commit-hooks.nix, enforcing conventional commits

enable treefmt and commitizen in pre-commit-hooks.nix

Along with this, we also:

* bump: update nixpkgs of dev flake for pre-commit-hooks.nix to work

the older version didn't have cljfmt
This commit is contained in:
shivaraj-bh 2024-03-06 07:09:34 +05:30 committed by Shivaraj B H
parent e0a1074f8a
commit 788ef28769
4 changed files with 124 additions and 3 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
/result
# created when `just run <service>` is used
/test/data
/.pre-commit-config.yaml

View File

@ -1,5 +1,21 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
@ -33,13 +49,52 @@
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks-nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1703887061,
"narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1697688401,
"narHash": "sha256-61QlajY7R9PbK25uFl55zh968CVNspwXX1zzimic4Uo=",
"lastModified": 1709613862,
"narHash": "sha256-mH+c2gFEzEe49lhUWJ0ieIaMaJ1W85E6G1xLm8ege90=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "458ef9126aa380996d77d44f53f886c2d8485f53",
"rev": "311a4be96d940a0c673e88bd5bc83ea4f005cc02",
"type": "github"
},
"original": {
@ -83,11 +138,38 @@
"type": "github"
}
},
"pre-commit-hooks-nix": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1708018599,
"narHash": "sha256-M+Ng6+SePmA8g06CmUZWi1AjG2tFBX9WCXElBHEKnyM=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "5df5a70ad7575f6601d91f0efec95dd9bc619431",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"flake-root": "flake-root",
"nixpkgs": "nixpkgs",
"pre-commit-hooks-nix": "pre-commit-hooks-nix",
"services-flake": "services-flake",
"treefmt-nix": "treefmt-nix"
}
@ -107,6 +189,21 @@
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_2"

View File

@ -4,6 +4,11 @@
flake-parts.url = "github:hercules-ci/flake-parts";
flake-root.url = "github:srid/flake-root";
treefmt-nix.url = "github:numtide/treefmt-nix";
pre-commit-hooks-nix = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.nixpkgs-stable.follows = "nixpkgs";
};
# CI will override `services-flake` to run checks on the latest source
services-flake.url = "github:juspay/services-flake";
};
@ -13,11 +18,14 @@
imports = [
inputs.flake-root.flakeModule
inputs.treefmt-nix.flakeModule
inputs.pre-commit-hooks-nix.flakeModule
./nix/pre-commit.nix
];
perSystem = { pkgs, lib, config, ... }: {
treefmt = {
projectRoot = inputs.services-flake;
projectRootFile = "flake.nix";
flakeCheck = false; # pre-commit-hooks.nix checks this
programs = {
nixpkgs-fmt.enable = true;
};
@ -29,6 +37,7 @@
# cf. https://flakular.in/haskell-flake/devshell#composing-devshells
inputsFrom = [
config.treefmt.build.devShell
config.pre-commit.devShell
];
shellHook = ''
echo

14
dev/nix/pre-commit.nix Normal file
View File

@ -0,0 +1,14 @@
{ ... }:
{
perSystem = { pkgs, lib, ... }: {
pre-commit = {
check.enable = true;
settings = {
hooks = {
treefmt.enable = true;
commitizen.enable = true;
};
};
};
};
}