From bf7cd0ea0d275a876d31726f4cfd6084e6f0f6ac Mon Sep 17 00:00:00 2001 From: Zahin Mohammad Date: Thu, 9 Apr 2026 22:51:39 -0400 Subject: [PATCH 1/2] chore(root): setup commitlint as a nix pre-commit hook Add pre-commit-hooks.nix input and configure commitlint on the commit-msg stage, mirroring the setup in bitgo-microservices. Entering the nix dev shell now installs the hook automatically so commit messages are validated locally without manual setup. WAL-565 --- flake.lock | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 26 +++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/flake.lock b/flake.lock index c0679747a0..43ea7993cb 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,42 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1687316158, @@ -31,10 +68,33 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1775585728, + "narHash": "sha256-8Psjt+TWvE4thRKktJsXfR6PA/fWWsZ04DVaY6PUhr4=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "580633fa3fe5fc0379905986543fd7495481913d", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "nixpkgs": "nixpkgs", - "nixpkgs-nodejs": "nixpkgs-nodejs" + "nixpkgs-nodejs": "nixpkgs-nodejs", + "pre-commit-hooks": "pre-commit-hooks" } } }, diff --git a/flake.nix b/flake.nix index df2f2f3068..6ea1adf26b 100644 --- a/flake.nix +++ b/flake.nix @@ -2,12 +2,20 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs"; nixpkgs-nodejs.url = "github:nixos/nixpkgs/6ad174a6dc07c7742fc64005265addf87ad08615"; # Node.js 22.14.0 + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + # Avoids pulling in a second version of `nixpkgs` + inputs = { + nixpkgs.follows = "nixpkgs"; + }; + }; }; outputs = { self, nixpkgs, nixpkgs-nodejs, + pre-commit-hooks, }: let forEachSystem = nixpkgs.lib.genAttrs [ "aarch64-darwin" @@ -16,8 +24,24 @@ "x86_64-linux" ]; in { + checks = forEachSystem (system: { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + commitlint = { + enable = true; + name = "commitlint"; + entry = "npx --no -- commitlint --edit"; + language = "system"; + stages = ["commit-msg"]; + }; + }; + }; + }); + devShells = forEachSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; + pre-commit-check = self.checks.${system}.pre-commit-check; in { default = pkgs.mkShell { packages = with nixpkgs-nodejs.legacyPackages.${system}; [ @@ -27,6 +51,8 @@ shellHook = '' export PATH="$(pwd)/node_modules/.bin:$PATH" + ${pre-commit-check.shellHook} + pre-commit install --hook-type commit-msg ''; }; }); From d01e1cb2c624938760bea5d26fb3dd8ff77665b6 Mon Sep 17 00:00:00 2001 From: Zahin Mohammad Date: Thu, 9 Apr 2026 22:56:34 -0400 Subject: [PATCH 2/2] chore(root): add commitlint as a husky commit-msg hook Add a commit-msg husky hook that runs `yarn check-commits` to validate commit messages locally. This ensures conventional commit format is enforced before commits are pushed, for all developers regardless of their shell setup. Reverts the nix-specific pre-commit-hooks approach in favor of the simpler husky-based hook which works universally after `yarn install`. WAL-565 --- .husky/commit-msg | 6 +++++ flake.lock | 62 +---------------------------------------------- flake.nix | 26 -------------------- 3 files changed, 7 insertions(+), 87 deletions(-) create mode 100755 .husky/commit-msg diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000000..cd9d4d836c --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,6 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" +rootDir=$(pwd) +cd "$rootDir" + +yarn check-commits diff --git a/flake.lock b/flake.lock index 43ea7993cb..c0679747a0 100644 --- a/flake.lock +++ b/flake.lock @@ -1,42 +1,5 @@ { "nodes": { - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1767039857, - "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", - "owner": "NixOS", - "repo": "flake-compat", - "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "flake-compat", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "pre-commit-hooks", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1709087332, - "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1687316158, @@ -68,33 +31,10 @@ "type": "github" } }, - "pre-commit-hooks": { - "inputs": { - "flake-compat": "flake-compat", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1775585728, - "narHash": "sha256-8Psjt+TWvE4thRKktJsXfR6PA/fWWsZ04DVaY6PUhr4=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "580633fa3fe5fc0379905986543fd7495481913d", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, "root": { "inputs": { "nixpkgs": "nixpkgs", - "nixpkgs-nodejs": "nixpkgs-nodejs", - "pre-commit-hooks": "pre-commit-hooks" + "nixpkgs-nodejs": "nixpkgs-nodejs" } } }, diff --git a/flake.nix b/flake.nix index 6ea1adf26b..df2f2f3068 100644 --- a/flake.nix +++ b/flake.nix @@ -2,20 +2,12 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs"; nixpkgs-nodejs.url = "github:nixos/nixpkgs/6ad174a6dc07c7742fc64005265addf87ad08615"; # Node.js 22.14.0 - pre-commit-hooks = { - url = "github:cachix/pre-commit-hooks.nix"; - # Avoids pulling in a second version of `nixpkgs` - inputs = { - nixpkgs.follows = "nixpkgs"; - }; - }; }; outputs = { self, nixpkgs, nixpkgs-nodejs, - pre-commit-hooks, }: let forEachSystem = nixpkgs.lib.genAttrs [ "aarch64-darwin" @@ -24,24 +16,8 @@ "x86_64-linux" ]; in { - checks = forEachSystem (system: { - pre-commit-check = pre-commit-hooks.lib.${system}.run { - src = ./.; - hooks = { - commitlint = { - enable = true; - name = "commitlint"; - entry = "npx --no -- commitlint --edit"; - language = "system"; - stages = ["commit-msg"]; - }; - }; - }; - }); - devShells = forEachSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - pre-commit-check = self.checks.${system}.pre-commit-check; in { default = pkgs.mkShell { packages = with nixpkgs-nodejs.legacyPackages.${system}; [ @@ -51,8 +27,6 @@ shellHook = '' export PATH="$(pwd)/node_modules/.bin:$PATH" - ${pre-commit-check.shellHook} - pre-commit install --hook-type commit-msg ''; }; });