Skip to content

Commit b5a6275

Browse files
authored
Merge pull request #573 from cachix/unlink-config
2 parents 1293270 + f4cdd2c commit b5a6275

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

modules/pre-commit.nix

+13-7
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ in
286286
default = ".pre-commit-config.yaml";
287287
description =
288288
''
289-
The path to the generated pre-commit configuration file.
289+
The path where to generate the pre-commit configuration file.
290+
291+
This path is relative to the root of the project. By default,
292+
this is set to ".pre-commit-config.yaml", which is the standard
293+
location expected by pre-commit.
290294
'';
291295
};
292296

@@ -428,14 +432,16 @@ in
428432
if ! readlink "''${GIT_WC}/${cfg.configPath}" >/dev/null \
429433
|| [[ $(readlink "''${GIT_WC}/${cfg.configPath}") != ${cfg.configFile} ]]; then
430434
echo 1>&2 "git-hooks.nix: updating $PWD repo"
431-
[ -L ${cfg.configPath} ] && unlink ${cfg.configPath}
435+
[ -L "''${GIT_WC}/${cfg.configPath}" ] && unlink "''${GIT_WC}/${cfg.configPath}"
432436
433437
if [ -e "''${GIT_WC}/${cfg.configPath}" ]; then
434-
echo 1>&2 "git-hooks.nix: WARNING: Refusing to install because of pre-existing ${cfg.configPath}"
435-
echo 1>&2 " 1. Translate ${cfg.configPath} contents to the new syntax in your Nix file"
436-
echo 1>&2 " see https://github.com/cachix/git-hooks.nix#getting-started"
437-
echo 1>&2 " 2. remove ${cfg.configPath}"
438-
echo 1>&2 " 3. add ${cfg.configPath} to .gitignore"
438+
echo 1>&2 "git-hooks.nix: WARNING: Refusing to install because of an existing config at ${cfg.configPath}"
439+
echo 1>&2 ""
440+
echo 1>&2 " To migrate the existing config to a Nix configuration:"
441+
echo 1>&2 " 1. Translate the contents of ${cfg.configPath} into a Nix configuration."
442+
echo 1>&2 " See https://github.com/cachix/git-hooks.nix#getting-started"
443+
echo 1>&2 " 2. Remove ${cfg.configPath}"
444+
echo 1>&2 " 3. Add ${cfg.configPath} to .gitignore"
439445
else
440446
if ${boolToString cfg.addGcRoot}; then
441447
nix-store --add-root "''${GIT_WC}/${cfg.configPath}" --indirect --realise ${cfg.configFile}

nix/run.nix

+16-20
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
builtinStuff@{ pkgs, tools, isFlakes, pre-commit, git, runCommand, writeText, writeScript, lib, gitignore-nix-src }:
22

3-
{ src
4-
, settings ? { }
5-
, hooks ? { }
6-
, excludes ? [ ]
7-
, tools ? { }
8-
, default_stages ? [ "pre-commit" ]
9-
, addGcRoot ? true
3+
options@{ src
104
, imports ? [ ]
11-
, configPath ? ".pre-commit-config.yaml"
5+
, tools ? { }
6+
, ...
127
}:
138
let
9+
moduleOptions = builtins.removeAttrs options [ "imports" "tools" ];
10+
1411
project =
1512
lib.evalModules {
1613
modules =
1714
[
1815
../modules/all-modules.nix
1916
{
20-
config =
21-
{
22-
_module.args.pkgs = pkgs;
23-
_module.args.gitignore-nix-src = gitignore-nix-src;
24-
inherit hooks excludes default_stages settings addGcRoot configPath;
25-
tools = builtinStuff.tools // tools;
26-
package = pre-commit;
27-
} // (if isFlakes
28-
then { rootSrc = src; }
29-
else {
30-
rootSrc = gitignore-nix-src.lib.gitignoreSource src;
31-
});
17+
config = moduleOptions //
18+
{
19+
_module.args.pkgs = pkgs;
20+
_module.args.gitignore-nix-src = gitignore-nix-src;
21+
package = lib.mkDefault pre-commit;
22+
tools = lib.mkDefault (builtinStuff.tools // tools);
23+
} // (if isFlakes
24+
then { rootSrc = src; }
25+
else {
26+
rootSrc = gitignore-nix-src.lib.gitignoreSource src;
27+
});
3228
}
3329
] ++ imports;
3430
};

0 commit comments

Comments
 (0)