Skip to content

Commit b6ee9db

Browse files
authored
Merge pull request #494 from kakkun61/customizable-run
feat: update pre-commit.nix to be "run" customizable
2 parents 741fee0 + 8057e18 commit b6ee9db

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

modules/pre-commit.nix

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,27 @@ let
8787
mkDerivation {
8888
name = "pre-commit-run";
8989
src = cfg.rootSrc;
90-
buildInputs = [ cfg.gitPackage ];
90+
buildInputs = [ cfg.gitPackage cfg.package ];
9191
nativeBuildInputs = enabledExtraPackages
9292
++ lib.optional (config.settings.rust.check.cargoDeps != null) cargoSetupHook;
9393
cargoDeps = config.settings.rust.check.cargoDeps;
9494
buildPhase = ''
9595
set +e
9696
# Set HOME to a temporary directory for pre-commit to create its cache files in.
9797
HOME=$(mktemp -d)
98-
ln -fs ${configFile} .pre-commit-config.yaml
98+
ln -fs ${cfg.configFile} .pre-commit-config.yaml
9999
git init -q
100100
git add .
101101
git config --global user.email "you@example.com"
102102
git config --global user.name "Your Name"
103103
git commit -m "init" -q
104-
if [[ ${toString (compare install_stages [ "manual" ])} -eq 0 ]]
104+
if [[ ${toString (compare cfg.installStages [ "manual" ])} -eq 0 ]]
105105
then
106106
echo "Running: $ pre-commit run --hook-stage manual --all-files"
107-
${cfg.package}/bin/pre-commit run --hook-stage manual --all-files
107+
pre-commit run --hook-stage manual --all-files
108108
else
109109
echo "Running: $ pre-commit run --all-files"
110-
${cfg.package}/bin/pre-commit run --all-files
110+
pre-commit run --all-files
111111
fi
112112
exitcode=$?
113113
git --no-pager diff --color
@@ -254,7 +254,7 @@ in
254254
A derivation that tests whether the pre-commit hooks run cleanly on
255255
the entire project.
256256
'';
257-
readOnly = true;
257+
readOnly = false;
258258
default = run;
259259
defaultText = lib.literalExpression "<derivation>";
260260
};
@@ -269,6 +269,18 @@ in
269269
readOnly = true;
270270
};
271271

272+
configFile =
273+
mkOption {
274+
type = types.package;
275+
description =
276+
''
277+
The pre-commit configuration file.
278+
'';
279+
readOnly = true;
280+
default = configFile;
281+
defaultText = "<derivation>";
282+
};
283+
272284
src =
273285
lib.mkOption {
274286
description = ''
@@ -363,6 +375,15 @@ in
363375
display a warning message when a renamed option is used.
364376
'';
365377
};
378+
379+
installStages = lib.mkOption {
380+
type = types.listOf (types.either types.str types.anything);
381+
description = ''
382+
The stages to install the hooks to.
383+
'';
384+
default = install_stages;
385+
readOnly = true;
386+
};
366387
};
367388

368389
config =

0 commit comments

Comments
 (0)