aboutsummaryrefslogtreecommitdiff
path: root/src/nix-store/nix-store.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-09-16 22:35:24 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-09-16 22:35:24 +0000
commitf60b380a7f32406659efee282cde4c1330fc1c65 (patch)
tree8bd0680b8fafa02c93b29d0934133b0ff5b29e7a /src/nix-store/nix-store.cc
parentc08c9f08c75bf379439348cccb5b8871a27bf498 (diff)
parent5080d4e7b2525d1656282c65a217a22ff8381df3 (diff)
Merge remote-tracking branch 'upstream/master' into remove-storetype-delegate-regStore
Diffstat (limited to 'src/nix-store/nix-store.cc')
-rw-r--r--src/nix-store/nix-store.cc25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index 3f2594712..b027e84b7 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -64,6 +64,7 @@ static PathSet realisePath(StorePathWithOutputs path, bool build = true)
if (path.path.isDerivation()) {
if (build) store->buildPaths({path});
+ auto outputPaths = store->queryDerivationOutputMap(path.path);
Derivation drv = store->derivationFromPath(path.path);
rootNr++;
@@ -76,7 +77,8 @@ static PathSet realisePath(StorePathWithOutputs path, bool build = true)
if (i == drv.outputs.end())
throw Error("derivation '%s' does not have an output named '%s'",
store2->printStorePath(path.path), j);
- auto outPath = store2->printStorePath(i->second.path(*store, drv.name));
+ auto outPath = outputPaths.at(i->first);
+ auto retPath = store->printStorePath(outPath);
if (store2) {
if (gcRoot == "")
printGCWarning();
@@ -84,10 +86,10 @@ static PathSet realisePath(StorePathWithOutputs path, bool build = true)
Path rootName = gcRoot;
if (rootNr > 1) rootName += "-" + std::to_string(rootNr);
if (i->first != "out") rootName += "-" + i->first;
- outPath = store2->addPermRoot(store->parseStorePath(outPath), rootName);
+ retPath = store2->addPermRoot(outPath, rootName);
}
}
- outputs.insert(outPath);
+ outputs.insert(retPath);
}
return outputs;
}
@@ -217,8 +219,13 @@ static StorePathSet maybeUseOutputs(const StorePath & storePath, bool useOutput,
if (useOutput && storePath.isDerivation()) {
auto drv = store->derivationFromPath(storePath);
StorePathSet outputs;
- for (auto & i : drv.outputsAndPaths(*store))
- outputs.insert(i.second.second);
+ if (forceRealise)
+ return store->queryDerivationOutputs(storePath);
+ for (auto & i : drv.outputsAndOptPaths(*store)) {
+ if (!i.second.second)
+ throw UsageError("Cannot use output path of floating content-addressed derivation until we know what it is (e.g. by building it)");
+ outputs.insert(*i.second.second);
+ }
return outputs;
}
else return {storePath};
@@ -308,11 +315,9 @@ static void opQuery(Strings opFlags, Strings opArgs)
case qOutputs: {
for (auto & i : opArgs) {
- auto i2 = store->followLinksToStorePath(i);
- if (forceRealise) realisePath({i2});
- Derivation drv = store->derivationFromPath(i2);
- for (auto & j : drv.outputsAndPaths(*store))
- cout << fmt("%1%\n", store->printStorePath(j.second.second));
+ auto outputs = maybeUseOutputs(store->followLinksToStorePath(i), true, forceRealise);
+ for (auto & outputPath : outputs)
+ cout << fmt("%1%\n", store->printStorePath(outputPath));
}
break;
}