From bf798609c796fb8e9945c5b87dc014c9b7a3058d Mon Sep 17 00:00:00 2001 From: Kazuki Okamoto Date: Tue, 3 Sep 2024 19:29:31 +0900 Subject: [PATCH] feat: update pre-commit.nix to be "run" customizable --- modules/pre-commit.nix | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/modules/pre-commit.nix b/modules/pre-commit.nix index a5fae075..506de414 100644 --- a/modules/pre-commit.nix +++ b/modules/pre-commit.nix @@ -53,14 +53,14 @@ let ); run = - runCommand "pre-commit-run" { buildInputs = [ git ]; } '' + runCommand "pre-commit-run" { buildInputs = [ git cfg.package ]; } '' set +e HOME=$PWD # Use `chmod +w` instead of `cp --no-preserve=mode` to be able to write and to # preserve the executable bit at the same time cp -R ${cfg.rootSrc} src chmod -R +w src - ln -fs ${configFile} src/.pre-commit-config.yaml + ln -fs ${cfg.configFile} src/.pre-commit-config.yaml cd src rm -rf .git git init -q @@ -68,13 +68,13 @@ let git config --global user.email "you@example.com" git config --global user.name "Your Name" git commit -m "init" -q - if [[ ${toString (compare install_stages [ "manual" ])} -eq 0 ]] + if [[ ${toString (compare cfg.installStages [ "manual" ])} -eq 0 ]] then echo "Running: $ pre-commit run --hook-stage manual --all-files" - ${cfg.package}/bin/pre-commit run --hook-stage manual --all-files + pre-commit run --hook-stage manual --all-files else echo "Running: $ pre-commit run --all-files" - ${cfg.package}/bin/pre-commit run --all-files + pre-commit run --all-files fi exitcode=$? git --no-pager diff --color @@ -205,7 +205,7 @@ in A derivation that tests whether the pre-commit hooks run cleanly on the entire project. ''; - readOnly = true; + readOnly = false; default = run; defaultText = ""; }; @@ -220,6 +220,18 @@ in readOnly = true; }; + configFile = + mkOption { + type = types.package; + description = + '' + The pre-commit configuration file. + ''; + readOnly = true; + default = configFile; + defaultText = ""; + }; + src = lib.mkOption { description = '' @@ -314,6 +326,15 @@ in display a warning message when a renamed option is used. ''; }; + + installStages = lib.mkOption { + type = types.listOf (types.either types.str types.anything); + description = '' + The stages to install the hooks to. + ''; + default = install_stages; + readOnly = true; + }; }; config =