aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libstore/binary-cache-store.cc18
-rw-r--r--src/libstore/binary-cache-store.hh7
-rw-r--r--src/libstore/build/derivation-goal.cc27
-rw-r--r--src/libstore/ca-specific-schema.sql11
-rw-r--r--src/libstore/daemon.cc22
-rw-r--r--src/libstore/dummy-store.cc3
-rw-r--r--src/libstore/legacy-ssh-store.cc4
-rw-r--r--src/libstore/local-binary-cache-store.cc1
-rw-r--r--src/libstore/local-store.cc210
-rw-r--r--src/libstore/local-store.hh12
-rw-r--r--src/libstore/local.mk4
-rw-r--r--src/libstore/realisation.cc49
-rw-r--r--src/libstore/realisation.hh35
-rw-r--r--src/libstore/remote-store.cc21
-rw-r--r--src/libstore/remote-store.hh4
-rw-r--r--src/libstore/store-api.hh15
-rw-r--r--src/libstore/worker-protocol.hh5
-rw-r--r--tests/content-addressed.sh3
18 files changed, 379 insertions, 72 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc
index a918b7208..5b081c1ae 100644
--- a/src/libstore/binary-cache-store.cc
+++ b/src/libstore/binary-cache-store.cc
@@ -443,6 +443,24 @@ StorePath BinaryCacheStore::addTextToStore(const string & name, const string & s
})->path;
}
+std::optional<const Realisation> BinaryCacheStore::queryRealisation(const DrvOutput & id)
+{
+ auto outputInfoFilePath = realisationsPrefix + "/" + id.to_string() + ".doi";
+ auto rawOutputInfo = getFile(outputInfoFilePath);
+
+ if (rawOutputInfo) {
+ return {Realisation::fromJSON(
+ nlohmann::json::parse(*rawOutputInfo), outputInfoFilePath)};
+ } else {
+ return std::nullopt;
+ }
+}
+
+void BinaryCacheStore::registerDrvOutput(const Realisation& info) {
+ auto filePath = realisationsPrefix + "/" + info.id.to_string() + ".doi";
+ upsertFile(filePath, info.toJSON(), "application/json");
+}
+
ref<FSAccessor> BinaryCacheStore::getFSAccessor()
{
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()), localNarCache);
diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh
index 5224d7ec8..07a8b2beb 100644
--- a/src/libstore/binary-cache-store.hh
+++ b/src/libstore/binary-cache-store.hh
@@ -33,6 +33,9 @@ private:
protected:
+ // The prefix under which realisation infos will be stored
+ const std::string realisationsPrefix = "/realisations";
+
BinaryCacheStore(const Params & params);
public:
@@ -99,6 +102,10 @@ public:
StorePath addTextToStore(const string & name, const string & s,
const StorePathSet & references, RepairFlag repair) override;
+ void registerDrvOutput(const Realisation & info) override;
+
+ std::optional<const Realisation> queryRealisation(const DrvOutput &) override;
+
void narFromPath(const StorePath & path, Sink & sink) override;
BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc
index de58d9f06..b7bf866eb 100644
--- a/src/libstore/build/derivation-goal.cc
+++ b/src/libstore/build/derivation-goal.cc
@@ -493,8 +493,9 @@ void DerivationGoal::inputsRealised()
if (useDerivation) {
auto & fullDrv = *dynamic_cast<Derivation *>(drv.get());
- if ((!fullDrv.inputDrvs.empty() && derivationIsCA(fullDrv.type()))
- || fullDrv.type() == DerivationType::DeferredInputAddressed) {
+ if (settings.isExperimentalFeatureEnabled("ca-derivations") &&
+ ((!fullDrv.inputDrvs.empty() && derivationIsCA(fullDrv.type()))
+ || fullDrv.type() == DerivationType::DeferredInputAddressed)) {
/* We are be able to resolve this derivation based on the
now-known results of dependencies. If so, we become a stub goal
aliasing that resolved derivation goal */
@@ -2094,6 +2095,20 @@ struct RestrictedStore : public LocalFSStore, public virtual RestrictedStoreConf
/* Nothing to be done; 'path' must already be valid. */
}
+ void registerDrvOutput(const Realisation & info) override
+ {
+ if (!goal.isAllowed(info.id.drvPath))
+ throw InvalidPath("cannot register unknown drv output '%s' in recursive Nix", printStorePath(info.id.drvPath));
+ next->registerDrvOutput(info);
+ }
+
+ std::optional<const Realisation> queryRealisation(const DrvOutput & id) override
+ {
+ if (!goal.isAllowed(id.drvPath))
+ throw InvalidPath("cannot query the output info for unknown derivation '%s' in recursive Nix", printStorePath(id.drvPath));
+ return next->queryRealisation(id);
+ }
+
void buildPaths(const std::vector<StorePathWithOutputs> & paths, BuildMode buildMode) override
{
if (buildMode != bmNormal) throw Error("unsupported build mode");
@@ -3391,9 +3406,11 @@ void DerivationGoal::registerOutputs()
drvPathResolved = writeDerivation(worker.store, drv2);
}
- if (useDerivation || isCaFloating)
- for (auto & [outputName, newInfo] : infos)
- worker.store.linkDeriverToPath(drvPathResolved, outputName, newInfo.path);
+ if (settings.isExperimentalFeatureEnabled("ca-derivations"))
+ for (auto& [outputName, newInfo] : infos)
+ worker.store.registerDrvOutput(Realisation{
+ .id = DrvOutput{drvPathResolved, outputName},
+ .outPath = newInfo.path});
}
diff --git a/src/libstore/ca-specific-schema.sql b/src/libstore/ca-specific-schema.sql
new file mode 100644
index 000000000..93c442826
--- /dev/null
+++ b/src/libstore/ca-specific-schema.sql
@@ -0,0 +1,11 @@
+-- Extension of the sql schema for content-addressed derivations.
+-- Won't be loaded unless the experimental feature `ca-derivations`
+-- is enabled
+
+create table if not exists Realisations (
+ drvPath text not null,
+ outputName text not null, -- symbolic output id, usually "out"
+ outputPath integer not null,
+ primary key (drvPath, outputName),
+ foreign key (outputPath) references ValidPaths(id) on delete cascade
+);
diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc
index 2224d54d5..ba5788b64 100644
--- a/src/libstore/daemon.cc
+++ b/src/libstore/daemon.cc
@@ -868,6 +868,28 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
break;
}
+ case wopRegisterDrvOutput: {
+ logger->startWork();
+ auto outputId = DrvOutput::parse(readString(from));
+ auto outputPath = StorePath(readString(from));
+ auto resolvedDrv = StorePath(readString(from));
+ store->registerDrvOutput(Realisation{
+ .id = outputId, .outPath = outputPath});
+ logger->stopWork();
+ break;
+ }
+
+ case wopQueryRealisation: {
+ logger->startWork();
+ auto outputId = DrvOutput::parse(readString(from));
+ auto info = store->queryRealisation(outputId);
+ logger->stopWork();
+ std::set<StorePath> outPaths;
+ if (info) outPaths.insert(info->outPath);
+ worker_proto::write(*store, to, outPaths);
+ break;
+ }
+
default:
throw Error("invalid operation %1%", op);
}
diff --git a/src/libstore/dummy-store.cc b/src/libstore/dummy-store.cc
index 98b745c3a..91fc178db 100644
--- a/src/libstore/dummy-store.cc
+++ b/src/libstore/dummy-store.cc
@@ -60,6 +60,9 @@ struct DummyStore : public Store, public virtual DummyStoreConfig
BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
BuildMode buildMode) override
{ unsupported("buildDerivation"); }
+
+ std::optional<const Realisation> queryRealisation(const DrvOutput&) override
+ { unsupported("queryRealisation"); }
};
static RegisterStoreImplementation<DummyStore, DummyStoreConfig> regDummyStore;
diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc
index 467169ce8..ad1779aea 100644
--- a/src/libstore/legacy-ssh-store.cc
+++ b/src/libstore/legacy-ssh-store.cc
@@ -333,6 +333,10 @@ public:
auto conn(connections->get());
return conn->remoteVersion;
}
+
+ std::optional<const Realisation> queryRealisation(const DrvOutput&) override
+ // TODO: Implement
+ { unsupported("queryRealisation"); }
};
static RegisterStoreImplementation<LegacySSHStore, LegacySSHStoreConfig> regLegacySSHStore;
diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc
index 7d979c5c2..bb7464989 100644
--- a/src/libstore/local-binary-cache-store.cc
+++ b/src/libstore/local-binary-cache-store.cc
@@ -87,6 +87,7 @@ protected:
void LocalBinaryCacheStore::init()
{
createDirs(binaryCacheDir + "/nar");
+ createDirs(binaryCacheDir + realisationsPrefix);
if (writeDebugInfo)
createDirs(binaryCacheDir + "/debuginfo");
BinaryCacheStore::init();
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 2a47b3956..69ab821d9 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -52,12 +52,52 @@ struct LocalStore::State::Stmts {
SQLiteStmt QueryReferrers;
SQLiteStmt InvalidatePath;
SQLiteStmt AddDerivationOutput;
+ SQLiteStmt RegisterRealisedOutput;
SQLiteStmt QueryValidDerivers;
SQLiteStmt QueryDerivationOutputs;
+ SQLiteStmt QueryRealisedOutput;
+ SQLiteStmt QueryAllRealisedOutputs;
SQLiteStmt QueryPathFromHashPart;
SQLiteStmt QueryValidPaths;
};
+int getSchema(Path schemaPath)
+{
+ int curSchema = 0;
+ if (pathExists(schemaPath)) {
+ string s = readFile(schemaPath);
+ if (!string2Int(s, curSchema))
+ throw Error("'%1%' is corrupt", schemaPath);
+ }
+ return curSchema;
+}
+
+void migrateCASchema(SQLite& db, Path schemaPath, AutoCloseFD& lockFd)
+{
+ const int nixCASchemaVersion = 1;
+ int curCASchema = getSchema(schemaPath);
+ if (curCASchema != nixCASchemaVersion) {
+ if (curCASchema > nixCASchemaVersion) {
+ throw Error("current Nix store ca-schema is version %1%, but I only support %2%",
+ curCASchema, nixCASchemaVersion);
+ }
+
+ if (!lockFile(lockFd.get(), ltWrite, false)) {
+ printInfo("waiting for exclusive access to the Nix store for ca drvs...");
+ lockFile(lockFd.get(), ltWrite, true);
+ }
+
+ if (curCASchema == 0) {
+ static const char schema[] =
+ #include "ca-specific-schema.sql.gen.hh"
+ ;
+ db.exec(schema);
+ }
+ writeFile(schemaPath, fmt("%d", nixCASchemaVersion));
+ lockFile(lockFd.get(), ltRead, true);
+ }
+}
+
LocalStore::LocalStore(const Params & params)
: StoreConfig(params)
, Store(params)
@@ -238,6 +278,10 @@ LocalStore::LocalStore(const Params & params)
else openDB(*state, false);
+ if (settings.isExperimentalFeatureEnabled("ca-derivations")) {
+ migrateCASchema(state->db, dbDir + "/ca-schema", globalLock);
+ }
+
/* Prepare SQL statements. */
state->stmts->RegisterValidPath.create(state->db,
"insert into ValidPaths (path, hash, registrationTime, deriver, narSize, ultimate, sigs, ca) values (?, ?, ?, ?, ?, ?, ?, ?);");
@@ -264,6 +308,28 @@ LocalStore::LocalStore(const Params & params)
state->stmts->QueryPathFromHashPart.create(state->db,
"select path from ValidPaths where path >= ? limit 1;");
state->stmts->QueryValidPaths.create(state->db, "select path from ValidPaths");
+ if (settings.isExperimentalFeatureEnabled("ca-derivations")) {
+ state->stmts->RegisterRealisedOutput.create(state->db,
+ R"(
+ insert or replace into Realisations (drvPath, outputName, outputPath)
+ values (?, ?, (select id from ValidPaths where path = ?))
+ ;
+ )");
+ state->stmts->QueryRealisedOutput.create(state->db,
+ R"(
+ select Output.path from Realisations
+ inner join ValidPaths as Output on Output.id = Realisations.outputPath
+ where drvPath = ? and outputName = ?
+ ;
+ )");
+ state->stmts->QueryAllRealisedOutputs.create(state->db,
+ R"(
+ select outputName, Output.path from Realisations
+ inner join ValidPaths as Output on Output.id = Realisations.outputPath
+ where drvPath = ?
+ ;
+ )");
+ }
}
@@ -301,16 +367,7 @@ std::string LocalStore::getUri()
int LocalStore::getSchema()
-{
- int curSchema = 0;
- if (pathExists(schemaPath)) {
- string s = readFile(schemaPath);
- if (!string2Int(s, curSchema))
- throw Error("'%1%' is corrupt", schemaPath);
- }
- return curSchema;
-}
-
+{ return nix::getSchema(schemaPath); }
void LocalStore::openDB(State & state, bool create)
{
@@ -597,13 +654,19 @@ void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivat
}
-void LocalStore::linkDeriverToPath(const StorePath & deriver, const string & outputName, const StorePath & output)
+void LocalStore::registerDrvOutput(const Realisation & info)
{
auto state(_state.lock());
- return linkDeriverToPath(*state, queryValidPathId(*state, deriver), outputName, output);
+ retrySQLite<void>([&]() {
+ state->stmts->RegisterRealisedOutput.use()
+ (info.id.drvPath.to_string())
+ (info.id.outputName)
+ (printStorePath(info.outPath))
+ .exec();
+ });
}
-void LocalStore::linkDeriverToPath(State & state, uint64_t deriver, const string & outputName, const StorePath & output)
+void LocalStore::cacheDrvOutputMapping(State & state, const uint64_t deriver, const string & outputName, const StorePath & output)
{
retrySQLite<void>([&]() {
state.stmts->AddDerivationOutput.use()
@@ -653,7 +716,7 @@ uint64_t LocalStore::addValidPath(State & state,
/* Floating CA derivations have indeterminate output paths until
they are built, so don't register anything in that case */
if (i.second.second)
- linkDeriverToPath(state, id, i.first, *i.second.second);
+ cacheDrvOutputMapping(state, id, i.first, *i.second.second);
}
}
@@ -814,70 +877,85 @@ StorePathSet LocalStore::queryValidDerivers(const StorePath & path)
});
}
-
-std::map<std::string, std::optional<StorePath>> LocalStore::queryPartialDerivationOutputMap(const StorePath & path_)
+// Try to resolve the derivation at path `original`, with a caching layer
+// to make it more efficient
+std::optional<StorePath> cachedResolve(
+ LocalStore & store,
+ const StorePath & original)
{
- auto path = path_;
- std::map<std::string, std::optional<StorePath>> outputs;
- Derivation drv = readDerivation(path);
- for (auto & [outName, _] : drv.outputs) {
- outputs.insert_or_assign(outName, std::nullopt);
- }
- bool haveCached = false;
{
auto resolutions = drvPathResolutions.lock();
- auto resolvedPathOptIter = resolutions->find(path);
+ auto resolvedPathOptIter = resolutions->find(original);
if (resolvedPathOptIter != resolutions->end()) {
auto & [_, resolvedPathOpt] = *resolvedPathOptIter;
if (resolvedPathOpt)
- path = *resolvedPathOpt;
- haveCached = true;
+ return resolvedPathOpt;
}
}
- /* can't just use else-if instead of `!haveCached` because we need to unlock
- `drvPathResolutions` before it is locked in `Derivation::resolve`. */
- if (!haveCached && (drv.type() == DerivationType::CAFloating || drv.type() == DerivationType::DeferredInputAddressed)) {
- /* Try resolve drv and use that path instead. */
- auto attempt = drv.tryResolve(*this);
- if (!attempt)
- /* If we cannot resolve the derivation, we cannot have any path
- assigned so we return the map of all std::nullopts. */
- return outputs;
- /* Just compute store path */
- auto pathResolved = writeDerivation(*this, *std::move(attempt), NoRepair, true);
- /* Store in memo table. */
- /* FIXME: memo logic should not be local-store specific, should have
- wrapper-method instead. */
- drvPathResolutions.lock()->insert_or_assign(path, pathResolved);
- path = std::move(pathResolved);
- }
- return retrySQLite<std::map<std::string, std::optional<StorePath>>>([&]() {
- auto state(_state.lock());
+ /* Try resolve drv and use that path instead. */
+ auto drv = store.readDerivation(original);
+ auto attempt = drv.tryResolve(store);
+ if (!attempt)
+ return std::nullopt;
+ /* Just compute store path */
+ auto pathResolved =
+ writeDerivation(store, *std::move(attempt), NoRepair, true);
+ /* Store in memo table. */
+ drvPathResolutions.lock()->insert_or_assign(original, pathResolved);
+ return pathResolved;
+}
+
+std::map<std::string, std::optional<StorePath>>
+LocalStore::queryPartialDerivationOutputMap(const StorePath& path_)
+{
+ auto path = path_;
+ auto outputs = retrySQLite<std::map<std::string, std::optional<StorePath>>>([&]() {
+ auto state(_state.lock());
+ std::map<std::string, std::optional<StorePath>> outputs;
uint64_t drvId;
try {
drvId = queryValidPathId(*state, path);
- } catch (InvalidPath &) {
- /* FIXME? if the derivation doesn't exist, we cannot have a mapping
- for it. */
- return outputs;
+ } catch (InvalidPath&) {
+ // Ignore non-existing drvs as they might still have an output map
+ // defined if ca-derivations is enabled
}
+ auto use(state->stmts->QueryDerivationOutputs.use()(drvId));
+ while (use.next())
+ outputs.insert_or_assign(
+ use.getStr(0), parseStorePath(use.getStr(1)));
- auto useQueryDerivationOutputs {
- state->stmts->QueryDerivationOutputs.use()
- (drvId)
- };
+ return outputs;
+ });
+
+ if (!settings.isExperimentalFeatureEnabled("ca-derivations"))
+ return outputs;
+
+ auto drv = readDerivation(path);
+
+ for (auto & output : drv.outputsAndOptPaths(*this)) {
+ outputs.emplace(output.first, std::nullopt);
+ }
+
+ auto resolvedDrv = cachedResolve(*this, path);
+
+ if (!resolvedDrv)
+ return outputs;
+
+ retrySQLite<void>([&]() {
+ auto state(_state.lock());
+ path = *resolvedDrv;
+ auto useQueryDerivationOutputs{
+ state->stmts->QueryAllRealisedOutputs.use()(path.to_string())};
while (useQueryDerivationOutputs.next())
outputs.insert_or_assign(
useQueryDerivationOutputs.getStr(0),
- parseStorePath(useQueryDerivationOutputs.getStr(1))
- );
-
- return outputs;
+ parseStorePath(useQueryDerivationOutputs.getStr(1)));
});
-}
+ return outputs;
+}
std::optional<StorePath> LocalStore::queryPathFromHashPart(const std::string & hashPart)
{
@@ -1612,5 +1690,19 @@ void LocalStore::createUser(const std::string & userName, uid_t userId)
}
}
-
+std::optional<const Realisation> LocalStore::queryRealisation(
+ const DrvOutput& id) {
+ typedef std::optional<const Realisation> Ret;
+ return retrySQLite<Ret>([&]() -> Ret {
+ auto state(_state.lock());
+ auto use(state->stmts->QueryRealisedOutput.use()(id.drvPath.to_string())(
+ id.outputName));
+ if (!use.next())
+ return std::nullopt;
+ auto outputPath = parseStorePath(use.getStr(0));
+ auto resolvedDrv = StorePath(use.getStr(1));
+ return Ret{
+ Realisation{.id = id, .outPath = outputPath}};
+ });
}
+} // namespace nix
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index 332718af4..69559e346 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -208,6 +208,13 @@ public:
garbage until it exceeds maxFree. */
void autoGC(bool sync = true);
+ /* Register the store path 'output' as the output named 'outputName' of
+ derivation 'deriver'. */
+ void registerDrvOutput(const Realisation & info) override;
+ void cacheDrvOutputMapping(State & state, const uint64_t deriver, const string & outputName, const StorePath & output);
+
+ std::optional<const Realisation> queryRealisation(const DrvOutput&) override;
+
private:
int getSchema();
@@ -276,11 +283,6 @@ private:
specified by the ‘secret-key-files’ option. */
void signPathInfo(ValidPathInfo & info);
- /* Register the store path 'output' as the output named 'outputName' of
- derivation 'deriver'. */
- void linkDeriverToPath(const StorePath & deriver, const string & outputName, const StorePath & output);
- void linkDeriverToPath(State & state, uint64_t deriver, const string & outputName, const StorePath & output);
-
Path getRealStoreDir() override { return realStoreDir; }
void createUser(const std::string & userName, uid_t userId) override;
diff --git a/src/libstore/local.mk b/src/libstore/local.mk
index dfe1e2cc4..03c4351ac 100644
--- a/src/libstore/local.mk
+++ b/src/libstore/local.mk
@@ -48,7 +48,7 @@ ifneq ($(sandbox_shell),)
libstore_CXXFLAGS += -DSANDBOX_SHELL="\"$(sandbox_shell)\""
endif
-$(d)/local-store.cc: $(d)/schema.sql.gen.hh
+$(d)/local-store.cc: $(d)/schema.sql.gen.hh $(d)/ca-specific-schema.sql.gen.hh
$(d)/build.cc:
@@ -58,7 +58,7 @@ $(d)/build.cc:
@echo ')foo"' >> $@.tmp
@mv $@.tmp $@
-clean-files += $(d)/schema.sql.gen.hh
+clean-files += $(d)/schema.sql.gen.hh $(d)/ca-specific-schema.sql.gen.hh
$(eval $(call install-file-in, $(d)/nix-store.pc, $(prefix)/lib/pkgconfig, 0644))
diff --git a/src/libstore/realisation.cc b/src/libstore/realisation.cc
new file mode 100644
index 000000000..47db1ec9f
--- /dev/null
+++ b/src/libstore/realisation.cc
@@ -0,0 +1,49 @@
+#include "realisation.hh"
+#include "store-api.hh"
+#include <nlohmann/json.hpp>
+
+namespace nix {
+
+MakeError(InvalidDerivationOutputId, Error);
+
+DrvOutput DrvOutput::parse(const std::string &strRep) {
+ const auto &[rawPath, outputs] = parsePathWithOutputs(strRep);
+ if (outputs.size() != 1)
+ throw InvalidDerivationOutputId("Invalid derivation output id %s", strRep);
+
+ return DrvOutput{
+ .drvPath = StorePath(rawPath),
+ .outputName = *outputs.begin(),
+ };
+}
+
+std::string DrvOutput::to_string() const {
+ return std::string(drvPath.to_string()) + "!" + outputName;
+}
+
+nlohmann::json Realisation::toJSON() const {
+ return nlohmann::json{
+ {"id", id.to_string()},
+ {"outPath", outPath.to_string()},
+ };
+}
+
+Realisation Realisation::fromJSON(
+ const nlohmann::json& json,
+ const std::string& whence) {
+ auto getField = [&](std::string fieldName) -> std::string {
+ auto fieldIterator = json.find(fieldName);
+ if (fieldIterator == json.end())
+ throw Error(
+ "Drv output info file '%1%' is corrupt, missing field %2%",
+ whence, fieldName);
+ return *fieldIterator;
+ };
+
+ return Realisation{
+ .id = DrvOutput::parse(getField("id")),
+ .outPath = StorePath(getField("outPath")),
+ };
+}
+
+} // namespace nix
diff --git a/src/libstore/realisation.hh b/src/libstore/realisation.hh
new file mode 100644
index 000000000..08579b739
--- /dev/null
+++ b/src/libstore/realisation.hh
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "path.hh"
+#include <nlohmann/json_fwd.hpp>
+
+namespace nix {
+
+struct DrvOutput {
+ StorePath drvPath;
+ std::string outputName;
+
+ std::string to_string() const;
+
+ static DrvOutput parse(const std::string &);
+
+ bool operator<(const DrvOutput& other) const { return to_pair() < other.to_pair(); }
+ bool operator==(const DrvOutput& other) const { return to_pair() == other.to_pair(); }
+
+private:
+ // Just to make comparison operators easier to write
+ std::pair<StorePath, std::string> to_pair() const
+ { return std::make_pair(drvPath, outputName); }
+};
+
+struct Realisation {
+ DrvOutput id;
+ StorePath outPath;
+
+ nlohmann::json toJSON() const;
+ static Realisation fromJSON(const nlohmann::json& json, const std::string& whence);
+};
+
+typedef std::map<DrvOutput, Realisation> DrvOutputs;
+
+}
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index be29f8e6f..f1f4d0516 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -609,6 +609,27 @@ StorePath RemoteStore::addTextToStore(const string & name, const string & s,
return addCAToStore(source, name, TextHashMethod{}, references, repair)->path;
}
+void RemoteStore::registerDrvOutput(const Realisation & info)
+{
+ auto conn(getConnection());
+ conn->to << wopRegisterDrvOutput;
+ conn->to << info.id.to_string();
+ conn->to << std::string(info.outPath.to_string());
+ conn.processStderr();
+}
+
+std::optional<const Realisation> RemoteStore::queryRealisation(const DrvOutput & id)
+{
+ auto conn(getConnection());
+ conn->to << wopQueryRealisation;
+ conn->to << id.to_string();
+ conn.processStderr();
+ auto outPaths = worker_proto::read(*this, conn->from, Phantom<std::set<StorePath>>{});
+ if (outPaths.empty())
+ return std::nullopt;
+ return {Realisation{.id = id, .outPath = *outPaths.begin()}};
+}
+
void RemoteStore::buildPaths(const std::vector<StorePathWithOutputs> & drvPaths, BuildMode buildMode)
{
diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh
index 9f78fcb02..fdd53e6ed 100644
--- a/src/libstore/remote-store.hh
+++ b/src/libstore/remote-store.hh
@@ -81,6 +81,10 @@ public:
StorePath addTextToStore(const string & name, const string & s,
const StorePathSet & references, RepairFlag repair) override;
+ void registerDrvOutput(const Realisation & info) override;
+
+ std::optional<const Realisation> queryRealisation(const DrvOutput &) override;
+
void buildPaths(const std::vector<StorePathWithOutputs> & paths, BuildMode buildMode) override;
BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 6b9331495..7cdadc1f3 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -1,5 +1,6 @@
#pragma once
+#include "realisation.hh"
#include "path.hh"
#include "hash.hh"
#include "content-address.hh"
@@ -396,6 +397,8 @@ protected:
public:
+ virtual std::optional<const Realisation> queryRealisation(const DrvOutput &) = 0;
+
/* Queries the set of incoming FS references for a store path.
The result is not cleared. */
virtual void queryReferrers(const StorePath & path, StorePathSet & referrers)
@@ -468,6 +471,18 @@ public:
virtual StorePath addTextToStore(const string & name, const string & s,
const StorePathSet & references, RepairFlag repair = NoRepair) = 0;
+ /**
+ * Add a mapping indicating that `deriver!outputName` maps to the output path
+ * `output`.
+ *
+ * This is redundant for known-input-addressed and fixed-output derivations
+ * as this information is already present in the drv file, but necessary for
+ * floating-ca derivations and their dependencies as there's no way to
+ * retrieve this information otherwise.
+ */
+ virtual void registerDrvOutput(const Realisation & output)
+ { unsupported("registerDrvOutput"); }
+
/* Write a NAR dump of a store path. */
virtual void narFromPath(const StorePath & path, Sink & sink) = 0;
diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh
index 63bd6ea49..f2cdc7ca3 100644
--- a/src/libstore/worker-protocol.hh
+++ b/src/libstore/worker-protocol.hh
@@ -1,5 +1,8 @@
#pragma once
+#include "store-api.hh"
+#include "serialise.hh"
+
namespace nix {
@@ -50,6 +53,8 @@ typedef enum {
wopAddToStoreNar = 39,
wopQueryMissing = 40,
wopQueryDerivationOutputMap = 41,
+ wopRegisterDrvOutput = 42,
+ wopQueryRealisation = 43,
} WorkerOp;
diff --git a/tests/content-addressed.sh b/tests/content-addressed.sh
index bc37a99c1..e8ac88609 100644
--- a/tests/content-addressed.sh
+++ b/tests/content-addressed.sh
@@ -55,7 +55,8 @@ testNixCommand () {
nix build --experimental-features 'nix-command ca-derivations' --file ./content-addressed.nix --no-link
}
-testRemoteCache
+# Disabled until we have it properly working
+# testRemoteCache
testDeterministicCA
testCutoff
testGC