aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libmain/shared.cc29
-rw-r--r--src/libmain/shared.hh2
-rw-r--r--src/nix-env/nix-env.cc27
-rw-r--r--src/nix-store/nix-store.cc29
4 files changed, 50 insertions, 37 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index 5a8f600e8..fd16dece7 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -4,6 +4,7 @@
#include "globals.hh"
#include "store-api.hh"
#include "util.hh"
+#include "misc.hh"
#include <iostream>
#include <cctype>
@@ -49,6 +50,34 @@ void printGCWarning()
}
+void printMissing(const PathSet & paths)
+{
+ unsigned long long downloadSize;
+ PathSet willBuild, willSubstitute, unknown;
+ queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize);
+
+ if (!willBuild.empty()) {
+ printMsg(lvlInfo, format("the following derivations will be built:"));
+ foreach (PathSet::iterator, i, willBuild)
+ printMsg(lvlInfo, format(" %1%") % *i);
+ }
+
+ if (!willSubstitute.empty()) {
+ printMsg(lvlInfo, format("the following paths will be downloaded/copied (%.2f MiB):") %
+ (downloadSize / (1024.0 * 1024.0)));
+ foreach (PathSet::iterator, i, willSubstitute)
+ printMsg(lvlInfo, format(" %1%") % *i);
+ }
+
+ if (!unknown.empty()) {
+ printMsg(lvlInfo, format("don't know how to build the following paths%1%:")
+ % (readOnlyMode ? " (may be caused by read-only store access)" : ""));
+ foreach (PathSet::iterator, i, unknown)
+ printMsg(lvlInfo, format(" %1%") % *i);
+ }
+}
+
+
static void setLogType(string lt)
{
if (lt == "pretty") logType = ltPretty;
diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh
index 95d80bacd..c432dc5f7 100644
--- a/src/libmain/shared.hh
+++ b/src/libmain/shared.hh
@@ -26,6 +26,8 @@ namespace nix {
Path makeRootName(const Path & gcRoot, int & counter);
void printGCWarning();
+void printMissing(const PathSet & paths);
+
unsigned long long getIntArg(const string & opt,
Strings::iterator & i, const Strings::iterator & end);
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index c3fe2d089..2f2f263f5 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -531,8 +531,8 @@ static void queryInstSources(EvalState & state,
static void printMissing(EvalState & state, const DrvInfos & elems)
{
- PathSet targets, willBuild, willSubstitute, unknown;
- for (DrvInfos::const_iterator i = elems.begin(); i != elems.end(); ++i) {
+ PathSet targets;
+ foreach (DrvInfos::const_iterator, i, elems) {
Path drvPath = i->queryDrvPath(state);
if (drvPath != "")
targets.insert(drvPath);
@@ -540,28 +540,7 @@ static void printMissing(EvalState & state, const DrvInfos & elems)
targets.insert(i->queryOutPath(state));
}
- unsigned long long downloadSize;
- queryMissing(targets, willBuild, willSubstitute, unknown, downloadSize);
-
- if (!willBuild.empty()) {
- printMsg(lvlInfo, format("the following derivations will be built:"));
- foreach (PathSet::iterator, i, willBuild)
- printMsg(lvlInfo, format(" %1%") % *i);
- }
-
- if (!willSubstitute.empty()) {
- printMsg(lvlInfo, format("the following paths will be downloaded/copied (%.2f MiB):") %
- (downloadSize / (1024.0 * 1024.0)));
- foreach (PathSet::iterator, i, willSubstitute)
- printMsg(lvlInfo, format(" %1%") % *i);
- }
-
- if (!unknown.empty()) {
- printMsg(lvlInfo, format("don't know how to build the following paths%1%:")
- % (readOnlyMode ? " (may be caused by read-only store access)" : ""));
- foreach (PathSet::iterator, i, unknown)
- printMsg(lvlInfo, format(" %1%") % *i);
- }
+ printMissing(targets);
}
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index b59ff27bb..0030745b4 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -77,23 +77,26 @@ static Path realisePath(const Path & path)
/* Realise the given paths. */
static void opRealise(Strings opFlags, Strings opArgs)
{
- if (!opFlags.empty()) throw UsageError("unknown flag");
+ bool dryRun = false;
+
+ foreach (Strings::iterator, i, opFlags)
+ if (*i == "--dry-run") dryRun = true;
+ else throw UsageError(format("unknown flag `%1%'") % *i);
- for (Strings::iterator i = opArgs.begin();
- i != opArgs.end(); ++i)
+ foreach (Strings::iterator, i, opArgs)
*i = followLinksToStorePath(*i);
- if (opArgs.size() > 1) {
- PathSet drvPaths;
- for (Strings::iterator i = opArgs.begin();
- i != opArgs.end(); ++i)
- if (isDerivation(*i))
- drvPaths.insert(*i);
- store->buildDerivations(drvPaths);
- }
+ printMissing(PathSet(opArgs.begin(), opArgs.end()));
+
+ if (dryRun) return;
+
+ /* Build all derivations at the same time to exploit parallelism. */
+ PathSet drvPaths;
+ foreach (Strings::iterator, i, opArgs)
+ if (isDerivation(*i)) drvPaths.insert(*i);
+ store->buildDerivations(drvPaths);
- for (Strings::iterator i = opArgs.begin();
- i != opArgs.end(); ++i)
+ foreach (Strings::iterator, i,opArgs)
cout << format("%1%\n") % realisePath(*i);
}