about summary refs log tree commit diff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-08-16T15·00+0200
committerEelco Dolstra <edolstra@gmail.com>2017-08-16T18·56+0200
commit23b8b7e096d3a2a784387a09f68115706b1e9552 (patch)
tree5e8756716b67d87b8f8d48dcf5f0f108affe2219 /src/nix
parent40bffe0a43e5f2f320c6bae7e39ea9c26906451d (diff)
nix optimise-store: Add
This replaces "nix-store --optimise". Main difference is that it has a
progress indicator.
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/optimise-store.cc41
-rw-r--r--src/nix/progress-bar.cc10
2 files changed, 47 insertions, 4 deletions
diff --git a/src/nix/optimise-store.cc b/src/nix/optimise-store.cc
new file mode 100644
index 000000000000..725fb75a19ec
--- /dev/null
+++ b/src/nix/optimise-store.cc
@@ -0,0 +1,41 @@
+#include "command.hh"
+#include "shared.hh"
+#include "store-api.hh"
+
+#include <atomic>
+
+using namespace nix;
+
+struct CmdOptimiseStore : StoreCommand
+{
+    CmdOptimiseStore()
+    {
+    }
+
+    std::string name() override
+    {
+        return "optimise-store";
+    }
+
+    std::string description() override
+    {
+        return "replace identical files in the store by hard links";
+    }
+
+    Examples examples() override
+    {
+        return {
+            Example{
+                "To optimise the Nix store:",
+                "nix optimise-store"
+            },
+        };
+    }
+
+    void run(ref<Store> store) override
+    {
+        store->optimiseStore();
+    }
+};
+
+static RegisterCommand r1(make_ref<CmdOptimiseStore>());
diff --git a/src/nix/progress-bar.cc b/src/nix/progress-bar.cc
index 6288737088a2..15ef95370a8b 100644
--- a/src/nix/progress-bar.cc
+++ b/src/nix/progress-bar.cc
@@ -210,7 +210,7 @@ public:
 
         std::string res;
 
-        auto renderActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt, double unit) {
+        auto renderActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
             auto & act = state.activitiesByType[type];
             uint64_t done = act.done, expected = act.done, running = 0, failed = act.failed;
             for (auto & j : act.its) {
@@ -242,16 +242,16 @@ public:
             return s;
         };
 
-        auto showActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt, double unit) {
+        auto showActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
             auto s = renderActivity(type, itemFmt, numberFmt, unit);
             if (s.empty()) return;
             if (!res.empty()) res += ", ";
             res += s;
         };
 
-        showActivity(actBuilds, "%s built", "%d", 1);
+        showActivity(actBuilds, "%s built");
 
-        auto s1 = renderActivity(actCopyPaths, "%s copied", "%d", 1);
+        auto s1 = renderActivity(actCopyPaths, "%s copied");
         auto s2 = renderActivity(actCopyPath, "%s MiB", "%.1f", MiB);
 
         if (!s1.empty() || !s2.empty()) {
@@ -262,6 +262,8 @@ public:
 
         showActivity(actDownload, "%s MiB DL", "%.1f", MiB);
 
+        showActivity(actOptimiseStore, "%s paths optimised");
+
         return res;
     }
 };