Skip to content

Commit b24ef71

Browse files
committed
check: set HOME to a tmp dir to avoid polluting the working dir
pre-commit creates cache files in $HOME/.cache/pre-commit. If $HOME is set to $PWD, we will pollute the working directory, causing hook failures. Previously, we would copy the source files into a nested `src` directory. Now that Nix already provides the source files in the working directory for us, to avoid another copy, we set $HOME to a temporary directory.
1 parent 4c09990 commit b24ef71

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

modules/pre-commit.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ let
8686
run =
8787
mkDerivation {
8888
name = "pre-commit-run";
89-
9089
src = cfg.rootSrc;
9190
buildInputs = [ cfg.gitPackage ];
9291
nativeBuildInputs = enabledExtraPackages
9392
++ lib.optional (config.settings.rust.check.cargoDeps != null) cargoSetupHook;
9493
cargoDeps = config.settings.rust.check.cargoDeps;
9594
buildPhase = ''
9695
set +e
97-
HOME=$PWD
96+
# Set HOME to a temporary directory for pre-commit to create its cache files in.
97+
HOME=$(mktemp -d)
9898
ln -fs ${configFile} .pre-commit-config.yaml
9999
git init -q
100100
git add .
@@ -111,6 +111,7 @@ let
111111
fi
112112
exitcode=$?
113113
git --no-pager diff --color
114+
# Derivations must produce an output
114115
mkdir $out
115116
[ $? -eq 0 ] && exit $exitcode
116117
'';

0 commit comments

Comments
 (0)