|
17 | 17 | mkdir -p $out/bin
|
18 | 18 | ln -s ${cfg.package}/bin/pre-commit $out/bin/pre-commit
|
19 | 19 | '';
|
| 20 | + |
| 21 | + anyEnabled = ((lib.filterAttrs (id: value: value.enable) cfg.hooks) != { }); |
20 | 22 | in
|
21 | 23 | {
|
22 | 24 | imports = [
|
|
40 | 42 | description = "Integration with https://github.com/cachix/git-hooks.nix";
|
41 | 43 | };
|
42 | 44 |
|
43 |
| - config = lib.mkIf ((lib.filterAttrs (id: value: value.enable) cfg.hooks) != { }) { |
44 |
| - ci = [ cfg.run ]; |
45 |
| - # Add the packages for any enabled hooks at the end to avoid overriding the language-defined packages. |
46 |
| - packages = lib.mkAfter ([ packageBin ] ++ (cfg.enabledPackages or [ ])); |
47 |
| - tasks = { |
48 |
| - # TODO: split installation script into status + exec |
49 |
| - "devenv:git-hooks:install" = { |
50 |
| - exec = cfg.installationScript; |
51 |
| - before = [ "devenv:enterShell" ]; |
52 |
| - }; |
53 |
| - "devenv:git-hooks:run" = { |
54 |
| - exec = "pre-commit run -a"; |
55 |
| - before = [ "devenv:enterTest" ]; |
| 45 | + config = lib.mkMerge [ |
| 46 | + (lib.mkIf (!anyEnabled) { |
| 47 | + # Remove .pre-commit-config.yaml if it exists and is in the nix store |
| 48 | + enterShell = '' |
| 49 | + preCommitConfig="$DEVENV_ROOT/.pre-commit-config.yaml" |
| 50 | + if $(nix-store --quiet --verify-path "$preCommitConfig" > /dev/null 2>&1); then |
| 51 | + echo Removing "$preCommitConfig" |
| 52 | + rm -rf "$preCommitConfig" |
| 53 | + fi |
| 54 | + ''; |
| 55 | + }) |
| 56 | + |
| 57 | + (lib.mkIf anyEnabled { |
| 58 | + ci = [ cfg.run ]; |
| 59 | + # Add the packages for any enabled hooks at the end to avoid overriding the language-defined packages. |
| 60 | + packages = lib.mkAfter ([ packageBin ] ++ (cfg.enabledPackages or [ ])); |
| 61 | + tasks = { |
| 62 | + # TODO: split installation script into status + exec |
| 63 | + "devenv:git-hooks:install" = { |
| 64 | + exec = cfg.installationScript; |
| 65 | + before = [ "devenv:enterShell" ]; |
| 66 | + }; |
| 67 | + "devenv:git-hooks:run" = { |
| 68 | + exec = "pre-commit run -a"; |
| 69 | + before = [ "devenv:enterTest" ]; |
| 70 | + }; |
56 | 71 | };
|
57 |
| - }; |
58 |
| - }; |
| 72 | + }) |
| 73 | + ]; |
59 | 74 | }
|
0 commit comments