Skip to content

Commit 6f4e2a2

Browse files
authored
Merge pull request #529 from terlar/configurable-git-package
feat: make git package configurable and default to gitMinimal
2 parents 3308484 + f833300 commit 6f4e2a2

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

modules/pre-commit.nix

+21-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let
1212
remove
1313
;
1414

15-
inherit (pkgs) runCommand git;
15+
inherit (pkgs) runCommand;
1616

1717
cfg = config;
1818
install_stages = lib.unique (builtins.concatLists (lib.mapAttrsToList (_: h: h.stages) enabledHooks));
@@ -51,7 +51,7 @@ let
5151
);
5252

5353
run =
54-
runCommand "pre-commit-run" { buildInputs = [ git ]; } ''
54+
runCommand "pre-commit-run" { buildInputs = [ cfg.gitPackage ]; } ''
5555
set +e
5656
HOME=$PWD
5757
# Use `chmod +w` instead of `cp --no-preserve=mode` to be able to write and to
@@ -115,6 +115,20 @@ in
115115
'';
116116
};
117117

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+
118132
tools =
119133
mkOption {
120134
type = types.lazyAttrsOf (types.nullOr types.package);
@@ -338,10 +352,10 @@ in
338352
if ! type -t git >/dev/null; then
339353
# This happens in pure shells, including lorri
340354
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
342356
echo 1>&2 "WARNING: git-hooks.nix: .git not found; skipping installation."
343357
else
344-
GIT_WC=`${git}/bin/git rev-parse --show-toplevel`
358+
GIT_WC=`${cfg.gitPackage}/bin/git rev-parse --show-toplevel`
345359
346360
# These update procedures compare before they write, to avoid
347361
# filesystem churn. This improves performance with watch tools like lorri
@@ -369,7 +383,7 @@ in
369383
for hook in $hooks; do
370384
pre-commit uninstall -t $hook
371385
done
372-
${git}/bin/git config --local core.hooksPath ""
386+
${cfg.gitPackage}/bin/git config --local core.hooksPath ""
373387
# Add hooks for configured stages (only) ...
374388
if [ ! -z "${concatStringsSep " " install_stages}" ]; then
375389
for stage in ${concatStringsSep " " install_stages}; do
@@ -396,12 +410,12 @@ in
396410
fi
397411
398412
# 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)
400414
401415
# Convert the absolute path to a path relative to the toplevel working directory.
402416
common_dir=''${common_dir#''$GIT_WC/}
403417
404-
${git}/bin/git config --local core.hooksPath "''$common_dir/hooks"
418+
${cfg.gitPackage}/bin/git config --local core.hooksPath "''$common_dir/hooks"
405419
fi
406420
fi
407421
fi

0 commit comments

Comments
 (0)