Skip to content

Commit

Permalink
feat: add an option to disable gc root creation
Browse files Browse the repository at this point in the history
Mostly for testing.
  • Loading branch information
sandydoo committed Aug 24, 2024
1 parent 6736cfd commit 3ca51c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion modules/pre-commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ in
internal = true;
};

addGcRoot = mkOption {
type = types.bool;
default = true;
description = ''
Whether to add the generated pre-commit-config.json to the garbage collector roots.
'';
};

assertions = lib.mkOption {
type = types.listOf types.unspecified;
internal = true;
Expand Down Expand Up @@ -351,7 +359,11 @@ in
echo 1>&2 " 2. remove .pre-commit-config.yaml"
echo 1>&2 " 3. add .pre-commit-config.yaml to .gitignore"
else
nix-store --add-root "''${GIT_WC}/.pre-commit-config.yaml" --realise ${configFile}
if [ $]
nix-store --add-root "''${GIT_WC}/.pre-commit-config.yaml" --realise ${configFile}
else
ln -fs ${configFile} "''${GIT_WC}/.pre-commit-config.yaml"
fi
# Remove any previously installed hooks (since pre-commit itself has no convergent design)
hooks="${concatStringsSep " " (remove "manual" supportedHooksLib.supportedHooks )}"
for hook in $hooks; do
Expand Down
4 changes: 2 additions & 2 deletions nix/installation-test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let

executeTest = lib.mapAttrsToList
(name: test:
let runDerivation = run ({ src = null; } // test.conf);
let runDerivation = run ({ src = null; settings.addGcRoot = false; } // test.conf);
in ''
rm -f ~/.git/hooks/*
${runDerivation.shellHook}
Expand All @@ -74,7 +74,7 @@ let
'')
tests;
in
runCommand "installation-test" { nativeBuildInputs = [ git perl coreutils mktemp nix ]; } ''
runCommand "installation-test" { nativeBuildInputs = [ git perl coreutils mktemp ]; } ''
set -eoux
HOME=$(mktemp -d)
Expand Down

0 comments on commit 3ca51c2

Please sign in to comment.