From 788ef287696452e19577aedc83c474216546799f Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Wed, 6 Mar 2024 07:09:34 +0530 Subject: [PATCH] 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 --- .gitignore | 1 + dev/flake.lock | 103 +++++++++++++++++++++++++++++++++++++++-- dev/flake.nix | 9 ++++ dev/nix/pre-commit.nix | 14 ++++++ 4 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 dev/nix/pre-commit.nix diff --git a/.gitignore b/.gitignore index 2d58df9..d9dfaaf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /result # created when `just run ` is used /test/data +/.pre-commit-config.yaml diff --git a/dev/flake.lock b/dev/flake.lock index bcdbccc..b96bd98 100644 --- a/dev/flake.lock +++ b/dev/flake.lock @@ -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" diff --git a/dev/flake.nix b/dev/flake.nix index d18d60e..81c7550 100644 --- a/dev/flake.nix +++ b/dev/flake.nix @@ -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 diff --git a/dev/nix/pre-commit.nix b/dev/nix/pre-commit.nix new file mode 100644 index 0000000..32a089d --- /dev/null +++ b/dev/nix/pre-commit.nix @@ -0,0 +1,14 @@ +{ ... }: +{ + perSystem = { pkgs, lib, ... }: { + pre-commit = { + check.enable = true; + settings = { + hooks = { + treefmt.enable = true; + commitizen.enable = true; + }; + }; + }; + }; +}