Merge commit '1b6cf0d5f56e166a1cbbf38142375b7a92fc88f2' into ca-drv-exotic

This commit is contained in:
John Ericson 2021-04-05 19:06:43 -04:00
commit d0ed11ca72
36 changed files with 289 additions and 224 deletions

View file

@ -162,7 +162,7 @@ void MixProfile::updateProfile(const StorePath & storePath)
profile2, storePath)); profile2, storePath));
} }
void MixProfile::updateProfile(const Buildables & buildables) void MixProfile::updateProfile(const DerivedPathsWithHints & buildables)
{ {
if (!profile) return; if (!profile) return;
@ -170,10 +170,10 @@ void MixProfile::updateProfile(const Buildables & buildables)
for (auto & buildable : buildables) { for (auto & buildable : buildables) {
std::visit(overloaded { std::visit(overloaded {
[&](BuildableOpaque bo) { [&](DerivedPathWithHints::Opaque bo) {
result.push_back(bo.path); result.push_back(bo.path);
}, },
[&](BuildableFromDrv bfd) { [&](DerivedPathWithHints::Built bfd) {
for (auto & output : bfd.outputs) { for (auto & output : bfd.outputs) {
/* Output path should be known because we just tried to /* Output path should be known because we just tried to
build it. */ build it. */
@ -181,7 +181,7 @@ void MixProfile::updateProfile(const Buildables & buildables)
result.push_back(*output.second); result.push_back(*output.second);
} }
}, },
}, buildable); }, buildable.raw());
} }
if (result.size() != 1) if (result.size() != 1)

View file

@ -216,7 +216,7 @@ static RegisterCommand registerCommand2(std::vector<std::string> && name)
return RegisterCommand(std::move(name), [](){ return make_ref<T>(); }); return RegisterCommand(std::move(name), [](){ return make_ref<T>(); });
} }
Buildables build(ref<Store> store, Realise mode, DerivedPathsWithHints build(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables, BuildMode bMode = bmNormal); std::vector<std::shared_ptr<Installable>> installables, BuildMode bMode = bmNormal);
std::set<StorePath> toStorePaths(ref<Store> store, std::set<StorePath> toStorePaths(ref<Store> store,
@ -252,7 +252,7 @@ struct MixProfile : virtual StoreCommand
/* If 'profile' is set, make it point at the store path produced /* If 'profile' is set, make it point at the store path produced
by 'buildables'. */ by 'buildables'. */
void updateProfile(const Buildables & buildables); void updateProfile(const DerivedPathsWithHints & buildables);
}; };
struct MixDefaultProfile : MixProfile struct MixDefaultProfile : MixProfile

View file

@ -285,9 +285,9 @@ void completeFlakeRef(ref<Store> store, std::string_view prefix)
} }
} }
Buildable Installable::toBuildable() DerivedPathWithHints Installable::toDerivedPathWithHints()
{ {
auto buildables = toBuildables(); auto buildables = toDerivedPathsWithHints();
if (buildables.size() != 1) if (buildables.size() != 1)
throw Error("installable '%s' evaluates to %d derivations, where only one is expected", what(), buildables.size()); throw Error("installable '%s' evaluates to %d derivations, where only one is expected", what(), buildables.size());
return std::move(buildables[0]); return std::move(buildables[0]);
@ -321,7 +321,7 @@ struct InstallableStorePath : Installable
std::string what() override { return store->printStorePath(storePath); } std::string what() override { return store->printStorePath(storePath); }
Buildables toBuildables() override DerivedPathsWithHints toDerivedPathsWithHints() override
{ {
if (storePath.isDerivation()) { if (storePath.isDerivation()) {
std::map<std::string, std::optional<StorePath>> outputs; std::map<std::string, std::optional<StorePath>> outputs;
@ -329,14 +329,14 @@ struct InstallableStorePath : Installable
for (auto & [name, output] : drv.outputsAndOptPaths(*store)) for (auto & [name, output] : drv.outputsAndOptPaths(*store))
outputs.emplace(name, output.second); outputs.emplace(name, output.second);
return { return {
BuildableFromDrv { DerivedPathWithHints::Built {
.drvPath = storePath, .drvPath = storePath,
.outputs = std::move(outputs) .outputs = std::move(outputs)
} }
}; };
} else { } else {
return { return {
BuildableOpaque { DerivedPathWithHints::Opaque {
.path = storePath, .path = storePath,
} }
}; };
@ -349,9 +349,9 @@ struct InstallableStorePath : Installable
} }
}; };
Buildables InstallableValue::toBuildables() DerivedPathsWithHints InstallableValue::toDerivedPathsWithHints()
{ {
Buildables res; DerivedPathsWithHints res;
std::map<StorePath, std::map<std::string, std::optional<StorePath>>> drvsToOutputs; std::map<StorePath, std::map<std::string, std::optional<StorePath>>> drvsToOutputs;
@ -364,7 +364,7 @@ Buildables InstallableValue::toBuildables()
} }
for (auto & i : drvsToOutputs) for (auto & i : drvsToOutputs)
res.push_back(BuildableFromDrv { i.first, i.second }); res.push_back(DerivedPathWithHints::Built { i.first, i.second });
return res; return res;
} }
@ -671,30 +671,30 @@ std::shared_ptr<Installable> SourceExprCommand::parseInstallable(
return installables.front(); return installables.front();
} }
Buildables build(ref<Store> store, Realise mode, DerivedPathsWithHints build(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables, BuildMode bMode) std::vector<std::shared_ptr<Installable>> installables, BuildMode bMode)
{ {
if (mode == Realise::Nothing) if (mode == Realise::Nothing)
settings.readOnlyMode = true; settings.readOnlyMode = true;
Buildables buildables; DerivedPathsWithHints buildables;
std::vector<BuildableReq> pathsToBuild; std::vector<DerivedPath> pathsToBuild;
for (auto & i : installables) { for (auto & i : installables) {
for (auto & b : i->toBuildables()) { for (auto & b : i->toDerivedPathsWithHints()) {
std::visit(overloaded { std::visit(overloaded {
[&](BuildableOpaque bo) { [&](DerivedPathWithHints::Opaque bo) {
pathsToBuild.push_back(bo); pathsToBuild.push_back(bo);
}, },
[&](BuildableFromDrv bfd) { [&](DerivedPathWithHints::Built bfd) {
StringSet outputNames; StringSet outputNames;
for (auto & output : bfd.outputs) for (auto & output : bfd.outputs)
outputNames.insert(output.first); outputNames.insert(output.first);
pathsToBuild.push_back( pathsToBuild.push_back(
BuildableReqFromDrv{bfd.drvPath, outputNames}); DerivedPath::Built{bfd.drvPath, outputNames});
}, },
}, b); }, b.raw());
buildables.push_back(std::move(b)); buildables.push_back(std::move(b));
} }
} }
@ -717,10 +717,10 @@ std::set<RealisedPath> toRealisedPaths(
if (operateOn == OperateOn::Output) { if (operateOn == OperateOn::Output) {
for (auto & b : build(store, mode, installables)) for (auto & b : build(store, mode, installables))
std::visit(overloaded { std::visit(overloaded {
[&](BuildableOpaque bo) { [&](DerivedPathWithHints::Opaque bo) {
res.insert(bo.path); res.insert(bo.path);
}, },
[&](BuildableFromDrv bfd) { [&](DerivedPathWithHints::Built bfd) {
auto drv = store->readDerivation(bfd.drvPath); auto drv = store->readDerivation(bfd.drvPath);
auto outputHashes = staticOutputHashes(*store, drv); auto outputHashes = staticOutputHashes(*store, drv);
for (auto & output : bfd.outputs) { for (auto & output : bfd.outputs) {
@ -745,14 +745,14 @@ std::set<RealisedPath> toRealisedPaths(
} }
} }
}, },
}, b); }, b.raw());
} else { } else {
if (mode == Realise::Nothing) if (mode == Realise::Nothing)
settings.readOnlyMode = true; settings.readOnlyMode = true;
for (auto & i : installables) for (auto & i : installables)
for (auto & b : i->toBuildables()) for (auto & b : i->toDerivedPathsWithHints())
if (auto bfd = std::get_if<BuildableFromDrv>(&b)) if (auto bfd = std::get_if<DerivedPathWithHints::Built>(&b))
res.insert(bfd->drvPath); res.insert(bfd->drvPath);
} }
@ -787,9 +787,9 @@ StorePathSet toDerivations(ref<Store> store,
StorePathSet drvPaths; StorePathSet drvPaths;
for (auto & i : installables) for (auto & i : installables)
for (auto & b : i->toBuildables()) for (auto & b : i->toDerivedPathsWithHints())
std::visit(overloaded { std::visit(overloaded {
[&](BuildableOpaque bo) { [&](DerivedPathWithHints::Opaque bo) {
if (!useDeriver) if (!useDeriver)
throw Error("argument '%s' did not evaluate to a derivation", i->what()); throw Error("argument '%s' did not evaluate to a derivation", i->what());
auto derivers = store->queryValidDerivers(bo.path); auto derivers = store->queryValidDerivers(bo.path);
@ -798,10 +798,10 @@ StorePathSet toDerivations(ref<Store> store,
// FIXME: use all derivers? // FIXME: use all derivers?
drvPaths.insert(*derivers.begin()); drvPaths.insert(*derivers.begin());
}, },
[&](BuildableFromDrv bfd) { [&](DerivedPathWithHints::Built bfd) {
drvPaths.insert(bfd.drvPath); drvPaths.insert(bfd.drvPath);
}, },
}, b); }, b.raw());
return drvPaths; return drvPaths;
} }

View file

@ -3,7 +3,7 @@
#include "util.hh" #include "util.hh"
#include "path.hh" #include "path.hh"
#include "path-with-outputs.hh" #include "path-with-outputs.hh"
#include "buildable.hh" #include "derived-path.hh"
#include "eval.hh" #include "eval.hh"
#include "flake/flake.hh" #include "flake/flake.hh"
@ -29,9 +29,9 @@ struct Installable
virtual std::string what() = 0; virtual std::string what() = 0;
virtual Buildables toBuildables() = 0; virtual DerivedPathsWithHints toDerivedPathsWithHints() = 0;
Buildable toBuildable(); DerivedPathWithHints toDerivedPathWithHints();
App toApp(EvalState & state); App toApp(EvalState & state);
@ -74,7 +74,7 @@ struct InstallableValue : Installable
virtual std::vector<DerivationInfo> toDerivations() = 0; virtual std::vector<DerivationInfo> toDerivations() = 0;
Buildables toBuildables() override; DerivedPathsWithHints toDerivedPathsWithHints() override;
}; };
struct InstallableFlake : InstallableValue struct InstallableFlake : InstallableValue

