Have devShell install git pre-commit hook

This commit is contained in:
Archit Gupta 2023-04-16 13:22:21 -07:00
parent 07e68ac51b
commit 9c40724207
4 changed files with 27 additions and 3 deletions

View File

@ -62,6 +62,14 @@ let
+ optionalString (!pathExists (src + /.ecrc)) + optionalString (!pathExists (src + /.ecrc))
" -disable-indent-size -disable-max-line-length"; " -disable-indent-size -disable-max-line-length";
}); });
shellHook = { lib, flakelite }: ''
if [ -f flake.nix ] && [ -d .git/hooks ] &&
[ ! -f .git/hooks/pre-commit ]; then
echo Installing git pre-commit hook...
cp ${lib.getExe flakelite.inputs'.flakelite.packages.pre-commit
} .git/hooks
fi
'';
devTools = pkgs: with pkgs; [ nixpkgs-fmt nodePackages.prettier ]; devTools = pkgs: with pkgs; [ nixpkgs-fmt nodePackages.prettier ];
formatters = { formatters = {
"*.nix" = "nixpkgs-fmt"; "*.nix" = "nixpkgs-fmt";

View File

@ -6,9 +6,10 @@
inputs.nixpkgs.url = "nixpkgs/nixos-22.11"; inputs.nixpkgs.url = "nixpkgs/nixos-22.11";
outputs = inputs: outputs = inputs:
let let
lib = import ./. inputs; flakelite.lib = import ./. inputs;
in in
lib.mkFlake ./. { flakelite.lib.mkFlake ./. {
outputs = { inherit lib; }; nixDir = ./.;
outputs = flakelite;
}; };
} }

5
packages/pre-commit Normal file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
TREE=$(mktemp -d)
git archive "$(git write-tree)" | tar -xC "$TREE"
nix flake check "$TREE"

10
packages/pre-commit.nix Normal file
View File

@ -0,0 +1,10 @@
{ writeShellApplication
, nix
, git
, gnutar
}:
writeShellApplication {
name = "pre-commit";
runtimeInputs = [ nix git gnutar ];
text = builtins.readFile ./pre-commit;
}