From f6ea88d542e577285f81bbf12e36a9885104a8a9 Mon Sep 17 00:00:00 2001 From: Joe DeVivo Date: Mon, 25 Mar 2024 11:30:27 -0700 Subject: [PATCH] Add `check_phase` to pre-commit settings --- modules/pre-commit.nix | 26 ++++++++++++++++++-------- nix/run.nix | 3 ++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/modules/pre-commit.nix b/modules/pre-commit.nix index 54e1fe16..e73b71bf 100644 --- a/modules/pre-commit.nix +++ b/modules/pre-commit.nix @@ -69,14 +69,14 @@ let git config --global user.email "you@example.com" git config --global user.name "Your Name" git commit -m "init" - if [[ ${toString (compare install_stages [ "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 - else - echo "Running: $ pre-commit run --all-files" - ${cfg.package}/bin/pre-commit run --all-files - fi + local check_stage=${toString cfg.check_stage} + case $check_stage in + commit | merge-commit | push) + check_stage="pre-"$check_stage + ;; + esac + echo "Running: $ pre-commit run --hook-stage $check_stage --all-files" + ${cfg.package}/bin/pre-commit run --hook-stage $check_stage --all-files exitcode=$? git --no-pager diff --color touch $out @@ -263,6 +263,16 @@ in default = [ "commit" ]; }; + check_stage = + mkOption { + type = types.str; + description = lib.mdDoc + '' + This is pre-commit stage to be used in a nix `checkPhase`. `commit` maps to `pre-commit`, which is `pre-commit`'s default. + ''; + default = "commit"; + }; + rawConfig = mkOption { type = types.attrs; diff --git a/nix/run.nix b/nix/run.nix index 2179e50e..197d1300 100644 --- a/nix/run.nix +++ b/nix/run.nix @@ -5,6 +5,7 @@ builtinStuff@{ pkgs, tools, isFlakes, pre-commit, git, runCommand, writeText, wr , hooks ? { } , excludes ? [ ] , tools ? { } +, check_stage ? "commit" , default_stages ? [ "commit" ] }: let @@ -18,7 +19,7 @@ let { _module.args.pkgs = pkgs; _module.args.gitignore-nix-src = gitignore-nix-src; - inherit hooks excludes default_stages settings; + inherit hooks excludes default_stages check_stage settings; tools = builtinStuff.tools // tools; package = pre-commit; } // (if isFlakes