diff --git a/modules/pre-commit.nix b/modules/pre-commit.nix index c506aa9a..327f8e81 100644 --- a/modules/pre-commit.nix +++ b/modules/pre-commit.nix @@ -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; @@ -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 diff --git a/nix/installation-test.nix b/nix/installation-test.nix index 864c6e00..7e7ddc32 100644 --- a/nix/installation-test.nix +++ b/nix/installation-test.nix @@ -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} @@ -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)