95
95
set +e
96
96
# Set HOME to a temporary directory for pre-commit to create its cache files in.
97
97
HOME=$(mktemp -d)
98
- ln -fs ${ cfg . configFile } .pre-commit-config.yaml
98
+ ln -fs ${ cfg . configFile } ${ cfg . configPath }
99
99
git init -q
100
100
git add .
101
101
git config --global user.email "you@example.com"
@@ -104,10 +104,10 @@ let
104
104
if [[ ${ toString ( compare cfg . installStages [ "manual" ] ) } -eq 0 ]]
105
105
then
106
106
echo "Running: $ pre-commit run --hook-stage manual --all-files"
107
- pre-commit run --hook-stage manual --all-files
107
+ pre-commit run -c ${ cfg . configPath } - -hook-stage manual --all-files
108
108
else
109
109
echo "Running: $ pre-commit run --all-files"
110
- pre-commit run --all-files
110
+ pre-commit run -c ${ cfg . configPath } - -all-files
111
111
fi
112
112
exitcode=$?
113
113
git --no-pager diff --color
281
281
defaultText = "<derivation>" ;
282
282
} ;
283
283
284
+ configPath = lib . mkOption {
285
+ type = types . str ;
286
+ default = ".pre-commit-config.yaml" ;
287
+ description =
288
+ ''
289
+ The path to the generated pre-commit configuration file.
290
+ '' ;
291
+ } ;
292
+
284
293
src =
285
294
lib . mkOption {
286
295
description = ''
347
356
type = types . bool ;
348
357
default = true ;
349
358
description = ''
350
- Whether to add the generated pre-commit- config.yaml to the garbage collector roots.
359
+ Whether to add the generated pre-commit config to the garbage collector roots.
351
360
This prevents Nix from garbage-collecting the tools used by hooks.
352
361
'' ;
353
362
} ;
419
428
# filesystem churn. This improves performance with watch tools like lorri
420
429
# and prevents installation loops by lorri.
421
430
422
- if ! readlink "'' ${GIT_WC}/.pre-commit-config.yaml " >/dev/null \
423
- || [[ $(readlink "'' ${GIT_WC}/.pre-commit-config.yaml ") != ${ configFile } ]]; then
431
+ if ! readlink "'' ${GIT_WC}/${ cfg . configPath } " >/dev/null \
432
+ || [[ $(readlink "'' ${GIT_WC}/${ cfg . configPath } ") != ${ cfg . configFile } ]]; then
424
433
echo 1>&2 "git-hooks.nix: updating $PWD repo"
425
- [ -L .pre-commit-config.yaml ] && unlink .pre-commit-config.yaml
434
+ [ -L ${ cfg . configPath } ] && unlink ${ cfg . configPath }
426
435
427
- if [ -e "'' ${GIT_WC}/.pre-commit-config.yaml " ]; then
428
- echo 1>&2 "git-hooks.nix: WARNING: Refusing to install because of pre-existing .pre-commit-config.yaml "
429
- echo 1>&2 " 1. Translate .pre-commit-config.yaml contents to the new syntax in your Nix file"
436
+ if [ -e "'' ${GIT_WC}/${ cfg . configPath } " ]; then
437
+ echo 1>&2 "git-hooks.nix: WARNING: Refusing to install because of pre-existing ${ cfg . configPath } "
438
+ echo 1>&2 " 1. Translate ${ cfg . configPath } contents to the new syntax in your Nix file"
430
439
echo 1>&2 " see https://github.com/cachix/git-hooks.nix#getting-started"
431
- echo 1>&2 " 2. remove .pre-commit-config.yaml "
432
- echo 1>&2 " 3. add .pre-commit-config.yaml to .gitignore"
440
+ echo 1>&2 " 2. remove ${ cfg . configPath } "
441
+ echo 1>&2 " 3. add ${ cfg . configPath } to .gitignore"
433
442
else
434
443
if ${ boolToString cfg . addGcRoot } ; then
435
- nix-store --add-root "'' ${GIT_WC}/.pre-commit-config.yaml " --indirect --realise ${ configFile }
444
+ nix-store --add-root "'' ${GIT_WC}/${ cfg . configPath } " --indirect --realise ${ cfg . configFile }
436
445
else
437
- ln -fs ${ configFile } "'' ${GIT_WC}/.pre-commit-config.yaml "
446
+ ln -fs ${ cfg . configFile } "'' ${GIT_WC}/${ cfg . configPath } "
438
447
fi
439
448
# Remove any previously installed hooks (since pre-commit itself has no convergent design)
440
449
hooks="${ concatStringsSep " " ( remove "manual" supportedHooksLib . supportedHooks ) } "
451
460
# if you amend these switches please also review $hooks above
452
461
commit | merge-commit | push)
453
462
stage="pre-"$stage
454
- pre-commit install -t $stage
463
+ pre-commit install -c ${ cfg . configPath } - t $stage
455
464
;;
456
465
${ concatStringsSep "|" supportedHooksLib . supportedHooks } )
457
- pre-commit install -t $stage
466
+ pre-commit install -c ${ cfg . configPath } - t $stage
458
467
;;
459
468
*)
460
469
echo 1>&2 "ERROR: git-hooks.nix: either $stage is not a valid stage or git-hooks.nix doesn't yet support it."
464
473
done
465
474
# ... or default 'pre-commit' hook
466
475
else
467
- pre-commit install
476
+ pre-commit install -c ${ cfg . configPath }
468
477
fi
469
478
470
479
# Fetch the absolute path to the git common directory. This will normally point to $GIT_WC/.git.
0 commit comments