|
12 | 12 | remove |
13 | 13 | ; |
14 | 14 |
|
15 | | - inherit (pkgs) runCommand git; |
| 15 | + inherit (pkgs) runCommand; |
16 | 16 |
|
17 | 17 | cfg = config; |
18 | 18 | install_stages = lib.unique (builtins.concatLists (lib.mapAttrsToList (_: h: h.stages) enabledHooks)); |
|
51 | 51 | ); |
52 | 52 |
|
53 | 53 | run = |
54 | | - runCommand "pre-commit-run" { buildInputs = [ git ]; } '' |
| 54 | + runCommand "pre-commit-run" { buildInputs = [ cfg.gitPackage ]; } '' |
55 | 55 | set +e |
56 | 56 | HOME=$PWD |
57 | 57 | # Use `chmod +w` instead of `cp --no-preserve=mode` to be able to write and to |
|
115 | 115 | ''; |
116 | 116 | }; |
117 | 117 |
|
| 118 | + gitPackage = |
| 119 | + mkOption { |
| 120 | + type = types.package; |
| 121 | + description = |
| 122 | + '' |
| 123 | + The `git` package to use. |
| 124 | + ''; |
| 125 | + default = pkgs.gitMinimal; |
| 126 | + defaultText = |
| 127 | + lib.literalExpression or literalExample '' |
| 128 | + pkgs.gitMinimal |
| 129 | + ''; |
| 130 | + }; |
| 131 | + |
118 | 132 | tools = |
119 | 133 | mkOption { |
120 | 134 | type = types.lazyAttrsOf (types.nullOr types.package); |
|
338 | 352 | if ! type -t git >/dev/null; then |
339 | 353 | # This happens in pure shells, including lorri |
340 | 354 | echo 1>&2 "WARNING: git-hooks.nix: git command not found; skipping installation." |
341 | | - elif ! ${git}/bin/git rev-parse --git-dir &> /dev/null; then |
| 355 | + elif ! ${cfg.gitPackage}/bin/git rev-parse --git-dir &> /dev/null; then |
342 | 356 | echo 1>&2 "WARNING: git-hooks.nix: .git not found; skipping installation." |
343 | 357 | else |
344 | | - GIT_WC=`${git}/bin/git rev-parse --show-toplevel` |
| 358 | + GIT_WC=`${cfg.gitPackage}/bin/git rev-parse --show-toplevel` |
345 | 359 |
|
346 | 360 | # These update procedures compare before they write, to avoid |
347 | 361 | # filesystem churn. This improves performance with watch tools like lorri |
|
369 | 383 | for hook in $hooks; do |
370 | 384 | pre-commit uninstall -t $hook |
371 | 385 | done |
372 | | - ${git}/bin/git config --local core.hooksPath "" |
| 386 | + ${cfg.gitPackage}/bin/git config --local core.hooksPath "" |
373 | 387 | # Add hooks for configured stages (only) ... |
374 | 388 | if [ ! -z "${concatStringsSep " " install_stages}" ]; then |
375 | 389 | for stage in ${concatStringsSep " " install_stages}; do |
|
396 | 410 | fi |
397 | 411 |
|
398 | 412 | # Fetch the absolute path to the git common directory. This will normally point to $GIT_WC/.git. |
399 | | - common_dir=''$(${git}/bin/git rev-parse --path-format=absolute --git-common-dir) |
| 413 | + common_dir=''$(${cfg.gitPackage}/bin/git rev-parse --path-format=absolute --git-common-dir) |
400 | 414 |
|
401 | 415 | # Convert the absolute path to a path relative to the toplevel working directory. |
402 | 416 | common_dir=''${common_dir#''$GIT_WC/} |
403 | 417 |
|
404 | | - ${git}/bin/git config --local core.hooksPath "''$common_dir/hooks" |
| 418 | + ${cfg.gitPackage}/bin/git config --local core.hooksPath "''$common_dir/hooks" |
405 | 419 | fi |
406 | 420 | fi |
407 | 421 | fi |
|
0 commit comments