about summary refs log tree commit diff
path: root/src/nix/installables.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-09-10T13·58+0200
committerEelco Dolstra <edolstra@gmail.com>2017-09-10T20·40+0200
commitad228d84e56aeb1b5f77ae3bd3f8272f00782a8c (patch)
tree00e47bf7501c2c95e3790ac4a28e2abb27051c74 /src/nix/installables.cc
parent3ed8290e5331011609de462bda67857837998583 (diff)
nix build: Only download the requested derivation outputs
Also some refactoring.
Diffstat (limited to 'src/nix/installables.cc')
-rw-r--r--src/nix/installables.cc41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index f3c7d3075fe8..76df05fa32d2 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -240,7 +240,17 @@ static std::vector<std::shared_ptr<Installable>> parseInstallables(
     return result;
 }
 
-Buildables InstallablesCommand::toBuildables(ref<Store> store, RealiseMode mode)
+std::shared_ptr<Installable> parseInstallable(
+    SourceExprCommand & cmd, ref<Store> store, const std::string & installable,
+    bool useDefaultInstallables)
+{
+    auto installables = parseInstallables(cmd, store, {installable}, false);
+    assert(installables.size() == 1);
+    return installables.front();
+}
+
+Buildables toBuildables(ref<Store> store, RealiseMode mode,
+    std::vector<std::shared_ptr<Installable>> installables)
 {
     if (mode != Build)
         settings.readOnlyMode = true;
@@ -251,8 +261,13 @@ Buildables InstallablesCommand::toBuildables(ref<Store> store, RealiseMode mode)
 
     for (auto & i : installables) {
         for (auto & b : i->toBuildables()) {
-            if (b.drvPath != "")
-                pathsToBuild.insert(b.drvPath);
+            if (b.drvPath != "") {
+                StringSet outputNames;
+                for (auto & output : b.outputs)
+                    outputNames.insert(output.first);
+                pathsToBuild.insert(
+                    b.drvPath + "!" + concatStringsSep(",", outputNames));
+            }
             buildables.push_back(std::move(b));
         }
     }
@@ -265,17 +280,29 @@ Buildables InstallablesCommand::toBuildables(ref<Store> store, RealiseMode mode)
     return buildables;
 }
 
-PathSet InstallablesCommand::toStorePaths(ref<Store> store, RealiseMode mode)
+PathSet toStorePaths(ref<Store> store, RealiseMode mode,
+    std::vector<std::shared_ptr<Installable>> installables)
 {
     PathSet outPaths;
 
-    for (auto & b : toBuildables(store, mode))
+    for (auto & b : toBuildables(store, mode, installables))
         for (auto & output : b.outputs)
             outPaths.insert(output.second);
 
     return outPaths;
 }
 
+Path toStorePath(ref<Store> store, RealiseMode mode,
+    std::shared_ptr<Installable> installable)
+{
+    auto paths = toStorePaths(store, mode, {installable});
+
+    if (paths.size() != 1)
+            throw Error("argument '%s' should evaluate to one store path", installable->what());
+
+    return *paths.begin();
+}
+
 void InstallablesCommand::prepare()
 {
     installables = parseInstallables(*this, getStore(), _installables, useDefaultInstallables());
@@ -283,9 +310,7 @@ void InstallablesCommand::prepare()
 
 void InstallableCommand::prepare()
 {
-    auto installables = parseInstallables(*this, getStore(), {_installable}, false);
-    assert(installables.size() == 1);
-    installable = installables.front();
+    installable = parseInstallable(*this, getStore(), _installable, false);
 }
 
 }