View file

@ -35,7 +35,7 @@ InvalidPathError::InvalidPathError(const Path & path) :
void EvalState::realiseContext(const PathSet & context) void EvalState::realiseContext(const PathSet & context)
{ {
std::vector<BuildableReqFromDrv> drvs; std::vector<DerivedPath::Built> drvs;
for (auto & i : context) { for (auto & i : context) {
auto [ctxS, outputName] = decodeContext(i); auto [ctxS, outputName] = decodeContext(i);
@ -56,8 +56,8 @@ void EvalState::realiseContext(const PathSet & context)
/* For performance, prefetch all substitute info. */ /* For performance, prefetch all substitute info. */
StorePathSet willBuild, willSubstitute, unknown; StorePathSet willBuild, willSubstitute, unknown;
uint64_t downloadSize, narSize; uint64_t downloadSize, narSize;
std::vector<BuildableReq> buildReqs; std::vector<DerivedPath> buildReqs;
for (auto & d : drvs) buildReqs.emplace_back(BuildableReq { d }); for (auto & d : drvs) buildReqs.emplace_back(DerivedPath { d });
store->queryMissing(buildReqs, willBuild, willSubstitute, unknown, downloadSize, narSize); store->queryMissing(buildReqs, willBuild, willSubstitute, unknown, downloadSize, narSize);
store->buildPaths(buildReqs); store->buildPaths(buildReqs);

View file

@ -36,7 +36,7 @@ void printGCWarning()
} }
void printMissing(ref<Store> store, const std::vector<BuildableReq> & paths, Verbosity lvl) void printMissing(ref<Store> store, const std::vector<DerivedPath> & paths, Verbosity lvl)
{ {
uint64_t downloadSize, narSize; uint64_t downloadSize, narSize;
StorePathSet willBuild, willSubstitute, unknown; StorePathSet willBuild, willSubstitute, unknown;

View file

@ -4,7 +4,7 @@
#include "args.hh" #include "args.hh"
#include "common-args.hh" #include "common-args.hh"
#include "path.hh" #include "path.hh"
#include "buildable.hh" #include "derived-path.hh"
#include <signal.h> #include <signal.h>
@ -43,7 +43,7 @@ struct StorePathWithOutputs;
void printMissing( void printMissing(
ref<Store> store, ref<Store> store,
const std::vector<BuildableReq> & paths, const std::vector<DerivedPath> & paths,
Verbosity lvl = lvlInfo); Verbosity lvl = lvlInfo);
void printMissing(ref<Store> store, const StorePathSet & willBuild, void printMissing(ref<Store> store, const StorePathSet & willBuild,

View file

@ -73,7 +73,7 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath,
state = &DerivationGoal::getDerivation; state = &DerivationGoal::getDerivation;
name = fmt( name = fmt(
"building of '%s' from .drv file", "building of '%s' from .drv file",
BuildableReqFromDrv { drvPath, wantedOutputs }.to_string(worker.store)); DerivedPath::Built { drvPath, wantedOutputs }.to_string(worker.store));
trace("created"); trace("created");
mcExpectedBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.expectedBuilds); mcExpectedBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.expectedBuilds);
@ -94,7 +94,7 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation
state = &DerivationGoal::haveDerivation; state = &DerivationGoal::haveDerivation;
name = fmt( name = fmt(
"building of '%s' from in-memory derivation", "building of '%s' from in-memory derivation",
BuildableReqFromDrv { drvPath, drv.outputNames() }.to_string(worker.store)); DerivedPath::Built { drvPath, drv.outputNames() }.to_string(worker.store));
trace("created"); trace("created");
mcExpectedBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.expectedBuilds); mcExpectedBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.expectedBuilds);

View file

@ -6,17 +6,17 @@
namespace nix { namespace nix {
void Store::buildPaths(const std::vector<BuildableReq> & reqs, BuildMode buildMode) void Store::buildPaths(const std::vector<DerivedPath> & reqs, BuildMode buildMode)
{ {
Worker worker(*this); Worker worker(*this);
Goals goals; Goals goals;
for (auto & br : reqs) { for (auto & br : reqs) {
std::visit(overloaded { std::visit(overloaded {
[&](BuildableReqFromDrv bfd) { [&](DerivedPath::Built bfd) {
goals.insert(worker.makeDerivationGoal(bfd.drvPath, bfd.outputs, buildMode)); goals.insert(worker.makeDerivationGoal(bfd.drvPath, bfd.outputs, buildMode));
}, },
[&](BuildableOpaque bo) { [&](DerivedPath::Opaque bo) {
goals.insert(worker.makePathSubstitutionGoal(bo.path, buildMode == bmRepair ? Repair : NoRepair)); goals.insert(worker.makePathSubstitutionGoal(bo.path, buildMode == bmRepair ? Repair : NoRepair));
}, },
}, br.raw()); }, br.raw());

View file

@ -1191,20 +1191,20 @@ void LocalDerivationGoal::writeStructuredAttrs()
} }
static StorePath pathPartOfReq(const BuildableReq & req) static StorePath pathPartOfReq(const DerivedPath & req)
{ {
return std::visit(overloaded { return std::visit(overloaded {
[&](BuildableOpaque bo) { [&](DerivedPath::Opaque bo) {
return bo.path; return bo.path;
}, },
[&](BuildableReqFromDrv bfd) { [&](DerivedPath::Built bfd) {
return bfd.drvPath; return bfd.drvPath;
}, },
}, req.raw()); }, req.raw());
} }
bool LocalDerivationGoal::isAllowed(const BuildableReq & req) bool LocalDerivationGoal::isAllowed(const DerivedPath & req)
{ {
return this->isAllowed(pathPartOfReq(req)); return this->isAllowed(pathPartOfReq(req));
} }
@ -1332,7 +1332,7 @@ struct RestrictedStore : public virtual RestrictedStoreConfig, public virtual Lo
// an allowed derivation // an allowed derivation
{ throw Error("queryRealisation"); } { throw Error("queryRealisation"); }
void buildPaths(const std::vector<BuildableReq> & paths, BuildMode buildMode) override void buildPaths(const std::vector<DerivedPath> & paths, BuildMode buildMode) override
{ {
if (buildMode != bmNormal) throw Error("unsupported build mode"); if (buildMode != bmNormal) throw Error("unsupported build mode");
@ -1346,7 +1346,7 @@ struct RestrictedStore : public virtual RestrictedStoreConfig, public virtual Lo
next->buildPaths(paths, buildMode); next->buildPaths(paths, buildMode);
for (auto & path : paths) { for (auto & path : paths) {
auto p = std::get_if<BuildableReqFromDrv>(&path); auto p = std::get_if<DerivedPath::Built>(&path);
if (!p) continue; if (!p) continue;
auto & bfd = *p; auto & bfd = *p;
auto outputs = next->queryDerivationOutputMap(bfd.drvPath); auto outputs = next->queryDerivationOutputMap(bfd.drvPath);
@ -1380,7 +1380,7 @@ struct RestrictedStore : public virtual RestrictedStoreConfig, public virtual Lo
void addSignatures(const StorePath & storePath, const StringSet & sigs) override void addSignatures(const StorePath & storePath, const StringSet & sigs) override
{ unsupported("addSignatures"); } { unsupported("addSignatures"); }
void queryMissing(const std::vector<BuildableReq> & targets, void queryMissing(const std::vector<DerivedPath> & targets,
StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown, StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown,
uint64_t & downloadSize, uint64_t & narSize) override uint64_t & downloadSize, uint64_t & narSize) override
{ {
@ -1388,7 +1388,7 @@ struct RestrictedStore : public virtual RestrictedStoreConfig, public virtual Lo
client about what paths will be built/substituted or are client about what paths will be built/substituted or are
already present. Probably not a big deal. */ already present. Probably not a big deal. */
std::vector<BuildableReq> allowed; std::vector<DerivedPath> allowed;
for (auto & req : targets) { for (auto & req : targets) {
if (goal.isAllowed(req)) if (goal.isAllowed(req))
allowed.emplace_back(req); allowed.emplace_back(req);

View file

@ -116,7 +116,7 @@ struct LocalDerivationGoal : public DerivationGoal
{ {
return inputPaths.count(path) || addedPaths.count(path); return inputPaths.count(path) || addedPaths.count(path);
} }
bool isAllowed(const BuildableReq & req); bool isAllowed(const DerivedPath & req);
friend struct RestrictedStore; friend struct RestrictedStore;

View file

@ -226,14 +226,14 @@ void Worker::waitForAWhile(GoalPtr goal)
void Worker::run(const Goals & _topGoals) void Worker::run(const Goals & _topGoals)
{ {
std::vector<nix::BuildableReq> topPaths; std::vector<nix::DerivedPath> topPaths;
for (auto & i : _topGoals) { for (auto & i : _topGoals) {
topGoals.insert(i); topGoals.insert(i);
if (auto goal = dynamic_cast<DerivationGoal *>(i.get())) { if (auto goal = dynamic_cast<DerivationGoal *>(i.get())) {
topPaths.push_back(BuildableReqFromDrv{goal->drvPath, goal->wantedOutputs}); topPaths.push_back(DerivedPath::Built{goal->drvPath, goal->wantedOutputs});
} else if (auto goal = dynamic_cast<PathSubstitutionGoal *>(i.get())) { } else if (auto goal = dynamic_cast<PathSubstitutionGoal *>(i.get())) {
topPaths.push_back(BuildableOpaque{goal->storePath}); topPaths.push_back(DerivedPath::Opaque{goal->storePath});
} }
} }

View file

@ -1,65 +0,0 @@
#pragma once
#include "util.hh"
#include "path.hh"
#include <optional>
#include <variant>
#include <nlohmann/json_fwd.hpp>
namespace nix {
class Store;
struct BuildableOpaque {
StorePath path;
nlohmann::json toJSON(ref<Store> store) const;
std::string to_string(const Store & store) const;
static BuildableOpaque parse(const Store & store, std::string_view);
};
struct BuildableReqFromDrv {
StorePath drvPath;
std::set<std::string> outputs;
std::string to_string(const Store & store) const;
static BuildableReqFromDrv parse(const Store & store, std::string_view);
};
using _BuildableReqRaw = std::variant<
BuildableOpaque,
BuildableReqFromDrv
>;
struct BuildableReq : _BuildableReqRaw {
using Raw = _BuildableReqRaw;
using Raw::Raw;
inline const Raw & raw() const {
return static_cast<const Raw &>(*this);
}
std::string to_string(const Store & store) const;
static BuildableReq parse(const Store & store, std::string_view);
};
struct BuildableFromDrv {
StorePath drvPath;
std::map<std::string, std::optional<StorePath>> outputs;
nlohmann::json toJSON(ref<Store> store) const;
static BuildableFromDrv parse(const Store & store, std::string_view);
};
using Buildable = std::variant<
BuildableOpaque,
BuildableFromDrv
>;
typedef std::vector<Buildable> Buildables;
nlohmann::json buildablesToJSON(const Buildables & buildables, ref<Store> store);
}

View file

@ -260,14 +260,14 @@ static void writeValidPathInfo(
} }
} }
static std::vector<BuildableReq> readBuildableReqs(Store & store, unsigned int clientVersion, Source & from) static std::vector<DerivedPath> readDerivedPaths(Store & store, unsigned int clientVersion, Source & from)
{ {
std::vector<BuildableReq> reqs; std::vector<DerivedPath> reqs;
if (GET_PROTOCOL_MINOR(clientVersion) >= 29) { if (GET_PROTOCOL_MINOR(clientVersion) >= 29) {
reqs = worker_proto::read(store, from, Phantom<std::vector<BuildableReq>> {}); reqs = worker_proto::read(store, from, Phantom<std::vector<DerivedPath>> {});
} else { } else {
for (auto & s : readStrings<Strings>(from)) for (auto & s : readStrings<Strings>(from))
reqs.push_back(parsePathWithOutputs(store, s).toBuildableReq()); reqs.push_back(parsePathWithOutputs(store, s).toDerivedPath());
} }
return reqs; return reqs;
} }
@ -510,7 +510,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
} }
case wopBuildPaths: { case wopBuildPaths: {
auto drvs = readBuildableReqs(*store, clientVersion, from); auto drvs = readDerivedPaths(*store, clientVersion, from);
BuildMode mode = bmNormal; BuildMode mode = bmNormal;
if (GET_PROTOCOL_MINOR(clientVersion) >= 15) { if (GET_PROTOCOL_MINOR(clientVersion) >= 15) {
mode = (BuildMode) readInt(from); mode = (BuildMode) readInt(from);
@ -874,7 +874,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
} }
case wopQueryMissing: { case wopQueryMissing: {
auto targets = readBuildableReqs(*store, clientVersion, from); auto targets = readDerivedPaths(*store, clientVersion, from);
logger->startWork(); logger->startWork();
StorePathSet willBuild, willSubstitute, unknown; StorePathSet willBuild, willSubstitute, unknown;
uint64_t downloadSize, narSize; uint64_t downloadSize, narSize;

View file

@ -1,17 +1,17 @@
#include "buildable.hh" #include "derived-path.hh"
#include "store-api.hh" #include "store-api.hh"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
namespace nix { namespace nix {
nlohmann::json BuildableOpaque::toJSON(ref<Store> store) const { nlohmann::json DerivedPath::Opaque::toJSON(ref<Store> store) const {
nlohmann::json res; nlohmann::json res;
res["path"] = store->printStorePath(path); res["path"] = store->printStorePath(path);
return res; return res;
} }
nlohmann::json BuildableFromDrv::toJSON(ref<Store> store) const { nlohmann::json DerivedPathWithHints::Built::toJSON(ref<Store> store) const {
nlohmann::json res; nlohmann::json res;
res["drvPath"] = store->printStorePath(drvPath); res["drvPath"] = store->printStorePath(drvPath);
for (const auto& [output, path] : outputs) { for (const auto& [output, path] : outputs) {
@ -20,28 +20,28 @@ nlohmann::json BuildableFromDrv::toJSON(ref<Store> store) const {
return res; return res;
} }
nlohmann::json buildablesToJSON(const Buildables & buildables, ref<Store> store) { nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildables, ref<Store> store) {
auto res = nlohmann::json::array(); auto res = nlohmann::json::array();
for (const Buildable & buildable : buildables) { for (const DerivedPathWithHints & buildable : buildables) {
std::visit([&res, store](const auto & buildable) { std::visit([&res, store](const auto & buildable) {
res.push_back(buildable.toJSON(store)); res.push_back(buildable.toJSON(store));
}, buildable); }, buildable.raw());
} }
return res; return res;
} }
std::string BuildableOpaque::to_string(const Store & store) const { std::string DerivedPath::Opaque::to_string(const Store & store) const {
return store.printStorePath(path); return store.printStorePath(path);
} }
std::string BuildableReqFromDrv::to_string(const Store & store) const { std::string DerivedPath::Built::to_string(const Store & store) const {
return store.printStorePath(drvPath) return store.printStorePath(drvPath)
+ "!" + "!"
+ (outputs.empty() ? std::string { "*" } : concatStringsSep(",", outputs)); + (outputs.empty() ? std::string { "*" } : concatStringsSep(",", outputs));
} }
std::string BuildableReq::to_string(const Store & store) const std::string DerivedPath::to_string(const Store & store) const
{ {
return std::visit( return std::visit(
[&](const auto & req) { return req.to_string(store); }, [&](const auto & req) { return req.to_string(store); },
@ -49,12 +49,12 @@ std::string BuildableReq::to_string(const Store & store) const
} }
BuildableOpaque BuildableOpaque::parse(const Store & store, std::string_view s) DerivedPath::Opaque DerivedPath::Opaque::parse(const Store & store, std::string_view s)
{ {
return {store.parseStorePath(s)}; return {store.parseStorePath(s)};
} }
BuildableReqFromDrv BuildableReqFromDrv::parse(const Store & store, std::string_view s) DerivedPath::Built DerivedPath::Built::parse(const Store & store, std::string_view s)
{ {
size_t n = s.find("!"); size_t n = s.find("!");
assert(n != s.npos); assert(n != s.npos);
@ -66,12 +66,12 @@ BuildableReqFromDrv BuildableReqFromDrv::parse(const Store & store, std::string_
return {drvPath, outputs}; return {drvPath, outputs};
} }
BuildableReq BuildableReq::parse(const Store & store, std::string_view s) DerivedPath DerivedPath::parse(const Store & store, std::string_view s)
{ {
size_t n = s.find("!"); size_t n = s.find("!");
return n == s.npos return n == s.npos
? (BuildableReq) BuildableOpaque::parse(store, s) ? (DerivedPath) DerivedPath::Opaque::parse(store, s)
: (BuildableReq) BuildableReqFromDrv::parse(store, s); : (DerivedPath) DerivedPath::Built::parse(store, s);
} }
} }

View file

@ -0,0 +1,130 @@
#pragma once
#include "util.hh"
#include "path.hh"
#include <optional>
#include <variant>
#include <nlohmann/json_fwd.hpp>
namespace nix {
class Store;
/**
* An opaque derived path.
*
* Opaque derived paths are just store paths, and fully evaluated. They
* cannot be simplified further. Since they are opaque, they cannot be
* built, but they can fetched.
*/
struct DerivedPathOpaque {
StorePath path;
nlohmann::json toJSON(ref<Store> store) const;
std::string to_string(const Store & store) const;
static DerivedPathOpaque parse(const Store & store, std::string_view);
};
/**
* A derived path that is built from a derivation
*
* Built derived paths are pair of a derivation and some output names.
* They are evaluated by building the derivation, and then replacing the
* output names with the resulting outputs.
*
* Note that does mean a derived store paths evaluates to multiple
* opaque paths, which is sort of icky as expressions are supposed to
* evaluate to single values. Perhaps this should have just a single
* output name.
*/
struct DerivedPathBuilt {
StorePath drvPath;
std::set<std::string> outputs;
std::string to_string(const Store & store) const;
static DerivedPathBuilt parse(const Store & store, std::string_view);
};
using _DerivedPathRaw = std::variant<
DerivedPathOpaque,
DerivedPathBuilt
>;
/**
* A "derived path" is a very simple sort of expression that evaluates
* to (concrete) store path. It is either:
*
* - opaque, in which case it is just a concrete store path with
* possibly no known derivation
*
* - built, in which case it is a pair of a derivation path and an
* output name.
*/
struct DerivedPath : _DerivedPathRaw {
using Raw = _DerivedPathRaw;
using Raw::Raw;
using Opaque = DerivedPathOpaque;
using Built = DerivedPathBuilt;
inline const Raw & raw() const {
return static_cast<const Raw &>(*this);
}
std::string to_string(const Store & store) const;
static DerivedPath parse(const Store & store, std::string_view);
};
/**
* A built derived path with hints in the form of optional concrete output paths.
*
* See 'DerivedPathWithHints' for more an explanation.
*/
struct DerivedPathWithHintsBuilt {
StorePath drvPath;
std::map<std::string, std::optional<StorePath>> outputs;
nlohmann::json toJSON(ref<Store> store) const;
static DerivedPathWithHintsBuilt parse(const Store & store, std::string_view);
};
using _DerivedPathWithHintsRaw = std::variant<
DerivedPath::Opaque,
DerivedPathWithHintsBuilt
>;
/**
* A derived path with hints in the form of optional concrete output paths in the built case.
*
* This type is currently just used by the CLI. The paths are filled in
* during evaluation for derivations that know what paths they will
* produce in advanced, i.e. input-addressed or fixed-output content
* addressed derivations.
*
* That isn't very good, because it puts floating content-addressed
* derivations "at a disadvantage". It would be better to never rely on
* the output path of unbuilt derivations, and exclusively use the
* realizations types to work with built derivations' concrete output
* paths.
*/
// FIXME Stop using and delete this, or if that is not possible move out of libstore to libcmd.
struct DerivedPathWithHints : _DerivedPathWithHintsRaw {
using Raw = _DerivedPathWithHintsRaw;
using Raw::Raw;
using Opaque = DerivedPathOpaque;
using Built = DerivedPathWithHintsBuilt;
inline const Raw & raw() const {
return static_cast<const Raw &>(*this);
}
};
typedef std::vector<DerivedPathWithHints> DerivedPathsWithHints;
nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildables, ref<Store> store);
}

View file

@ -266,14 +266,14 @@ public:
return status; return status;
} }
void buildPaths(const std::vector<BuildableReq> & drvPaths, BuildMode buildMode) override void buildPaths(const std::vector<DerivedPath> & drvPaths, BuildMode buildMode) override
{ {
auto conn(connections->get()); auto conn(connections->get());
conn->to << cmdBuildPaths; conn->to << cmdBuildPaths;
Strings ss; Strings ss;
for (auto & p : drvPaths) { for (auto & p : drvPaths) {
auto sOrDrvPath = StorePathWithOutputs::tryFromBuildableReq(p); auto sOrDrvPath = StorePathWithOutputs::tryFromDerivedPath(p);
std::visit(overloaded { std::visit(overloaded {
[&](StorePathWithOutputs s) { [&](StorePathWithOutputs s) {
ss.push_back(s.to_string(*this)); ss.push_back(s.to_string(*this));

View file

@ -128,7 +128,7 @@ std::optional<ContentAddress> getDerivationCA(const BasicDerivation & drv)
return std::nullopt; return std::nullopt;
} }
void Store::queryMissing(const std::vector<BuildableReq> & targets, void Store::queryMissing(const std::vector<DerivedPath> & targets,
StorePathSet & willBuild_, StorePathSet & willSubstitute_, StorePathSet & unknown_, StorePathSet & willBuild_, StorePathSet & willSubstitute_, StorePathSet & unknown_,
uint64_t & downloadSize_, uint64_t & narSize_) uint64_t & downloadSize_, uint64_t & narSize_)
{ {
@ -156,7 +156,7 @@ void Store::queryMissing(const std::vector<BuildableReq> & targets,
Sync<State> state_(State{{}, unknown_, willSubstitute_, willBuild_, downloadSize_, narSize_}); Sync<State> state_(State{{}, unknown_, willSubstitute_, willBuild_, downloadSize_, narSize_});
std::function<void(BuildableReq)> doPath; std::function<void(DerivedPath)> doPath;
auto mustBuildDrv = [&](const StorePath & drvPath, const Derivation & drv) { auto mustBuildDrv = [&](const StorePath & drvPath, const Derivation & drv) {
{ {
@ -165,7 +165,7 @@ void Store::queryMissing(const std::vector<BuildableReq> & targets,
} }
for (auto & i : drv.inputDrvs) for (auto & i : drv.inputDrvs)
pool.enqueue(std::bind(doPath, BuildableReqFromDrv { i.first, i.second })); pool.enqueue(std::bind(doPath, DerivedPath::Built { i.first, i.second }));
}; };
auto checkOutput = [&]( auto checkOutput = [&](
@ -188,13 +188,13 @@ void Store::queryMissing(const std::vector<BuildableReq> & targets,
drvState->outPaths.insert(outPath); drvState->outPaths.insert(outPath);
if (!drvState->left) { if (!drvState->left) {
for (auto & path : drvState->outPaths) for (auto & path : drvState->outPaths)
pool.enqueue(std::bind(doPath, BuildableOpaque { path } )); pool.enqueue(std::bind(doPath, DerivedPath::Opaque { path } ));
} }
} }
} }
}; };
doPath = [&](const BuildableReq & req) { doPath = [&](const DerivedPath & req) {
{ {
auto state(state_.lock()); auto state(state_.lock());
@ -202,7 +202,7 @@ void Store::queryMissing(const std::vector<BuildableReq> & targets,
} }
std::visit(overloaded { std::visit(overloaded {
[&](BuildableReqFromDrv bfd) { [&](DerivedPath::Built bfd) {
if (!isValidPath(bfd.drvPath)) { if (!isValidPath(bfd.drvPath)) {
// FIXME: we could try to substitute the derivation. // FIXME: we could try to substitute the derivation.
auto state(state_.lock()); auto state(state_.lock());
@ -235,7 +235,7 @@ void Store::queryMissing(const std::vector<BuildableReq> & targets,
mustBuildDrv(bfd.drvPath, *drv); mustBuildDrv(bfd.drvPath, *drv);
}, },
[&](BuildableOpaque bo) { [&](DerivedPath::Opaque bo) {
if (isValidPath(bo.path)) return; if (isValidPath(bo.path)) return;
@ -259,7 +259,7 @@ void Store::queryMissing(const std::vector<BuildableReq> & targets,
} }
for (auto & ref : info->second.references) for (auto & ref : info->second.references)
pool.enqueue(std::bind(doPath, BuildableOpaque { ref })); pool.enqueue(std::bind(doPath, DerivedPath::Opaque { ref }));
}, },
}, req.raw()); }, req.raw());
}; };

View file

@ -11,34 +11,34 @@ std::string StorePathWithOutputs::to_string(const Store & store) const
} }
BuildableReq StorePathWithOutputs::toBuildableReq() const DerivedPath StorePathWithOutputs::toDerivedPath() const
{ {
if (!outputs.empty() || path.isDerivation()) if (!outputs.empty() || path.isDerivation())
return BuildableReqFromDrv { path, outputs }; return DerivedPath::Built { path, outputs };
else else
return BuildableOpaque { path }; return DerivedPath::Opaque { path };
} }
std::vector<BuildableReq> toBuildableReqs(const std::vector<StorePathWithOutputs> ss) std::vector<DerivedPath> toDerivedPaths(const std::vector<StorePathWithOutputs> ss)
{ {
std::vector<BuildableReq> reqs; std::vector<DerivedPath> reqs;
for (auto & s : ss) reqs.push_back(s.toBuildableReq()); for (auto & s : ss) reqs.push_back(s.toDerivedPath());
return reqs; return reqs;
} }
std::variant<StorePathWithOutputs, StorePath> StorePathWithOutputs::tryFromBuildableReq(const BuildableReq & p) std::variant<StorePathWithOutputs, StorePath> StorePathWithOutputs::tryFromDerivedPath(const DerivedPath & p)
{ {
return std::visit(overloaded { return std::visit(overloaded {
[&](BuildableOpaque bo) -> std::variant<StorePathWithOutputs, StorePath> { [&](DerivedPath::Opaque bo) -> std::variant<StorePathWithOutputs, StorePath> {
if (bo.path.isDerivation()) { if (bo.path.isDerivation()) {
// drv path gets interpreted as "build", not "get drv file itself" // drv path gets interpreted as "build", not "get drv file itself"
return bo.path; return bo.path;
} }
return StorePathWithOutputs { bo.path }; return StorePathWithOutputs { bo.path };
}, },
[&](BuildableReqFromDrv bfd) -> std::variant<StorePathWithOutputs, StorePath> { [&](DerivedPath::Built bfd) -> std::variant<StorePathWithOutputs, StorePath> {
return StorePathWithOutputs { bfd.drvPath, bfd.outputs }; return StorePathWithOutputs { bfd.drvPath, bfd.outputs };
}, },
}, p.raw()); }, p.raw());

View file

@ -3,7 +3,7 @@
#include <variant> #include <variant>
#include "path.hh" #include "path.hh"
#include "buildable.hh" #include "derived-path.hh"
namespace nix { namespace nix {
@ -14,12 +14,12 @@ struct StorePathWithOutputs
std::string to_string(const Store & store) const; std::string to_string(const Store & store) const;
BuildableReq toBuildableReq() const; DerivedPath toDerivedPath() const;
static std::variant<StorePathWithOutputs, StorePath> tryFromBuildableReq(const BuildableReq &); static std::variant<StorePathWithOutputs, StorePath> tryFromDerivedPath(const DerivedPath &);
}; };
std::vector<BuildableReq> toBuildableReqs(const std::vector<StorePathWithOutputs>); std::vector<DerivedPath> toDerivedPaths(const std::vector<StorePathWithOutputs>);
std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s); std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s);

View file

@ -52,13 +52,13 @@ void write(const Store & store, Sink & out, const ContentAddress & ca)
} }
BuildableReq read(const Store & store, Source & from, Phantom<BuildableReq> _) DerivedPath read(const Store & store, Source & from, Phantom<DerivedPath> _)
{ {
auto s = readString(from); auto s = readString(from);
return BuildableReq::parse(store, s); return DerivedPath::parse(store, s);
} }
void write(const Store & store, Sink & out, const BuildableReq & req) void write(const Store & store, Sink & out, const DerivedPath & req)
{ {
out << req.to_string(store); out << req.to_string(store);
} }
@ -675,14 +675,14 @@ std::optional<const Realisation> RemoteStore::queryRealisation(const DrvOutput &
return {Realisation{.id = id, .outPath = *outPaths.begin()}}; return {Realisation{.id = id, .outPath = *outPaths.begin()}};
} }
static void writeBuildableReqs(RemoteStore & store, ConnectionHandle & conn, const std::vector<BuildableReq> & reqs) static void writeDerivedPaths(RemoteStore & store, ConnectionHandle & conn, const std::vector<DerivedPath> & reqs)
{ {
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 29) { if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 29) {
worker_proto::write(store, conn->to, reqs); worker_proto::write(store, conn->to, reqs);
} else { } else {
Strings ss; Strings ss;
for (auto & p : reqs) { for (auto & p : reqs) {
auto sOrDrvPath = StorePathWithOutputs::tryFromBuildableReq(p); auto sOrDrvPath = StorePathWithOutputs::tryFromDerivedPath(p);
std::visit(overloaded { std::visit(overloaded {
[&](StorePathWithOutputs s) { [&](StorePathWithOutputs s) {
ss.push_back(s.to_string(store)); ss.push_back(s.to_string(store));
@ -699,12 +699,12 @@ static void writeBuildableReqs(RemoteStore & store, ConnectionHandle & conn, con
} }
} }
void RemoteStore::buildPaths(const std::vector<BuildableReq> & drvPaths, BuildMode buildMode) void RemoteStore::buildPaths(const std::vector<DerivedPath> & drvPaths, BuildMode buildMode)
{ {
auto conn(getConnection()); auto conn(getConnection());
conn->to << wopBuildPaths; conn->to << wopBuildPaths;
assert(GET_PROTOCOL_MINOR(conn->daemonVersion) >= 13); assert(GET_PROTOCOL_MINOR(conn->daemonVersion) >= 13);
writeBuildableReqs(*this, conn, drvPaths); writeDerivedPaths(*this, conn, drvPaths);
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 15) if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 15)
conn->to << buildMode; conn->to << buildMode;
else else
@ -843,7 +843,7 @@ void RemoteStore::addSignatures(const StorePath & storePath, const StringSet & s
} }
void RemoteStore::queryMissing(const std::vector<BuildableReq> & targets, void RemoteStore::queryMissing(const std::vector<DerivedPath> & targets,
StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown, StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown,
uint64_t & downloadSize, uint64_t & narSize) uint64_t & downloadSize, uint64_t & narSize)
{ {
@ -854,7 +854,7 @@ void RemoteStore::queryMissing(const std::vector<BuildableReq> & targets,
// to prevent a deadlock. // to prevent a deadlock.
goto fallback; goto fallback;
conn->to << wopQueryMissing; conn->to << wopQueryMissing;
writeBuildableReqs(*this, conn, targets); writeDerivedPaths(*this, conn, targets);
conn.processStderr(); conn.processStderr();
willBuild = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {}); willBuild = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});
willSubstitute = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {}); willSubstitute = worker_proto::read(*this, conn->from, Phantom<StorePathSet> {});

View file

@ -86,7 +86,7 @@ public:
std::optional<const Realisation> queryRealisation(const DrvOutput &) override; std::optional<const Realisation> queryRealisation(const DrvOutput &) override;
void buildPaths(const std::vector<BuildableReq> & paths, BuildMode buildMode) override; void buildPaths(const std::vector<DerivedPath> & paths, BuildMode buildMode) override;
BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv, BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
BuildMode buildMode) override; BuildMode buildMode) override;
@ -109,7 +109,7 @@ public:
void addSignatures(const StorePath & storePath, const StringSet & sigs) override; void addSignatures(const StorePath & storePath, const StringSet & sigs) override;
void queryMissing(const std::vector<BuildableReq> & targets, void queryMissing(const std::vector<DerivedPath> & targets,
StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown, StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown,
uint64_t & downloadSize, uint64_t & narSize) override; uint64_t & downloadSize, uint64_t & narSize) override;

View file

@ -545,10 +545,10 @@ void Store::queryPathInfo(const StorePath & storePath,
void Store::substitutePaths(const StorePathSet & paths) void Store::substitutePaths(const StorePathSet & paths)
{ {
std::vector<BuildableReq> paths2; std::vector<DerivedPath> paths2;
for (auto & path : paths) for (auto & path : paths)
if (!path.isDerivation()) if (!path.isDerivation())
paths2.push_back(BuildableOpaque{path}); paths2.push_back(DerivedPath::Opaque{path});
uint64_t downloadSize, narSize; uint64_t downloadSize, narSize;
StorePathSet willBuild, willSubstitute, unknown; StorePathSet willBuild, willSubstitute, unknown;
queryMissing(paths2, queryMissing(paths2,
@ -556,8 +556,8 @@ void Store::substitutePaths(const StorePathSet & paths)
if (!willSubstitute.empty()) if (!willSubstitute.empty())
try { try {
std::vector<BuildableReq> subs; std::vector<DerivedPath> subs;
for (auto & p : willSubstitute) subs.push_back(BuildableOpaque{p}); for (auto & p : willSubstitute) subs.push_back(DerivedPath::Opaque{p});
buildPaths(subs); buildPaths(subs);
} catch (Error & e) { } catch (Error & e) {
logWarning(e.info()); logWarning(e.info());

View file

@ -2,7 +2,7 @@
#include "realisation.hh" #include "realisation.hh"
#include "path.hh" #include "path.hh"
#include "buildable.hh" #include "derived-path.hh"
#include "hash.hh" #include "hash.hh"
#include "content-address.hh" #include "content-address.hh"
#include "serialise.hh" #include "serialise.hh"
@ -490,7 +490,7 @@ public:
recursively building any sub-derivations. For inputs that are recursively building any sub-derivations. For inputs that are
not derivations, substitute them. */ not derivations, substitute them. */
virtual void buildPaths( virtual void buildPaths(
const std::vector<BuildableReq> & paths, const std::vector<DerivedPath> & paths,
BuildMode buildMode = bmNormal); BuildMode buildMode = bmNormal);
/* Build a single non-materialized derivation (i.e. not from an /* Build a single non-materialized derivation (i.e. not from an
@ -652,7 +652,7 @@ public:
/* Given a set of paths that are to be built, return the set of /* Given a set of paths that are to be built, return the set of
derivations that will be built, and the set of output paths derivations that will be built, and the set of output paths
that will be substituted. */ that will be substituted. */
virtual void queryMissing(const std::vector<BuildableReq> & targets, virtual void queryMissing(const std::vector<DerivedPath> & targets,
StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown, StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown,
uint64_t & downloadSize, uint64_t & narSize); uint64_t & downloadSize, uint64_t & narSize);

View file

@ -86,7 +86,7 @@ namespace worker_proto {
MAKE_WORKER_PROTO(, std::string); MAKE_WORKER_PROTO(, std::string);
MAKE_WORKER_PROTO(, StorePath); MAKE_WORKER_PROTO(, StorePath);
MAKE_WORKER_PROTO(, ContentAddress); MAKE_WORKER_PROTO(, ContentAddress);
MAKE_WORKER_PROTO(, BuildableReq); MAKE_WORKER_PROTO(, DerivedPath);
MAKE_WORKER_PROTO(, Realisation); MAKE_WORKER_PROTO(, Realisation);
MAKE_WORKER_PROTO(, DrvOutput); MAKE_WORKER_PROTO(, DrvOutput);

View file

@ -323,7 +323,7 @@ static void main_nix_build(int argc, char * * argv)
state->printStats(); state->printStats();
auto buildPaths = [&](const std::vector<StorePathWithOutputs> & paths0) { auto buildPaths = [&](const std::vector<StorePathWithOutputs> & paths0) {
auto paths = toBuildableReqs(paths0); auto paths = toDerivedPaths(paths0);
/* Note: we do this even when !printMissing to efficiently /* Note: we do this even when !printMissing to efficiently
fetch binary cache data. */ fetch binary cache data. */
uint64_t downloadSize, narSize; uint64_t downloadSize, narSize;

View file

@ -419,13 +419,13 @@ static void queryInstSources(EvalState & state,
static void printMissing(EvalState & state, DrvInfos & elems) static void printMissing(EvalState & state, DrvInfos & elems)
{ {
std::vector<BuildableReq> targets; std::vector<DerivedPath> targets;
for (auto & i : elems) { for (auto & i : elems) {
Path drvPath = i.queryDrvPath(); Path drvPath = i.queryDrvPath();
if (drvPath != "") if (drvPath != "")
targets.push_back(BuildableReqFromDrv{state.store->parseStorePath(drvPath)}); targets.push_back(DerivedPath::Built{state.store->parseStorePath(drvPath)});
else else
targets.push_back(BuildableOpaque{state.store->parseStorePath(i.queryOutPath())}); targets.push_back(DerivedPath::Opaque{state.store->parseStorePath(i.queryOutPath())});
} }
printMissing(state.store, targets); printMissing(state.store, targets);
@ -694,12 +694,12 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs)
if (globals.forceName != "") if (globals.forceName != "")
drv.setName(globals.forceName); drv.setName(globals.forceName);
std::vector<BuildableReq> paths { std::vector<DerivedPath> paths {
(drv.queryDrvPath() != "") (drv.queryDrvPath() != "")
? (BuildableReq) (BuildableReqFromDrv { ? (DerivedPath) (DerivedPath::Built {
globals.state->store->parseStorePath(drv.queryDrvPath()) globals.state->store->parseStorePath(drv.queryDrvPath())
}) })
: (BuildableReq) (BuildableOpaque { : (DerivedPath) (DerivedPath::Opaque {
globals.state->store->parseStorePath(drv.queryOutPath()) globals.state->store->parseStorePath(drv.queryOutPath())
}), }),
}; };

View file

@ -43,7 +43,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
debug(format("building user environment dependencies")); debug(format("building user environment dependencies"));
state.store->buildPaths( state.store->buildPaths(
toBuildableReqs(drvsToBuild), toDerivedPaths(drvsToBuild),
state.repair ? bmRepair : bmNormal); state.repair ? bmRepair : bmNormal);
/* Construct the whole top level derivation. */ /* Construct the whole top level derivation. */
@ -140,7 +140,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
std::vector<StorePathWithOutputs> topLevelDrvs; std::vector<StorePathWithOutputs> topLevelDrvs;
topLevelDrvs.push_back({topLevelDrv}); topLevelDrvs.push_back({topLevelDrv});
state.store->buildPaths( state.store->buildPaths(
toBuildableReqs(topLevelDrvs), toDerivedPaths(topLevelDrvs),
state.repair ? bmRepair : bmNormal); state.repair ? bmRepair : bmNormal);
/* Switch the current user environment to the output path. */ /* Switch the current user environment to the output path. */

View file

@ -63,7 +63,7 @@ static PathSet realisePath(StorePathWithOutputs path, bool build = true)
auto store2 = std::dynamic_pointer_cast<LocalFSStore>(store); auto store2 = std::dynamic_pointer_cast<LocalFSStore>(store);
if (path.path.isDerivation()) { if (path.path.isDerivation()) {
if (build) store->buildPaths({path.toBuildableReq()}); if (build) store->buildPaths({path.toDerivedPath()});
auto outputPaths = store->queryDerivationOutputMap(path.path); auto outputPaths = store->queryDerivationOutputMap(path.path);
Derivation drv = store->derivationFromPath(path.path); Derivation drv = store->derivationFromPath(path.path);
rootNr++; rootNr++;
@ -134,7 +134,7 @@ static void opRealise(Strings opFlags, Strings opArgs)
uint64_t downloadSize, narSize; uint64_t downloadSize, narSize;
StorePathSet willBuild, willSubstitute, unknown; StorePathSet willBuild, willSubstitute, unknown;
store->queryMissing( store->queryMissing(
toBuildableReqs(paths), toDerivedPaths(paths),
willBuild, willSubstitute, unknown, downloadSize, narSize); willBuild, willSubstitute, unknown, downloadSize, narSize);
if (ignoreUnknown) { if (ignoreUnknown) {
@ -151,7 +151,7 @@ static void opRealise(Strings opFlags, Strings opArgs)
if (dryRun) return; if (dryRun) return;
/* Build all paths at the same time to exploit parallelism. */ /* Build all paths at the same time to exploit parallelism. */
store->buildPaths(toBuildableReqs(paths), buildMode); store->buildPaths(toDerivedPaths(paths), buildMode);
if (!ignoreUnknown) if (!ignoreUnknown)
for (auto & i : paths) { for (auto & i : paths) {
@ -888,7 +888,7 @@ static void opServe(Strings opFlags, Strings opArgs)
try { try {
MonitorFdHup monitor(in.fd); MonitorFdHup monitor(in.fd);
store->buildPaths(toBuildableReqs(paths)); store->buildPaths(toDerivedPaths(paths));
out << 0; out << 0;
} catch (Error & e) { } catch (Error & e) {
assert(e.status); assert(e.status);

View file

@ -61,12 +61,12 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
for (const auto & [_i, buildable] : enumerate(buildables)) { for (const auto & [_i, buildable] : enumerate(buildables)) {
auto i = _i; auto i = _i;
std::visit(overloaded { std::visit(overloaded {
[&](BuildableOpaque bo) { [&](DerivedPathWithHints::Opaque bo) {
std::string symlink = outLink; std::string symlink = outLink;
if (i) symlink += fmt("-%d", i); if (i) symlink += fmt("-%d", i);
store2->addPermRoot(bo.path, absPath(symlink)); store2->addPermRoot(bo.path, absPath(symlink));
}, },
[&](BuildableFromDrv bfd) { [&](DerivedPathWithHints::Built bfd) {
auto builtOutputs = store->queryDerivationOutputMap(bfd.drvPath); auto builtOutputs = store->queryDerivationOutputMap(bfd.drvPath);
for (auto & output : builtOutputs) { for (auto & output : builtOutputs) {
std::string symlink = outLink; std::string symlink = outLink;
@ -75,12 +75,12 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
store2->addPermRoot(output.second, absPath(symlink)); store2->addPermRoot(output.second, absPath(symlink));
} }
}, },
}, buildable); }, buildable.raw());
} }
updateProfile(buildables); updateProfile(buildables);
if (json) logger->cout("%s", buildablesToJSON(buildables, store).dump()); if (json) logger->cout("%s", derivedPathsWithHintsToJSON(buildables, store).dump());
} }
}; };

View file

@ -70,7 +70,7 @@ struct CmdBundle : InstallableCommand
auto evalState = getEvalState(); auto evalState = getEvalState();
auto app = installable->toApp(*evalState); auto app = installable->toApp(*evalState);
store->buildPaths(toBuildableReqs(app.context)); store->buildPaths(toDerivedPaths(app.context));
auto [bundlerFlakeRef, bundlerName] = parseFlakeRefWithFragment(bundler, absPath(".")); auto [bundlerFlakeRef, bundlerName] = parseFlakeRefWithFragment(bundler, absPath("."));
const flake::LockFlags lockFlags{ .writeLockFile = false }; const flake::LockFlags lockFlags{ .writeLockFile = false };
@ -110,7 +110,7 @@ struct CmdBundle : InstallableCommand
StorePath outPath = store->parseStorePath(evalState->coerceToPath(*attr2->pos, *attr2->value, context2)); StorePath outPath = store->parseStorePath(evalState->coerceToPath(*attr2->pos, *attr2->value, context2));
store->buildPaths({ BuildableReqFromDrv { drvPath } }); store->buildPaths({ DerivedPath::Built { drvPath } });
auto outPathS = store->printStorePath(outPath); auto outPathS = store->printStorePath(outPath);

View file

@ -160,7 +160,7 @@ StorePath getDerivationEnvironment(ref<Store> store, const StorePath & drvPath)
auto shellDrvPath = writeDerivation(*store, drv); auto shellDrvPath = writeDerivation(*store, drv);
/* Build the derivation. */ /* Build the derivation. */
store->buildPaths({BuildableReqFromDrv{shellDrvPath}}); store->buildPaths({DerivedPath::Built{shellDrvPath}});
for (auto & [_0, outputAndOptPath] : drv.outputsAndOptPaths(*store)) { for (auto & [_0, outputAndOptPath] : drv.outputsAndOptPaths(*store)) {
auto & [_1, optPath] = outputAndOptPath; auto & [_1, optPath] = outputAndOptPath;
@ -265,7 +265,7 @@ struct Common : InstallableCommand, MixProfile
for (auto & [installable_, dir_] : redirects) { for (auto & [installable_, dir_] : redirects) {
auto dir = absPath(dir_); auto dir = absPath(dir_);
auto installable = parseInstallable(store, installable_); auto installable = parseInstallable(store, installable_);
auto buildable = installable->toBuildable(); auto buildable = installable->toDerivedPathWithHints();
auto doRedirect = [&](const StorePath & path) auto doRedirect = [&](const StorePath & path)
{ {
auto from = store->printStorePath(path); auto from = store->printStorePath(path);
@ -277,14 +277,14 @@ struct Common : InstallableCommand, MixProfile
} }
}; };
std::visit(overloaded { std::visit(overloaded {
[&](const BuildableOpaque & bo) { [&](const DerivedPathWithHints::Opaque & bo) {
doRedirect(bo.path); doRedirect(bo.path);
}, },
[&](const BuildableFromDrv & bfd) { [&](const DerivedPathWithHints::Built & bfd) {
for (auto & [outputName, path] : bfd.outputs) for (auto & [outputName, path] : bfd.outputs)
if (path) doRedirect(*path); if (path) doRedirect(*path);
}, },
}, buildable); }, buildable.raw());
} }
return rewriteStrings(script, rewrites); return rewriteStrings(script, rewrites);

View file

@ -293,7 +293,7 @@ struct CmdFlakeCheck : FlakeCommand
} }
}; };
std::vector<BuildableReq> drvPaths; std::vector<DerivedPath> drvPaths;
auto checkApp = [&](const std::string & attrPath, Value & v, const Pos & pos) { auto checkApp = [&](const std::string & attrPath, Value & v, const Pos & pos) {
try { try {
@ -462,7 +462,7 @@ struct CmdFlakeCheck : FlakeCommand
fmt("%s.%s.%s", name, attr.name, attr2.name), fmt("%s.%s.%s", name, attr.name, attr2.name),
*attr2.value, *attr2.pos); *attr2.value, *attr2.pos);
if ((std::string) attr.name == settings.thisSystem.get()) if ((std::string) attr.name == settings.thisSystem.get())
drvPaths.push_back(BuildableReqFromDrv{drvPath}); drvPaths.push_back(DerivedPath::Built{drvPath});
} }
} }
} }

View file

@ -30,18 +30,18 @@ struct CmdLog : InstallableCommand
subs.push_front(store); subs.push_front(store);
auto b = installable->toBuildable(); auto b = installable->toDerivedPathWithHints();
RunPager pager; RunPager pager;
for (auto & sub : subs) { for (auto & sub : subs) {
auto log = std::visit(overloaded { auto log = std::visit(overloaded {
[&](BuildableOpaque bo) { [&](DerivedPathWithHints::Opaque bo) {
return sub->getBuildLog(bo.path); return sub->getBuildLog(bo.path);
}, },
[&](BuildableFromDrv bfd) { [&](DerivedPathWithHints::Built bfd) {
return sub->getBuildLog(bfd.drvPath); return sub->getBuildLog(bfd.drvPath);
}, },
}, b); }, b.raw());
if (!log) continue; if (!log) continue;
stopProgressBar(); stopProgressBar();
printInfo("got build log for '%s' from '%s'", installable->what(), sub->getUri()); printInfo("got build log for '%s' from '%s'", installable->what(), sub->getUri());

View file

@ -242,7 +242,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
{ {
ProfileManifest manifest(*getEvalState(), *profile); ProfileManifest manifest(*getEvalState(), *profile);
std::vector<BuildableReq> pathsToBuild; std::vector<DerivedPath> pathsToBuild;
for (auto & installable : installables) { for (auto & installable : installables) {
if (auto installable2 = std::dynamic_pointer_cast<InstallableFlake>(installable)) { if (auto installable2 = std::dynamic_pointer_cast<InstallableFlake>(installable)) {
@ -258,7 +258,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
attrPath, attrPath,
}; };
pathsToBuild.push_back(BuildableReqFromDrv{drv.drvPath, StringSet{drv.outputName}}); pathsToBuild.push_back(DerivedPath::Built{drv.drvPath, StringSet{drv.outputName}});
manifest.elements.emplace_back(std::move(element)); manifest.elements.emplace_back(std::move(element));
} else { } else {
@ -268,20 +268,20 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
ProfileElement element; ProfileElement element;
std::visit(overloaded { std::visit(overloaded {
[&](BuildableOpaque bo) { [&](DerivedPathWithHints::Opaque bo) {
pathsToBuild.push_back(bo); pathsToBuild.push_back(bo);
element.storePaths.insert(bo.path); element.storePaths.insert(bo.path);
}, },
[&](BuildableFromDrv bfd) { [&](DerivedPathWithHints::Built bfd) {
// TODO: Why are we querying if we know the output // TODO: Why are we querying if we know the output
// names already? Is it just to figure out what the // names already? Is it just to figure out what the
// default one is? // default one is?
for (auto & output : store->queryDerivationOutputMap(bfd.drvPath)) { for (auto & output : store->queryDerivationOutputMap(bfd.drvPath)) {
pathsToBuild.push_back(BuildableReqFromDrv{bfd.drvPath, {output.first}}); pathsToBuild.push_back(DerivedPath::Built{bfd.drvPath, {output.first}});
element.storePaths.insert(output.second); element.storePaths.insert(output.second);
} }
}, },
}, buildable); }, buildable.raw());
manifest.elements.emplace_back(std::move(element)); manifest.elements.emplace_back(std::move(element));
} }
@ -400,7 +400,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
auto matchers = getMatchers(store); auto matchers = getMatchers(store);
// FIXME: code duplication // FIXME: code duplication
std::vector<BuildableReq> pathsToBuild; std::vector<DerivedPath> pathsToBuild;
for (size_t i = 0; i < manifest.elements.size(); ++i) { for (size_t i = 0; i < manifest.elements.size(); ++i) {
auto & element(manifest.elements[i]); auto & element(manifest.elements[i]);
@ -435,7 +435,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
attrPath, attrPath,
}; };
pathsToBuild.push_back(BuildableReqFromDrv{drv.drvPath, {"out"}}); // FIXME pathsToBuild.push_back(DerivedPath::Built{drv.drvPath, {"out"}}); // FIXME
} }
} }

View file

@ -182,7 +182,7 @@ struct CmdRun : InstallableCommand, RunCommon
auto app = installable->toApp(*state); auto app = installable->toApp(*state);
state->store->buildPaths(toBuildableReqs(app.context)); state->store->buildPaths(toDerivedPaths(app.context));
Strings allArgs{app.program}; Strings allArgs{app.program};
for (auto & i : args) allArgs.push_back(i); for (auto & i : args) allArgs.push_back(i);