about summary refs log tree commit diff
path: root/src/nix-collect-garbage/nix-collect-garbage.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-05-21T14·26+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-05-21T14·28+0200
commit4ca5a9dcfd577487f8a5b192e8ec525c5baad8cb (patch)
treed3686237252fae1cf7e719a4f4116cabfd467a18 /src/nix-collect-garbage/nix-collect-garbage.cc
parent22b1a8d43f0dea4f85bce2e79b1b986ecd8ba7f6 (diff)
nix-collect-garbage: Don't call nix-env
Also, make sure --delete-older-than doesn't delete the current
generation.
Diffstat (limited to 'src/nix-collect-garbage/nix-collect-garbage.cc')
-rw-r--r--src/nix-collect-garbage/nix-collect-garbage.cc14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/nix-collect-garbage/nix-collect-garbage.cc b/src/nix-collect-garbage/nix-collect-garbage.cc
index 740ef88f53..b671e6cb82 100644
--- a/src/nix-collect-garbage/nix-collect-garbage.cc
+++ b/src/nix-collect-garbage/nix-collect-garbage.cc
@@ -1,5 +1,5 @@
 #include "store-api.hh"
-#include "hash.hh"
+#include "profiles.hh"
 #include "shared.hh"
 #include "globals.hh"
 
@@ -7,7 +7,7 @@
 
 using namespace nix;
 
-std::string gen = "old";
+std::string deleteOlderThan;
 bool dryRun = false;
 
 void runProgramSimple(Path program, const Strings & args)
@@ -49,10 +49,10 @@ void removeOldGenerations(std::string dir)
             auto link = readLink(path);
             if (link.find("link") != string::npos) {
                 printMsg(lvlInfo, format("removing old generations of profile %1%") % path);
-
-                auto args = Strings{"-p", path, "--delete-generations", gen};
-                if (dryRun) args.push_back("--dry-run");
-                runProgramSimple(settings.nixBinDir + "/nix-env", args);
+                if (deleteOlderThan != "")
+                    deleteGenerationsOlderThan(path, deleteOlderThan, dryRun);
+                else
+                    deleteOldGenerations(path, dryRun);
             }
         } else if (type == DT_DIR) {
             removeOldGenerations(path);
@@ -76,7 +76,7 @@ int main(int argc, char * * argv)
             else if (*arg == "--delete-old" || *arg == "-d") removeOld = true;
             else if (*arg == "--delete-older-than") {
                 removeOld = true;
-                gen = getArg(*arg, arg, end);
+                deleteOlderThan = getArg(*arg, arg, end);
             }
             else if (*arg == "--dry-run") dryRun = true;
             else