about summary refs log tree commit diff
path: root/src/libstore/build.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-09-05T18·43+0200
committerEelco Dolstra <edolstra@gmail.com>2017-09-05T18·43+0200
commit0b606aad46e1d96da36d4831df63ad90f11d21c3 (patch)
tree5787f4f043f7316a8ad4625772abe9a4da3c1d57 /src/libstore/build.cc
parentb932ea58ec610830ed3141bb14fbd812aa66b2c1 (diff)
Add automatic garbage collection
Nix can now automatically run the garbage collector during builds or
while adding paths to the store. The option "min-free = <bytes>"
specifies that Nix should run the garbage collector whenever free
space in the Nix store drops below <bytes>. It will then delete
garbage until "max-free" bytes are available.

Garbage collection during builds is asynchronous; running builds are
not paused and new builds are not blocked. However, there also is a
synchronous GC run prior to the first build/substitution.

Currently, no old GC roots are deleted (as in "nix-collect-garbage
-d").
Diffstat (limited to 'src/libstore/build.cc')
-rw-r--r--src/libstore/build.cc5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index ce41752e6239..ddf4bf00d8c2 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -3957,6 +3957,8 @@ void Worker::run(const Goals & _topGoals)
 
         checkInterrupt();
 
+        store.autoGC(false);
+
         /* Call every wake goal (in the ordering established by
            CompareGoalPtrs). */
         while (!awake.empty() && !topGoals.empty()) {
@@ -4014,6 +4016,9 @@ void Worker::waitForInput()
        is a build timeout, then wait for input until the first
        deadline for any child. */
     auto nearest = steady_time_point::max(); // nearest deadline
+    if (settings.minFree.get() != 0)
+        // Periodicallty wake up to see if we need to run the garbage collector.
+        nearest = before + std::chrono::seconds(10);
     for (auto & i : children) {
         if (!i.respectTimeouts) continue;
         if (0 != settings.maxSilentTime)