diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 1eb7e806ca63e96349e9d74b859940c13d64817a..2e3a2221857e1e3e070a1a0d50b86610826ba3c0 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -911,6 +911,10 @@ DerivationGoal::DerivationGoal(const Path & drvPath, const BasicDerivation & drv
     state = &DerivationGoal::haveDerivation;
     name = (format("building of %1%") % showPaths(outputPaths(drv))).str();
     trace("created");
+
+    /* Prevent the .chroot directory from being
+       garbage-collected. (See isActiveTempFile() in gc.cc.) */
+    worker.store.addTempRoot(drvPath);
 }