2020-05-27 22:56:34 +02:00
|
|
|
#include "libstore/remote-store.hh"
|
2020-05-19 16:54:39 +02:00
|
|
|
|
2020-05-20 05:33:07 +02:00
|
|
|
#include <cerrno>
|
2010-06-24 19:51:04 +02:00
|
|
|
#include <cstring>
|
2020-05-19 16:54:39 +02:00
|
|
|
|
2020-08-14 04:06:23 +02:00
|
|
|
#include <absl/status/status.h>
|
2020-05-24 02:36:11 +02:00
|
|
|
#include <absl/strings/ascii.h>
|
2006-12-03 03:08:13 +01:00
|
|
|
#include <fcntl.h>
|
2020-05-19 02:02:44 +02:00
|
|
|
#include <glog/logging.h>
|
2006-12-03 03:36:44 +01:00
|
|
|
#include <sys/socket.h>
|
2006-12-03 03:08:13 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2006-12-04 15:21:39 +01:00
|
|
|
#include <sys/un.h>
|
2006-11-30 20:54:43 +01:00
|
|
|
#include <unistd.h>
|
2020-05-19 16:54:39 +02:00
|
|
|
|
2020-05-27 22:56:34 +02:00
|
|
|
#include "libstore/derivations.hh"
|
|
|
|
#include "libstore/globals.hh"
|
|
|
|
#include "libstore/worker-protocol.hh"
|
|
|
|
#include "libutil/affinity.hh"
|
|
|
|
#include "libutil/archive.hh"
|
|
|
|
#include "libutil/finally.hh"
|
|
|
|
#include "libutil/pool.hh"
|
|
|
|
#include "libutil/serialise.hh"
|
|
|
|
#include "libutil/util.hh"
|
2006-11-30 20:54:43 +01:00
|
|
|
|
2006-11-30 19:35:50 +01:00
|
|
|
namespace nix {
|
|
|
|
|
2016-06-01 14:49:12 +02:00
|
|
|
Path readStorePath(Store& store, Source& from) {
|
2006-12-05 02:31:45 +01:00
|
|
|
Path path = readString(from);
|
2016-06-01 14:49:12 +02:00
|
|
|
store.assertStorePath(path);
|
2006-12-05 02:31:45 +01:00
|
|
|
return path;
|
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2016-06-01 14:49:12 +02:00
|
|
|
template <class T>
|
|
|
|
T readStorePaths(Store& store, Source& from) {
|
2011-12-16 23:31:25 +01:00
|
|
|
T paths = readStrings<T>(from);
|
2020-05-19 18:38:04 +02:00
|
|
|
for (auto& i : paths) {
|
|
|
|
store.assertStorePath(i);
|
|
|
|
}
|
2006-12-05 02:31:45 +01:00
|
|
|
return paths;
|
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2016-04-05 15:30:22 +02:00
|
|
|
template PathSet readStorePaths(Store& store, Source& from);
|
2016-06-01 14:49:12 +02:00
|
|
|
template Paths readStorePaths(Store& store, Source& from);
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2016-06-01 14:49:12 +02:00
|
|
|
/* TODO: Separate these store impls into different files, give them better names
|
2020-05-17 17:31:57 +02:00
|
|
|
*/
|
2017-02-07 19:28:40 +01:00
|
|
|
RemoteStore::RemoteStore(const Params& params)
|
|
|
|
: Store(params),
|
|
|
|
connections(make_ref<Pool<Connection>>(
|
|
|
|
std::max(1, (int)maxConnections),
|
|
|
|
[this]() { return openConnectionWrapper(); },
|
|
|
|
[this](const ref<Connection>& r) {
|
|
|
|
return r->to.good() && r->from.good() &&
|
|
|
|
std::chrono::duration_cast<std::chrono::seconds>(
|
2016-09-02 20:15:04 +02:00
|
|
|
std::chrono::steady_clock::now() - r->startTime)
|
|
|
|
.count() < maxConnectionAge;
|
2020-05-17 17:31:57 +02:00
|
|
|
})) {}
|
|
|
|
|
2016-09-02 20:15:04 +02:00
|
|
|
ref<RemoteStore::Connection> RemoteStore::openConnectionWrapper() {
|
|
|
|
if (failed) {
|
|
|
|
throw Error("opening a connection to remote store '%s' previously failed",
|
|
|
|
getUri());
|
2020-05-19 21:47:23 +02:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
try {
|
2017-07-30 13:27:57 +02:00
|
|
|
return openConnection();
|
2016-09-02 20:15:04 +02:00
|
|
|
} catch (...) {
|
2017-03-03 19:35:34 +01:00
|
|
|
failed = true;
|
2016-09-02 20:15:04 +02:00
|
|
|
throw;
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-03 19:35:34 +01:00
|
|
|
void RemoteStore::initConnection(Connection& conn) {
|
2017-07-30 13:27:57 +02:00
|
|
|
/* Send the magic greeting, check for the reply. */
|
|
|
|
try {
|
|
|
|
conn.to << WORKER_MAGIC_1;
|
|
|
|
conn.to.flush();
|
|
|
|
unsigned int magic = readInt(conn.from);
|
2016-02-23 15:00:59 +01:00
|
|
|
if (magic != WORKER_MAGIC_2) {
|
|
|
|
throw Error("protocol mismatch");
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2017-03-01 13:52:54 +01:00
|
|
|
conn.from >> conn.daemonVersion;
|
2016-09-02 20:15:04 +02:00
|
|
|
if (GET_PROTOCOL_MAJOR(conn.daemonVersion) !=
|
2017-07-30 13:27:57 +02:00
|
|
|
GET_PROTOCOL_MAJOR(PROTOCOL_VERSION)) {
|
|
|
|
throw Error("Nix daemon protocol version not supported");
|
2020-05-19 21:47:23 +02:00
|
|
|
}
|
2017-03-03 19:35:34 +01:00
|
|
|
if (GET_PROTOCOL_MINOR(conn.daemonVersion) < 10) {
|
|
|
|
throw Error("the Nix daemon version is too old");
|
2020-05-19 21:47:23 +02:00
|
|
|
}
|
2016-09-02 20:15:04 +02:00
|
|
|
conn.to << PROTOCOL_VERSION;
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2016-09-02 20:15:04 +02:00
|
|
|
if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 14) {
|
2017-03-03 19:35:34 +01:00
|
|
|
int cpu = sameMachine() && settings.lockCPU ? lockToCurrentCPU() : -1;
|
|
|
|
if (cpu != -1) {
|
|
|
|
conn.to << 1 << cpu;
|
2020-05-17 17:31:57 +02:00
|
|
|
} else {
|
2016-09-02 20:15:04 +02:00
|
|
|
conn.to << 0;
|
2020-05-19 21:47:23 +02:00
|
|
|
}
|
2017-03-03 19:35:34 +01:00
|
|
|
}
|
2012-07-30 23:13:25 +02:00
|
|
|
|
2016-09-02 20:15:04 +02:00
|
|
|
if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 11) {
|
2020-05-20 23:27:37 +02:00
|
|
|
conn.to << 0u;
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2012-08-01 00:19:44 +02:00
|
|
|
|
2018-10-16 23:36:15 +02:00
|
|
|
auto ex = conn.processStderr();
|
|
|
|
if (ex) {
|
|
|
|
std::rethrow_exception(ex);
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2018-04-09 21:26:16 +02:00
|
|
|
} catch (Error& e) {
|
2017-07-30 13:27:57 +02:00
|
|
|
throw Error("cannot open connection to remote store '%s': %s", getUri(),
|
|
|
|
e.what());
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
setOptions(conn);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2016-09-02 20:15:04 +02:00
|
|
|
void RemoteStore::setOptions(Connection& conn) {
|
2020-05-20 23:27:37 +02:00
|
|
|
conn.to << wopSetOptions << static_cast<uint64_t>(settings.keepFailed)
|
|
|
|
<< static_cast<uint64_t>(settings.keepGoing)
|
2020-07-19 19:03:39 +02:00
|
|
|
<< static_cast<uint64_t>(settings.tryFallback)
|
|
|
|
<< /* previously: verbosity = */ 0 << settings.maxBuildJobs
|
|
|
|
<< settings.maxSilentTime << 1u
|
|
|
|
<< /* previously: remote verbosity = */ 0 << 0 // obsolete log type
|
|
|
|
<< 0 /* obsolete print build trace */
|
2020-05-20 23:27:37 +02:00
|
|
|
<< settings.buildCores
|
|
|
|
<< static_cast<uint64_t>(settings.useSubstitutes);
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2016-09-02 20:15:04 +02:00
|
|
|
if (GET_PROTOCOL_MINOR(conn.daemonVersion) >= 12) {
|
2018-03-27 18:41:31 +02:00
|
|
|
std::map<std::string, Config::SettingInfo> overrides;
|
|
|
|
globalConfig.getSettings(overrides, true);
|
2019-08-28 16:29:44 +02:00
|
|
|
overrides.erase(settings.keepFailed.name);
|
|
|
|
overrides.erase(settings.keepGoing.name);
|
|
|
|
overrides.erase(settings.tryFallback.name);
|
|
|
|
overrides.erase(settings.maxBuildJobs.name);
|
|
|
|
overrides.erase(settings.maxSilentTime.name);
|
|
|
|
overrides.erase(settings.buildCores.name);
|
|
|
|
overrides.erase(settings.useSubstitutes.name);
|
2019-09-22 12:57:20 +02:00
|
|
|
overrides.erase(settings.showTrace.name);
|
2016-09-02 20:15:04 +02:00
|
|
|
conn.to << overrides.size();
|
2018-03-27 18:41:31 +02:00
|
|
|
for (auto& i : overrides) {
|
|
|
|
conn.to << i.first << i.second.value;
|
2020-05-19 20:04:08 +02:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2018-10-16 23:36:15 +02:00
|
|
|
auto ex = conn.processStderr();
|
|
|
|
if (ex) {
|
|
|
|
std::rethrow_exception(ex);
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2018-10-16 23:36:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* A wrapper around Pool<RemoteStore::Connection>::Handle that marks
|
|
|
|
the connection as bad (causing it to be closed) if a non-daemon
|
|
|
|
exception is thrown before the handle is closed. Such an exception
|
|
|
|
causes a deviation from the expected protocol and therefore a
|
|
|
|
desynchronization between the client and daemon. */
|
|
|
|
struct ConnectionHandle {
|
|
|
|
Pool<RemoteStore::Connection>::Handle handle;
|
|
|
|
bool daemonException = false;
|
|
|
|
|
2020-05-19 23:02:23 +02:00
|
|
|
explicit ConnectionHandle(Pool<RemoteStore::Connection>::Handle&& handle)
|
2018-10-16 23:36:15 +02:00
|
|
|
: handle(std::move(handle)) {}
|
|
|
|
|
|
|
|
ConnectionHandle(ConnectionHandle&& h) : handle(std::move(h.handle)) {}
|
|
|
|
|
|
|
|
~ConnectionHandle() {
|
2020-05-20 23:27:37 +02:00
|
|
|
if (!daemonException && (std::uncaught_exceptions() != 0)) {
|
2018-10-16 23:36:15 +02:00
|
|
|
handle.markBad();
|
2020-05-19 02:02:44 +02:00
|
|
|
// TODO(tazjin): are these types of things supposed to be DEBUG?
|
|
|
|
DLOG(INFO) << "closing daemon connection because of an exception";
|
2018-10-16 23:36:15 +02:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
2018-10-16 23:36:15 +02:00
|
|
|
|
|
|
|
RemoteStore::Connection* operator->() { return &*handle; }
|
|
|
|
|
2020-05-20 05:33:07 +02:00
|
|
|
void processStderr(Sink* sink = nullptr, Source* source = nullptr) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto ex = handle->processStderr(sink, source);
|
|
|
|
if (ex) {
|
|
|
|
daemonException = true;
|
|
|
|
std::rethrow_exception(ex);
|
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
2018-10-16 23:36:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ConnectionHandle RemoteStore::getConnection() {
|
|
|
|
return ConnectionHandle(connections->get());
|
2007-09-18 11:11:20 +02:00
|
|
|
}
|
|
|
|
|
2016-04-19 18:50:15 +02:00
|
|
|
bool RemoteStore::isValidPathUncached(const Path& path) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopIsValidPath << path;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2020-05-20 23:27:37 +02:00
|
|
|
return readInt(conn->from) != 0u;
|
2012-07-11 17:08:47 +02:00
|
|
|
}
|
|
|
|
|
2012-07-11 16:49:04 +02:00
|
|
|
PathSet RemoteStore::queryValidPaths(const PathSet& paths,
|
2008-01-29 19:17:36 +01:00
|
|
|
SubstituteFlag maybeSubstitute) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 12) {
|
2012-07-11 17:08:47 +02:00
|
|
|
PathSet res;
|
2015-07-17 19:24:28 +02:00
|
|
|
for (auto& i : paths) {
|
2016-02-23 15:00:59 +01:00
|
|
|
if (isValidPath(i)) {
|
|
|
|
res.insert(i);
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2020-05-19 21:47:23 +02:00
|
|
|
}
|
2012-07-11 17:08:47 +02:00
|
|
|
return res;
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
2020-05-20 23:27:37 +02:00
|
|
|
conn->to << wopQueryValidPaths << paths;
|
|
|
|
conn.processStderr();
|
|
|
|
return readStorePaths<PathSet>(*this, conn->from);
|
2008-01-29 19:17:36 +01:00
|
|
|
}
|
|
|
|
|
2012-07-11 23:52:18 +02:00
|
|
|
PathSet RemoteStore::queryAllValidPaths() {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopQueryAllValidPaths;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-06-01 14:49:12 +02:00
|
|
|
return readStorePaths<PathSet>(*this, conn->from);
|
2006-11-30 19:35:50 +01:00
|
|
|
}
|
|
|
|
|
download-from-binary-cache: parallelise fetching of NAR info files
Getting substitute information using the binary cache substituter has
non-trivial latency overhead. A package or NixOS system configuration
can have hundreds of dependencies, and in the worst case (when the
local info cache is empty) we have to do a separate HTTP request for
each of these. If the ping time to the server is t, getting N info
files will take tN seconds; e.g., with a ping time of 0.1s to
nixos.org, sequentially downloading 1000 info files (a typical NixOS
config) will take at least 100 seconds.
To fix this problem, the binary cache substituter can now perform
requests in parallel. This required changing the substituter
interface to support a function querySubstitutablePathInfos() that
queries multiple paths at the same time, and rewriting queryMissing()
to take advantage of parallelism. (Due to local caching,
parallelising queryMissing() is sufficient for most use cases, since
it's almost always called before building a derivation and thus fills
the local info cache.)
For example, parallelism speeds up querying all 1056 paths in a
particular NixOS system configuration from 116s to 2.6s. It works so
well because the eccentricity of the top-level derivation in the
dependency graph is only 9. So we only need 10 round-trips (when
using an unlimited number of parallel connections) to get everything.
Currently we do a maximum of 150 parallel connections to the server.
Thus it's important that the binary cache server (e.g. nixos.org) has
a high connection limit. Alternatively we could use HTTP pipelining,
but WWW::Curl doesn't support it and libcurl has a hard-coded limit of
5 requests per pipeline.
2012-07-07 01:08:20 +02:00
|
|
|
PathSet RemoteStore::querySubstitutablePaths(const PathSet& paths) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 12) {
|
2016-06-01 14:49:12 +02:00
|
|
|
PathSet res;
|
|
|
|
for (auto& i : paths) {
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopHasSubstitutes << i;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2020-05-20 23:27:37 +02:00
|
|
|
if (readInt(conn->from) != 0u) {
|
2016-06-01 14:49:12 +02:00
|
|
|
res.insert(i);
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
download-from-binary-cache: parallelise fetching of NAR info files
Getting substitute information using the binary cache substituter has
non-trivial latency overhead. A package or NixOS system configuration
can have hundreds of dependencies, and in the worst case (when the
local info cache is empty) we have to do a separate HTTP request for
each of these. If the ping time to the server is t, getting N info
files will take tN seconds; e.g., with a ping time of 0.1s to
nixos.org, sequentially downloading 1000 info files (a typical NixOS
config) will take at least 100 seconds.
To fix this problem, the binary cache substituter can now perform
requests in parallel. This required changing the substituter
interface to support a function querySubstitutablePathInfos() that
queries multiple paths at the same time, and rewriting queryMissing()
to take advantage of parallelism. (Due to local caching,
parallelising queryMissing() is sufficient for most use cases, since
it's almost always called before building a derivation and thus fills
the local info cache.)
For example, parallelism speeds up querying all 1056 paths in a
particular NixOS system configuration from 116s to 2.6s. It works so
well because the eccentricity of the top-level derivation in the
dependency graph is only 9. So we only need 10 round-trips (when
using an unlimited number of parallel connections) to get everything.
Currently we do a maximum of 150 parallel connections to the server.
Thus it's important that the binary cache server (e.g. nixos.org) has
a high connection limit. Alternatively we could use HTTP pipelining,
but WWW::Curl doesn't support it and libcurl has a hard-coded limit of
5 requests per pipeline.
2012-07-07 01:08:20 +02:00
|
|
|
}
|
2016-09-16 18:54:14 +02:00
|
|
|
return res;
|
2010-02-22 13:44:36 +01:00
|
|
|
}
|
2020-05-20 23:27:37 +02:00
|
|
|
conn->to << wopQuerySubstitutablePaths << paths;
|
|
|
|
conn.processStderr();
|
|
|
|
return readStorePaths<PathSet>(*this, conn->from);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 07:28:20 +01:00
|
|
|
void RemoteStore::querySubstitutablePathInfos(const PathSet& paths,
|
2016-02-23 15:00:59 +01:00
|
|
|
SubstitutablePathInfos& infos) {
|
|
|
|
if (paths.empty()) {
|
|
|
|
return;
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2016-11-09 18:57:22 +01:00
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 12) {
|
|
|
|
for (auto& i : paths) {
|
2012-07-11 16:43:24 +02:00
|
|
|
SubstitutablePathInfo info;
|
2016-11-09 18:57:22 +01:00
|
|
|
conn->to << wopQuerySubstitutablePathInfo << i;
|
2018-03-21 23:46:03 +01:00
|
|
|
conn.processStderr();
|
|
|
|
unsigned int reply = readInt(conn->from);
|
|
|
|
if (reply == 0) {
|
|
|
|
continue;
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2018-03-21 23:46:03 +01:00
|
|
|
info.deriver = readString(conn->from);
|
2020-05-20 23:27:37 +02:00
|
|
|
if (!info.deriver.empty()) {
|
2018-03-21 23:46:03 +01:00
|
|
|
assertStorePath(info.deriver);
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2016-11-09 18:57:22 +01:00
|
|
|
info.references = readStorePaths<PathSet>(*this, conn->from);
|
2016-02-23 15:00:59 +01:00
|
|
|
info.downloadSize = readLongLong(conn->from);
|
2016-11-09 18:57:22 +01:00
|
|
|
info.narSize = readLongLong(conn->from);
|
2015-07-17 19:24:28 +02:00
|
|
|
infos[i] = info;
|
2016-11-09 18:57:22 +01:00
|
|
|
}
|
2016-11-09 18:45:06 +01:00
|
|
|
|
2016-11-09 18:57:22 +01:00
|
|
|
} else {
|
|
|
|
conn->to << wopQuerySubstitutablePathInfos << paths;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2020-05-20 05:33:07 +02:00
|
|
|
auto count = readNum<size_t>(conn->from);
|
2016-11-09 18:57:22 +01:00
|
|
|
for (size_t n = 0; n < count; n++) {
|
|
|
|
Path path = readStorePath(*this, conn->from);
|
2017-07-04 14:47:59 +02:00
|
|
|
SubstitutablePathInfo& info(infos[path]);
|
|
|
|
info.deriver = readString(conn->from);
|
2020-05-20 23:27:37 +02:00
|
|
|
if (!info.deriver.empty()) {
|
2017-07-04 14:47:59 +02:00
|
|
|
assertStorePath(info.deriver);
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2016-11-09 18:57:22 +01:00
|
|
|
info.references = readStorePaths<PathSet>(*this, conn->from);
|
2018-03-26 23:36:30 +02:00
|
|
|
info.downloadSize = readLongLong(conn->from);
|
|
|
|
info.narSize = readLongLong(conn->from);
|
2016-11-09 18:57:22 +01:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
2016-05-04 13:36:54 +02:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:06:12 +01:00
|
|
|
void RemoteStore::queryPathInfoUncached(
|
|
|
|
const Path& path,
|
2012-10-03 21:09:18 +02:00
|
|
|
Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept {
|
|
|
|
try {
|
|
|
|
std::shared_ptr<ValidPathInfo> info;
|
2020-05-17 17:31:57 +02:00
|
|
|
{
|
2006-12-01 21:51:18 +01:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopQueryPathInfo << path;
|
2014-06-10 13:45:50 +02:00
|
|
|
try {
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2014-06-10 13:45:50 +02:00
|
|
|
} catch (Error& e) {
|
|
|
|
// Ugly backwards compatibility hack.
|
|
|
|
if (e.msg().find("is not valid") != std::string::npos) {
|
2018-10-16 23:36:15 +02:00
|
|
|
throw InvalidPath(e.what());
|
2020-05-19 21:47:23 +02:00
|
|
|
}
|
2014-06-10 13:45:50 +02:00
|
|
|
throw;
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
2018-04-09 21:26:16 +02:00
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 17) {
|
2020-08-02 00:32:00 +02:00
|
|
|
bool valid;
|
2018-04-09 21:26:16 +02:00
|
|
|
conn->from >> valid;
|
|
|
|
if (!valid) {
|
|
|
|
throw InvalidPath(format("path '%s' is not valid") % path);
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
2018-04-09 21:26:16 +02:00
|
|
|
info = std::make_shared<ValidPathInfo>();
|
|
|
|
info->path = path;
|
|
|
|
info->deriver = readString(conn->from);
|
2020-05-20 23:27:37 +02:00
|
|
|
if (!info->deriver.empty()) {
|
2018-04-09 21:26:16 +02:00
|
|
|
assertStorePath(info->deriver);
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2020-07-28 04:57:04 +02:00
|
|
|
auto hash_ = Hash::deserialize(readString(conn->from), htSHA256);
|
|
|
|
info->narHash = Hash::unwrap_throw(hash_);
|
2018-04-09 21:26:16 +02:00
|
|
|
info->references = readStorePaths<PathSet>(*this, conn->from);
|
|
|
|
conn->from >> info->registrationTime >> info->narSize;
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 16) {
|
|
|
|
conn->from >> info->ultimate;
|
|
|
|
info->sigs = readStrings<StringSet>(conn->from);
|
|
|
|
conn->from >> info->ca;
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
2014-06-10 13:45:50 +02:00
|
|
|
}
|
2018-03-27 22:16:01 +02:00
|
|
|
callback(std::move(info));
|
2016-02-23 16:40:16 +01:00
|
|
|
} catch (...) {
|
2018-03-27 22:16:01 +02:00
|
|
|
callback.rethrow();
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-30 23:43:55 +01:00
|
|
|
void RemoteStore::queryReferrers(const Path& path, PathSet& referrers) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopQueryReferrers << path;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2020-05-20 05:33:07 +02:00
|
|
|
auto referrers2 = readStorePaths<PathSet>(*this, conn->from);
|
2006-11-30 23:43:55 +01:00
|
|
|
referrers.insert(referrers2.begin(), referrers2.end());
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2012-12-20 18:41:44 +01:00
|
|
|
PathSet RemoteStore::queryValidDerivers(const Path& path) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopQueryValidDerivers << path;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-06-01 14:49:12 +02:00
|
|
|
return readStorePaths<PathSet>(*this, conn->from);
|
2006-11-30 19:35:50 +01:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2008-12-03 16:06:30 +01:00
|
|
|
PathSet RemoteStore::queryDerivationOutputs(const Path& path) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopQueryDerivationOutputs << path;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-06-01 14:49:12 +02:00
|
|
|
return readStorePaths<PathSet>(*this, conn->from);
|
2006-11-30 19:35:50 +01:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2014-02-18 01:01:14 +01:00
|
|
|
PathSet RemoteStore::queryDerivationOutputNames(const Path& path) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopQueryDerivationOutputNames << path;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-02-23 15:00:59 +01:00
|
|
|
return readStrings<PathSet>(conn->from);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2020-05-24 23:29:21 +02:00
|
|
|
Path RemoteStore::queryPathFromHashPart(const std::string& hashPart) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopQueryPathFromHashPart << hashPart;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-02-23 15:00:59 +01:00
|
|
|
Path path = readString(conn->from);
|
2012-07-18 00:55:39 +02:00
|
|
|
if (!path.empty()) {
|
|
|
|
assertStorePath(path);
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2012-07-18 00:55:39 +02:00
|
|
|
return path;
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
void RemoteStore::addToStore(const ValidPathInfo& info, Source& source,
|
2017-06-28 18:11:01 +02:00
|
|
|
RepairFlag repair, CheckSigsFlag checkSigs,
|
|
|
|
std::shared_ptr<FSAccessor> accessor) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 18) {
|
|
|
|
conn->to << wopImportPaths;
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2018-03-21 23:46:03 +01:00
|
|
|
auto source2 = sinkToSource([&](Sink& sink) {
|
|
|
|
sink << 1 // == path follows
|
2020-05-17 17:31:57 +02:00
|
|
|
;
|
2018-03-21 23:46:03 +01:00
|
|
|
copyNAR(source, sink);
|
2017-03-01 16:07:15 +01:00
|
|
|
sink << exportMagic << info.path << info.references << info.deriver
|
2018-03-21 23:46:03 +01:00
|
|
|
<< 0 // == no legacy signature
|
|
|
|
<< 0 // == no path follows
|
2020-05-17 17:31:57 +02:00
|
|
|
;
|
|
|
|
});
|
|
|
|
|
2020-05-20 05:33:07 +02:00
|
|
|
conn.processStderr(nullptr, source2.get());
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
auto importedPaths = readStorePaths<PathSet>(*this, conn->from);
|
|
|
|
assert(importedPaths.size() <= 1);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2016-04-05 15:30:22 +02:00
|
|
|
conn->to << wopAddToStoreNar << info.path << info.deriver
|
2017-07-04 14:47:59 +02:00
|
|
|
<< info.narHash.to_string(Base16, false) << info.references
|
2016-11-09 18:57:22 +01:00
|
|
|
<< info.registrationTime << info.narSize << info.ultimate
|
2017-03-01 16:07:15 +01:00
|
|
|
<< info.sigs << info.ca << repair << !checkSigs;
|
2016-02-23 15:00:59 +01:00
|
|
|
bool tunnel = GET_PROTOCOL_MINOR(conn->daemonVersion) >= 21;
|
|
|
|
if (!tunnel) {
|
|
|
|
copyNAR(source, conn->to);
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2020-05-20 05:33:07 +02:00
|
|
|
conn.processStderr(nullptr, tunnel ? &source : nullptr);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:29:21 +02:00
|
|
|
Path RemoteStore::addToStore(const std::string& name, const Path& _srcPath,
|
2015-12-02 18:13:33 +01:00
|
|
|
bool recursive, HashType hashAlgo,
|
|
|
|
PathFilter& filter, RepairFlag repair) {
|
2020-05-20 23:27:37 +02:00
|
|
|
if (repair != 0u) {
|
2015-12-02 18:13:33 +01:00
|
|
|
throw Error(
|
|
|
|
"repairing is not supported when building through the Nix daemon");
|
2020-05-19 21:47:23 +02:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2015-12-02 18:13:33 +01:00
|
|
|
auto conn(getConnection());
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2012-12-29 23:21:46 +01:00
|
|
|
Path srcPath(absPath(_srcPath));
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2012-12-29 23:21:46 +01:00
|
|
|
conn->to << wopAddToStore << name
|
2015-07-20 01:16:16 +02:00
|
|
|
<< ((hashAlgo == htSHA256 && recursive)
|
2020-05-17 17:31:57 +02:00
|
|
|
? 0
|
2012-12-29 23:21:46 +01:00
|
|
|
: 1) /* backwards compatibility hack */
|
2015-07-17 19:24:28 +02:00
|
|
|
<< (recursive ? 1 : 0) << printHashType(hashAlgo);
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2015-07-17 19:24:28 +02:00
|
|
|
try {
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to.written = 0;
|
|
|
|
conn->to.warn = true;
|
2017-04-26 18:38:16 +02:00
|
|
|
connections->incCapacity();
|
2020-05-17 17:31:57 +02:00
|
|
|
{
|
2018-04-16 11:14:39 +02:00
|
|
|
Finally cleanup([&]() { connections->decCapacity(); });
|
2016-02-23 15:00:59 +01:00
|
|
|
dumpPath(srcPath, conn->to, filter);
|
2012-12-29 23:21:46 +01:00
|
|
|
}
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to.warn = false;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2018-04-09 21:26:16 +02:00
|
|
|
} catch (SysError& e) {
|
2014-06-10 13:45:50 +02:00
|
|
|
/* Daemon closed while we were sending the path. Probably OOM
|
|
|
|
or I/O error. */
|
|
|
|
if (e.errNo == EPIPE) {
|
|
|
|
try {
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2014-06-10 13:45:50 +02:00
|
|
|
} catch (EndOfFile& e) {
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
2020-05-19 21:47:23 +02:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2016-06-01 14:49:12 +02:00
|
|
|
return readStorePath(*this, conn->from);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2020-05-24 23:29:21 +02:00
|
|
|
Path RemoteStore::addTextToStore(const std::string& name, const std::string& s,
|
2017-06-28 18:11:01 +02:00
|
|
|
const PathSet& references, RepairFlag repair) {
|
2020-05-20 23:27:37 +02:00
|
|
|
if (repair != 0u) {
|
2012-10-03 21:09:18 +02:00
|
|
|
throw Error(
|
|
|
|
"repairing is not supported when building through the Nix daemon");
|
2020-05-19 21:47:23 +02:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopAddTextToStore << name << s << references;
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-06-01 14:49:12 +02:00
|
|
|
return readStorePath(*this, conn->from);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2020-08-20 04:28:35 +02:00
|
|
|
absl::Status RemoteStore::buildPaths(std::ostream& /* log_sink */,
|
|
|
|
const PathSet& drvPaths,
|
|
|
|
BuildMode build_mode) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopBuildPaths;
|
2018-04-09 21:26:16 +02:00
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 13) {
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << drvPaths;
|
2018-04-09 21:26:16 +02:00
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 15) {
|
2020-08-20 04:28:35 +02:00
|
|
|
conn->to << build_mode;
|
2020-08-21 01:51:55 +02:00
|
|
|
} else if (build_mode != bmNormal) {
|
|
|
|
/* Old daemons did not take a 'buildMode' parameter, so we
|
|
|
|
need to validate it here on the client side. */
|
2020-08-14 04:06:23 +02:00
|
|
|
return absl::Status(
|
|
|
|
absl::StatusCode::kInvalidArgument,
|
2012-10-03 21:09:18 +02:00
|
|
|
"repairing or checking is not supported when building through the "
|
|
|
|
"Nix daemon");
|
2020-05-19 21:47:23 +02:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
} else {
|
2012-12-29 23:21:46 +01:00
|
|
|
/* For backwards compatibility with old daemons, strip output
|
|
|
|
identifiers. */
|
|
|
|
PathSet drvPaths2;
|
2015-07-17 19:24:28 +02:00
|
|
|
for (auto& i : drvPaths) {
|
2020-05-24 23:29:21 +02:00
|
|
|
drvPaths2.insert(std::string(i, 0, i.find('!')));
|
2020-05-19 20:04:08 +02:00
|
|
|
}
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << drvPaths2;
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-02-23 15:00:59 +01:00
|
|
|
readInt(conn->from);
|
2020-08-14 04:06:23 +02:00
|
|
|
|
|
|
|
return absl::OkStatus();
|
2006-11-30 19:35:50 +01:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
BuildResult RemoteStore::buildDerivation(const Path& drvPath,
|
|
|
|
const BasicDerivation& drv,
|
|
|
|
BuildMode buildMode) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopBuildDerivation << drvPath << drv << buildMode;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2015-09-03 12:56:59 +02:00
|
|
|
BuildResult res;
|
2020-08-02 00:32:00 +02:00
|
|
|
unsigned int status;
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->from >> status >> res.errorMsg;
|
2020-08-02 02:17:44 +02:00
|
|
|
res.status = static_cast<BuildResult::Status>(status);
|
2015-09-03 12:56:59 +02:00
|
|
|
return res;
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2006-11-30 23:43:55 +01:00
|
|
|
void RemoteStore::ensurePath(const Path& path) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopEnsurePath << path;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-02-23 15:00:59 +01:00
|
|
|
readInt(conn->from);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2006-12-02 17:41:36 +01:00
|
|
|
void RemoteStore::addTempRoot(const Path& path) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopAddTempRoot << path;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-02-23 15:00:59 +01:00
|
|
|
readInt(conn->from);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2006-12-05 00:29:16 +01:00
|
|
|
void RemoteStore::addIndirectRoot(const Path& path) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopAddIndirectRoot << path;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-02-23 15:00:59 +01:00
|
|
|
readInt(conn->from);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2006-12-02 17:41:36 +01:00
|
|
|
void RemoteStore::syncWithGC() {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopSyncWithGC;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-02-23 15:00:59 +01:00
|
|
|
readInt(conn->from);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2019-03-14 13:50:07 +01:00
|
|
|
Roots RemoteStore::findRoots(bool censor) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopFindRoots;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2020-05-20 05:33:07 +02:00
|
|
|
auto count = readNum<size_t>(conn->from);
|
2006-12-05 02:31:45 +01:00
|
|
|
Roots result;
|
2020-05-20 23:27:37 +02:00
|
|
|
while ((count--) != 0u) {
|
2016-02-23 15:00:59 +01:00
|
|
|
Path link = readString(conn->from);
|
2016-06-01 14:49:12 +02:00
|
|
|
Path target = readStorePath(*this, conn->from);
|
2019-03-01 00:54:52 +01:00
|
|
|
result[target].emplace(link);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
2006-12-05 02:31:45 +01:00
|
|
|
return result;
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2008-06-18 11:34:17 +02:00
|
|
|
void RemoteStore::collectGarbage(const GCOptions& options, GCResults& results) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2016-07-27 15:03:20 +02:00
|
|
|
conn->to << wopCollectGarbage << options.action << options.pathsToDelete
|
2020-05-20 23:27:37 +02:00
|
|
|
<< static_cast<uint64_t>(options.ignoreLiveness)
|
2016-07-27 15:03:20 +02:00
|
|
|
<< options.maxFreed
|
2009-11-20 18:12:38 +01:00
|
|
|
/* removed options */
|
2016-07-27 15:03:20 +02:00
|
|
|
<< 0 << 0 << 0;
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
results.paths = readStrings<PathSet>(conn->from);
|
|
|
|
results.bytesFreed = readLongLong(conn->from);
|
|
|
|
readLongLong(conn->from); // obsolete
|
2020-05-17 17:31:57 +02:00
|
|
|
|
|
|
|
{
|
2016-04-19 18:50:15 +02:00
|
|
|
auto state_(Store::state.lock());
|
|
|
|
state_->pathInfoCache.clear();
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-01 22:21:42 +02:00
|
|
|
void RemoteStore::optimiseStore() {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopOptimiseStore;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-02-23 15:00:59 +01:00
|
|
|
readInt(conn->from);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2017-06-28 18:11:01 +02:00
|
|
|
bool RemoteStore::verifyStore(bool checkContents, RepairFlag repair) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2020-05-20 23:27:37 +02:00
|
|
|
conn->to << wopVerifyStore << static_cast<uint64_t>(checkContents) << repair;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2020-05-20 23:27:37 +02:00
|
|
|
return readInt(conn->from) != 0u;
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2016-04-05 15:30:22 +02:00
|
|
|
void RemoteStore::addSignatures(const Path& storePath, const StringSet& sigs) {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2016-04-05 15:30:22 +02:00
|
|
|
conn->to << wopAddSignatures << storePath << sigs;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-02-23 15:00:59 +01:00
|
|
|
readInt(conn->from);
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
}
|
|
|
|
|
2006-11-30 23:43:55 +01:00
|
|
|
void RemoteStore::queryMissing(const PathSet& targets, PathSet& willBuild,
|
|
|
|
PathSet& willSubstitute, PathSet& unknown,
|
2017-04-06 18:40:19 +02:00
|
|
|
unsigned long long& downloadSize,
|
2006-11-30 23:43:55 +01:00
|
|
|
unsigned long long& narSize) {
|
2006-11-30 19:35:50 +01:00
|
|
|
{
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(getConnection());
|
2020-05-19 18:38:04 +02:00
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 19) {
|
2016-02-23 15:00:59 +01:00
|
|
|
// Don't hold the connection handle in the fallback case
|
|
|
|
// to prevent a deadlock.
|
2017-04-06 18:40:19 +02:00
|
|
|
goto fallback;
|
2020-05-19 18:38:04 +02:00
|
|
|
}
|
2016-02-23 15:00:59 +01:00
|
|
|
conn->to << wopQueryMissing << targets;
|
2018-10-16 23:36:15 +02:00
|
|
|
conn.processStderr();
|
2016-02-23 15:00:59 +01:00
|
|
|
willBuild = readStorePaths<PathSet>(*this, conn->from);
|
2017-04-06 18:40:19 +02:00
|
|
|
willSubstitute = readStorePaths<PathSet>(*this, conn->from);
|
|
|
|
unknown = readStorePaths<PathSet>(*this, conn->from);
|
|
|
|
conn->from >> downloadSize >> narSize;
|
2020-05-17 17:31:57 +02:00
|
|
|
return;
|
2006-11-30 19:35:50 +01:00
|
|
|
}
|
|
|
|
|
2017-04-06 18:40:19 +02:00
|
|
|
fallback:
|
2006-12-02 17:41:36 +01:00
|
|
|
return Store::queryMissing(targets, willBuild, willSubstitute, unknown,
|
2016-02-23 15:00:59 +01:00
|
|
|
downloadSize, narSize);
|
2006-12-02 17:41:36 +01:00
|
|
|
}
|
|
|
|
|
2016-09-02 20:15:04 +02:00
|
|
|
void RemoteStore::connect() { auto conn(getConnection()); }
|
2006-12-02 17:41:36 +01:00
|
|
|
|
2006-12-05 00:29:16 +01:00
|
|
|
unsigned int RemoteStore::getProtocol() {
|
2018-10-16 23:36:15 +02:00
|
|
|
auto conn(connections->get());
|
2016-02-23 15:00:59 +01:00
|
|
|
return conn->daemonVersion;
|
2006-12-05 00:29:16 +01:00
|
|
|
}
|
|
|
|
|
2017-09-14 18:10:38 +02:00
|
|
|
void RemoteStore::flushBadConnections() { connections->flushBad(); }
|
2006-12-05 00:29:16 +01:00
|
|
|
|
2006-12-02 17:41:36 +01:00
|
|
|
RemoteStore::Connection::~Connection() {
|
|
|
|
try {
|
2018-10-16 23:36:15 +02:00
|
|
|
to.flush();
|
|
|
|
} catch (...) {
|
|
|
|
ignoreException();
|
2006-12-02 17:41:36 +01:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
|
|
|
|
2006-12-05 02:31:45 +01:00
|
|
|
std::exception_ptr RemoteStore::Connection::processStderr(Sink* sink,
|
|
|
|
Source* source) {
|
2016-02-23 16:40:16 +01:00
|
|
|
to.flush();
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2006-12-05 02:31:45 +01:00
|
|
|
while (true) {
|
|
|
|
auto msg = readNum<uint64_t>(from);
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2007-02-21 18:34:02 +01:00
|
|
|
if (msg == STDERR_WRITE) {
|
2020-05-24 23:29:21 +02:00
|
|
|
std::string s = readString(from);
|
2020-05-20 23:27:37 +02:00
|
|
|
if (sink == nullptr) {
|
2016-06-01 14:49:12 +02:00
|
|
|
throw Error("no sink");
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2019-03-01 00:54:52 +01:00
|
|
|
(*sink)(s);
|
2006-12-05 02:31:45 +01:00
|
|
|
}
|
2016-04-19 18:50:15 +02:00
|
|
|
|
|
|
|
else if (msg == STDERR_READ) {
|
2020-05-20 23:27:37 +02:00
|
|
|
if (source == nullptr) {
|
2016-04-19 18:50:15 +02:00
|
|
|
throw Error("no source");
|
2020-05-19 19:55:58 +02:00
|
|
|
}
|
2020-05-20 05:33:07 +02:00
|
|
|
auto len = readNum<size_t>(from);
|
2016-04-19 18:50:15 +02:00
|
|
|
auto buf = std::make_unique<unsigned char[]>(len);
|
|
|
|
writeString(buf.get(), source->read(buf.get(), len), to);
|
2016-02-23 16:40:16 +01:00
|
|
|
to.flush();
|
2016-04-19 18:50:15 +02:00
|
|
|
}
|
2016-02-23 16:40:16 +01:00
|
|
|
|
2016-04-05 15:30:22 +02:00
|
|
|
else if (msg == STDERR_ERROR) {
|
2020-05-24 23:29:21 +02:00
|
|
|
std::string error = readString(from);
|
2017-04-06 18:40:19 +02:00
|
|
|
unsigned int status = readInt(from);
|
|
|
|
return std::make_exception_ptr(Error(status, error));
|
|
|
|
}
|
|
|
|
|
2020-05-19 02:02:44 +02:00
|
|
|
else if (msg == STDERR_NEXT) {
|
2020-05-24 02:36:11 +02:00
|
|
|
LOG(ERROR) << absl::StripTrailingAsciiWhitespace(readString(from));
|
2020-05-19 02:02:44 +02:00
|
|
|
}
|
2020-05-17 17:31:57 +02:00
|
|
|
|
2017-04-06 18:40:19 +02:00
|
|
|
else if (msg == STDERR_START_ACTIVITY) {
|
2020-05-19 05:51:45 +02:00
|
|
|
LOG(INFO) << readString(from);
|
2020-05-17 17:31:57 +02:00
|
|
|
}
|
2017-08-28 18:49:42 +02:00
|
|
|
|
2020-05-19 02:02:44 +02:00
|
|
|
else if (msg == STDERR_LAST) {
|
2011-12-15 00:30:06 +01:00
|
|
|
break;
|
2020-05-19 02:02:44 +02:00
|
|
|
}
|
2017-08-28 18:49:42 +02:00
|
|
|
|
2020-05-19 02:02:44 +02:00
|
|
|
else {
|
2018-10-16 23:36:15 +02:00
|
|
|
throw Error("got unknown message type %x from Nix daemon", msg);
|
2020-05-19 02:02:44 +02:00
|
|
|
}
|
2017-08-28 18:49:42 +02:00
|
|
|
}
|
2018-10-16 23:36:15 +02:00
|
|
|
|
|
|
|
return nullptr;
|
2006-12-03 03:08:13 +01:00
|
|
|
}
|
|
|
|
|
2006-11-30 19:35:50 +01:00
|
|
|
} // namespace nix
|