Skip to content

Commit 8dd173f

Browse files
committed
fix: add configFile option
This fixes #345, by adding a `configFile` option to change the default (`.pre-commit-config.yaml`) and so enables the parallel usage of devenv and non-devenv maintained pre-commit hooks.
1 parent a5a9613 commit 8dd173f

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

modules/pre-commit.nix

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ in
362362
display a warning message when a renamed option is used.
363363
'';
364364
};
365+
366+
configFile = lib.mkOption {
367+
type = types.str;
368+
default = ".pre-commit-config.yaml";
369+
description = ''The name of the config file.'';
370+
};
365371
};
366372

367373
config =
@@ -397,22 +403,22 @@ in
397403
# filesystem churn. This improves performance with watch tools like lorri
398404
# and prevents installation loops by lorri.
399405
400-
if ! readlink "''${GIT_WC}/.pre-commit-config.yaml" >/dev/null \
401-
|| [[ $(readlink "''${GIT_WC}/.pre-commit-config.yaml") != ${configFile} ]]; then
406+
if ! readlink "''${GIT_WC}/${cfg.configFile}" >/dev/null \
407+
|| [[ $(readlink "''${GIT_WC}/${cfg.configFile}") != ${configFile} ]]; then
402408
echo 1>&2 "git-hooks.nix: updating $PWD repo"
403-
[ -L .pre-commit-config.yaml ] && unlink .pre-commit-config.yaml
409+
[ -L ${cfg.configFile} ] && unlink ${cfg.configFile}
404410
405-
if [ -e "''${GIT_WC}/.pre-commit-config.yaml" ]; then
406-
echo 1>&2 "git-hooks.nix: WARNING: Refusing to install because of pre-existing .pre-commit-config.yaml"
407-
echo 1>&2 " 1. Translate .pre-commit-config.yaml contents to the new syntax in your Nix file"
411+
if [ -e "''${GIT_WC}/${cfg.configFile}" ]; then
412+
echo 1>&2 "git-hooks.nix: WARNING: Refusing to install because of pre-existing ${cfg.configFile}"
413+
echo 1>&2 " 1. Translate ${cfg.configFile} contents to the new syntax in your Nix file"
408414
echo 1>&2 " see https://github.com/cachix/git-hooks.nix#getting-started"
409-
echo 1>&2 " 2. remove .pre-commit-config.yaml"
410-
echo 1>&2 " 3. add .pre-commit-config.yaml to .gitignore"
415+
echo 1>&2 " 2. remove ${cfg.configFile}"
416+
echo 1>&2 " 3. add ${cfg.configFile} to .gitignore"
411417
else
412418
if ${boolToString cfg.addGcRoot}; then
413-
nix-store --add-root "''${GIT_WC}/.pre-commit-config.yaml" --indirect --realise ${configFile}
419+
nix-store --add-root "''${GIT_WC}/${cfg.configFile}" --indirect --realise ${configFile}
414420
else
415-
ln -fs ${configFile} "''${GIT_WC}/.pre-commit-config.yaml"
421+
ln -fs ${configFile} "''${GIT_WC}/${cfg.configFile}"
416422
fi
417423
# Remove any previously installed hooks (since pre-commit itself has no convergent design)
418424
hooks="${concatStringsSep " " (remove "manual" supportedHooksLib.supportedHooks )}"
@@ -429,10 +435,10 @@ in
429435
# if you amend these switches please also review $hooks above
430436
commit | merge-commit | push)
431437
stage="pre-"$stage
432-
pre-commit install -t $stage
438+
pre-commit install -c ${cfg.configFile} -t $stage
433439
;;
434440
${concatStringsSep "|" supportedHooksLib.supportedHooks})
435-
pre-commit install -t $stage
441+
pre-commit install -c ${cfg.configFile} -t $stage
436442
;;
437443
*)
438444
echo 1>&2 "ERROR: git-hooks.nix: either $stage is not a valid stage or git-hooks.nix doesn't yet support it."
@@ -442,7 +448,7 @@ in
442448
done
443449
# ... or default 'pre-commit' hook
444450
else
445-
pre-commit install
451+
pre-commit install -c ${cfg.configFile}
446452
fi
447453
448454
# Fetch the absolute path to the git common directory. This will normally point to $GIT_WC/.git.

0 commit comments

Comments
 (0)