2006-11-30 20:54:43 +01:00
|
|
|
|
#include "serialise.hh"
|
|
|
|
|
#include "util.hh"
|
2006-11-30 19:35:50 +01:00
|
|
|
|
#include "remote-store.hh"
|
2006-11-30 21:13:59 +01:00
|
|
|
|
#include "worker-protocol.hh"
|
2006-11-30 21:45:20 +01:00
|
|
|
|
#include "archive.hh"
|
2013-08-07 13:51:55 +02:00
|
|
|
|
#include "affinity.hh"
|
2006-12-04 14:09:16 +01:00
|
|
|
|
#include "globals.hh"
|
2015-09-03 12:56:59 +02:00
|
|
|
|
#include "derivations.hh"
|
2016-02-23 15:00:59 +01:00
|
|
|
|
#include "pool.hh"
|
2006-11-30 19:35:50 +01:00
|
|
|
|
|
2006-12-03 03:08:13 +01:00
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
2006-12-03 03:36:44 +01:00
|
|
|
|
#include <sys/socket.h>
|
2006-12-04 15:21:39 +01:00
|
|
|
|
#include <sys/un.h>
|
2014-12-09 12:16:27 +01:00
|
|
|
|
#include <errno.h>
|
2006-12-03 03:08:13 +01:00
|
|
|
|
#include <fcntl.h>
|
2006-11-30 20:54:43 +01:00
|
|
|
|
#include <unistd.h>
|
2016-02-23 16:40:16 +01:00
|
|
|
|
|
2010-06-24 19:51:04 +02:00
|
|
|
|
#include <cstring>
|
2006-11-30 20:54:43 +01:00
|
|
|
|
|
2006-11-30 19:35:50 +01:00
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
2006-12-05 02:31:45 +01:00
|
|
|
|
Path readStorePath(Source & from)
|
|
|
|
|
{
|
|
|
|
|
Path path = readString(from);
|
|
|
|
|
assertStorePath(path);
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-12-16 23:31:25 +01:00
|
|
|
|
template<class T> T readStorePaths(Source & from)
|
2006-12-05 02:31:45 +01:00
|
|
|
|
{
|
2011-12-16 23:31:25 +01:00
|
|
|
|
T paths = readStrings<T>(from);
|
2015-07-17 19:24:28 +02:00
|
|
|
|
for (auto & i : paths) assertStorePath(i);
|
2006-12-05 02:31:45 +01:00
|
|
|
|
return paths;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-16 23:31:25 +01:00
|
|
|
|
template PathSet readStorePaths(Source & from);
|
|
|
|
|
|
2006-12-05 02:31:45 +01:00
|
|
|
|
|
2016-02-23 16:40:16 +01:00
|
|
|
|
RemoteStore::RemoteStore(size_t maxConnections)
|
2016-02-24 11:39:56 +01:00
|
|
|
|
: connections(make_ref<Pool<Connection>>(
|
|
|
|
|
maxConnections,
|
|
|
|
|
[this]() { return openConnection(); },
|
|
|
|
|
[](const ref<Connection> & r) { return r->to.good() && r->from.good(); }
|
|
|
|
|
))
|
2006-12-04 14:28:14 +01:00
|
|
|
|
{
|
2008-12-11 15:30:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-04-29 16:26:16 +02:00
|
|
|
|
std::string RemoteStore::getUri()
|
|
|
|
|
{
|
|
|
|
|
return "daemon";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-24 17:33:53 +01:00
|
|
|
|
ref<RemoteStore::Connection> RemoteStore::openConnection()
|
2008-12-11 15:30:25 +01:00
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn = make_ref<Connection>();
|
2008-12-11 15:30:25 +01:00
|
|
|
|
|
2016-01-31 10:19:14 +01:00
|
|
|
|
/* Connect to a daemon that does the privileged work for us. */
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->fd = socket(PF_UNIX, SOCK_STREAM, 0);
|
|
|
|
|
if (conn->fd == -1)
|
2006-12-04 15:21:39 +01:00
|
|
|
|
throw SysError("cannot create Unix domain socket");
|
2016-02-23 15:00:59 +01:00
|
|
|
|
closeOnExec(conn->fd);
|
2006-12-04 15:21:39 +01:00
|
|
|
|
|
2013-03-08 01:24:59 +01:00
|
|
|
|
string socketPath = settings.nixDaemonSocketFile;
|
2006-12-04 15:21:39 +01:00
|
|
|
|
|
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
|
addr.sun_family = AF_UNIX;
|
2016-03-23 17:16:16 +01:00
|
|
|
|
if (socketPath.size() + 1 >= sizeof(addr.sun_path))
|
|
|
|
|
throw Error(format("socket path ‘%1%’ is too long") % socketPath);
|
|
|
|
|
strcpy(addr.sun_path, socketPath.c_str());
|
2012-07-30 23:13:25 +02:00
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
if (connect(conn->fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
|
2014-08-20 17:00:17 +02:00
|
|
|
|
throw SysError(format("cannot connect to daemon at ‘%1%’") % socketPath);
|
2008-04-09 07:57:01 +02:00
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->from.fd = conn->fd;
|
|
|
|
|
conn->to.fd = conn->fd;
|
|
|
|
|
|
|
|
|
|
/* Send the magic greeting, check for the reply. */
|
|
|
|
|
try {
|
|
|
|
|
conn->to << WORKER_MAGIC_1;
|
|
|
|
|
conn->to.flush();
|
|
|
|
|
unsigned int magic = readInt(conn->from);
|
|
|
|
|
if (magic != WORKER_MAGIC_2) throw Error("protocol mismatch");
|
|
|
|
|
|
|
|
|
|
conn->daemonVersion = readInt(conn->from);
|
|
|
|
|
if (GET_PROTOCOL_MAJOR(conn->daemonVersion) != GET_PROTOCOL_MAJOR(PROTOCOL_VERSION))
|
|
|
|
|
throw Error("Nix daemon protocol version not supported");
|
|
|
|
|
conn->to << PROTOCOL_VERSION;
|
|
|
|
|
|
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 14) {
|
|
|
|
|
int cpu = settings.lockCPU ? lockToCurrentCPU() : -1;
|
|
|
|
|
if (cpu != -1)
|
|
|
|
|
conn->to << 1 << cpu;
|
|
|
|
|
else
|
|
|
|
|
conn->to << 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 11)
|
2016-02-24 17:33:53 +01:00
|
|
|
|
conn->to << false;
|
2016-02-23 15:00:59 +01:00
|
|
|
|
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
}
|
|
|
|
|
catch (Error & e) {
|
|
|
|
|
throw Error(format("cannot start daemon worker: %1%") % e.msg());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setOptions(conn);
|
|
|
|
|
|
|
|
|
|
return conn;
|
2006-11-30 19:35:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
void RemoteStore::setOptions(ref<Connection> conn)
|
2007-09-18 11:11:20 +02:00
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << wopSetOptions
|
2015-07-20 01:16:16 +02:00
|
|
|
|
<< settings.keepFailed
|
|
|
|
|
<< settings.keepGoing
|
|
|
|
|
<< settings.tryFallback
|
|
|
|
|
<< verbosity
|
|
|
|
|
<< settings.maxBuildJobs
|
|
|
|
|
<< settings.maxSilentTime;
|
2016-02-23 15:00:59 +01:00
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 2)
|
|
|
|
|
conn->to << settings.useBuildHook;
|
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 4)
|
2016-04-25 16:47:46 +02:00
|
|
|
|
conn->to << (settings.verboseBuild ? lvlError : lvlVomit)
|
2016-04-25 15:26:07 +02:00
|
|
|
|
<< 0 // obsolete log type
|
2016-04-25 16:35:28 +02:00
|
|
|
|
<< 0 /* obsolete print build trace */;
|
2016-02-23 15:00:59 +01:00
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 6)
|
|
|
|
|
conn->to << settings.buildCores;
|
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 10)
|
|
|
|
|
conn->to << settings.useSubstitutes;
|
2012-07-30 23:13:25 +02:00
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 12) {
|
2012-08-01 00:19:44 +02:00
|
|
|
|
Settings::SettingsMap overrides = settings.getOverrides();
|
2014-07-25 18:02:48 +02:00
|
|
|
|
if (overrides["ssh-auth-sock"] == "")
|
|
|
|
|
overrides["ssh-auth-sock"] = getEnv("SSH_AUTH_SOCK");
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << overrides.size();
|
2015-07-20 01:16:16 +02:00
|
|
|
|
for (auto & i : overrides)
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << i.first << i.second;
|
2012-08-01 00:19:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->processStderr();
|
2007-09-18 11:11:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-04-19 18:50:15 +02:00
|
|
|
|
bool RemoteStore::isValidPathUncached(const Path & path)
|
2006-11-30 19:35:50 +01:00
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopIsValidPath << path;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
unsigned int reply = readInt(conn->from);
|
2006-11-30 21:13:59 +01:00
|
|
|
|
return reply != 0;
|
2006-11-30 19:35:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-11 17:08:47 +02:00
|
|
|
|
PathSet RemoteStore::queryValidPaths(const PathSet & paths)
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
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)
|
|
|
|
|
if (isValidPath(i)) res.insert(i);
|
2012-07-11 17:08:47 +02:00
|
|
|
|
return res;
|
|
|
|
|
} else {
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << wopQueryValidPaths << paths;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
return readStorePaths<PathSet>(conn->from);
|
2012-07-11 17:08:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-11 16:49:04 +02:00
|
|
|
|
PathSet RemoteStore::queryAllValidPaths()
|
2008-01-29 19:17:36 +01:00
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopQueryAllValidPaths;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
return readStorePaths<PathSet>(conn->from);
|
2008-01-29 19:17:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-11 23:52:18 +02:00
|
|
|
|
PathSet RemoteStore::querySubstitutablePaths(const PathSet & paths)
|
2006-11-30 23:43:55 +01:00
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 12) {
|
2012-07-11 23:52:18 +02:00
|
|
|
|
PathSet res;
|
2015-07-17 19:24:28 +02:00
|
|
|
|
for (auto & i : paths) {
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << wopHasSubstitutes << i;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
if (readInt(conn->from)) res.insert(i);
|
2012-07-11 23:52:18 +02:00
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
} else {
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << wopQuerySubstitutablePaths << paths;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
return readStorePaths<PathSet>(conn->from);
|
2012-07-11 23:52:18 +02:00
|
|
|
|
}
|
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
|
|
|
|
void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
|
|
|
|
|
SubstitutablePathInfos & infos)
|
|
|
|
|
{
|
|
|
|
|
if (paths.empty()) return;
|
2012-07-11 16:43:24 +02:00
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
2012-07-30 23:13:25 +02:00
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 3) return;
|
2012-07-30 23:13:25 +02:00
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 12) {
|
2012-07-30 23:13:25 +02:00
|
|
|
|
|
2015-07-17 19:24:28 +02:00
|
|
|
|
for (auto & i : paths) {
|
2012-07-11 16:43:24 +02:00
|
|
|
|
SubstitutablePathInfo info;
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << wopQuerySubstitutablePathInfo << i;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
unsigned int reply = readInt(conn->from);
|
2012-07-11 16:43:24 +02:00
|
|
|
|
if (reply == 0) continue;
|
2016-02-23 15:00:59 +01:00
|
|
|
|
info.deriver = readString(conn->from);
|
2012-07-11 16:43:24 +02:00
|
|
|
|
if (info.deriver != "") assertStorePath(info.deriver);
|
2016-02-23 15:00:59 +01:00
|
|
|
|
info.references = readStorePaths<PathSet>(conn->from);
|
|
|
|
|
info.downloadSize = readLongLong(conn->from);
|
|
|
|
|
info.narSize = GET_PROTOCOL_MINOR(conn->daemonVersion) >= 7 ? readLongLong(conn->from) : 0;
|
2015-07-17 19:24:28 +02:00
|
|
|
|
infos[i] = info;
|
2012-07-11 16:43:24 +02:00
|
|
|
|
}
|
2012-07-30 23:13:25 +02:00
|
|
|
|
|
2012-07-11 16:43:24 +02:00
|
|
|
|
} else {
|
2012-07-30 23:13:25 +02:00
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << wopQuerySubstitutablePathInfos << paths;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
unsigned int count = readInt(conn->from);
|
2012-07-11 16:43:24 +02:00
|
|
|
|
for (unsigned int n = 0; n < count; n++) {
|
2016-02-23 15:00:59 +01:00
|
|
|
|
Path path = readStorePath(conn->from);
|
2012-07-11 16:43:24 +02:00
|
|
|
|
SubstitutablePathInfo & info(infos[path]);
|
2016-02-23 15:00:59 +01:00
|
|
|
|
info.deriver = readString(conn->from);
|
2012-07-11 16:43:24 +02:00
|
|
|
|
if (info.deriver != "") assertStorePath(info.deriver);
|
2016-02-23 15:00:59 +01:00
|
|
|
|
info.references = readStorePaths<PathSet>(conn->from);
|
|
|
|
|
info.downloadSize = readLongLong(conn->from);
|
|
|
|
|
info.narSize = readLongLong(conn->from);
|
2012-07-11 16:43:24 +02:00
|
|
|
|
}
|
2012-07-30 23:13:25 +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-04-19 18:50:15 +02:00
|
|
|
|
std::shared_ptr<ValidPathInfo> RemoteStore::queryPathInfoUncached(const Path & path)
|
2010-11-16 18:11:46 +01:00
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopQueryPathInfo << path;
|
2016-04-20 15:28:07 +02:00
|
|
|
|
try {
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
} catch (Error & e) {
|
|
|
|
|
// Ugly backwards compatibility hack.
|
|
|
|
|
if (e.msg().find("is not valid") != std::string::npos)
|
|
|
|
|
throw InvalidPath(e.what());
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 17) {
|
|
|
|
|
bool valid = readInt(conn->from) != 0;
|
|
|
|
|
if (!valid) throw InvalidPath(format("path ‘%s’ is not valid") % path);
|
|
|
|
|
}
|
2016-04-19 18:50:15 +02:00
|
|
|
|
auto info = std::make_shared<ValidPathInfo>();
|
|
|
|
|
info->path = path;
|
|
|
|
|
info->deriver = readString(conn->from);
|
|
|
|
|
if (info->deriver != "") assertStorePath(info->deriver);
|
|
|
|
|
info->narHash = parseHash(htSHA256, readString(conn->from));
|
|
|
|
|
info->references = readStorePaths<PathSet>(conn->from);
|
|
|
|
|
info->registrationTime = readInt(conn->from);
|
|
|
|
|
info->narSize = readLongLong(conn->from);
|
2016-03-30 17:35:48 +02:00
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 16) {
|
2016-04-19 18:50:15 +02:00
|
|
|
|
info->ultimate = readInt(conn->from) != 0;
|
|
|
|
|
info->sigs = readStrings<StringSet>(conn->from);
|
2016-03-30 17:35:48 +02:00
|
|
|
|
}
|
2010-11-17 13:08:01 +01:00
|
|
|
|
return info;
|
2010-11-16 18:11:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-30 23:43:55 +01:00
|
|
|
|
void RemoteStore::queryReferrers(const Path & path,
|
2006-11-30 19:35:50 +01:00
|
|
|
|
PathSet & referrers)
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopQueryReferrers << path;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
PathSet referrers2 = readStorePaths<PathSet>(conn->from);
|
2006-11-30 23:43:55 +01:00
|
|
|
|
referrers.insert(referrers2.begin(), referrers2.end());
|
2006-11-30 19:35:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-12-20 18:41:44 +01:00
|
|
|
|
PathSet RemoteStore::queryValidDerivers(const Path & path)
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopQueryValidDerivers << path;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
return readStorePaths<PathSet>(conn->from);
|
2012-12-20 18:41:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-02-22 13:44:36 +01:00
|
|
|
|
PathSet RemoteStore::queryDerivationOutputs(const Path & path)
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopQueryDerivationOutputs << path;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
return readStorePaths<PathSet>(conn->from);
|
2010-02-22 13:44:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-06 07:28:20 +01:00
|
|
|
|
PathSet RemoteStore::queryDerivationOutputNames(const Path & path)
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopQueryDerivationOutputNames << path;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
return readStrings<PathSet>(conn->from);
|
2011-11-06 07:28:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-18 00:55:39 +02:00
|
|
|
|
Path RemoteStore::queryPathFromHashPart(const string & hashPart)
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopQueryPathFromHashPart << hashPart;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
Path path = readString(conn->from);
|
2012-07-18 00:55:39 +02:00
|
|
|
|
if (!path.empty()) assertStorePath(path);
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-05-31 11:18:45 +02:00
|
|
|
|
void RemoteStore::addToStore(const ValidPathInfo & info, const std::string & nar,
|
|
|
|
|
bool repair, bool dontCheckSigs)
|
2016-05-04 13:36:54 +02:00
|
|
|
|
{
|
|
|
|
|
throw Error("RemoteStore::addToStore() not implemented");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-03-25 17:06:12 +01:00
|
|
|
|
Path RemoteStore::addToStore(const string & name, const Path & _srcPath,
|
2012-10-03 21:09:18 +02:00
|
|
|
|
bool recursive, HashType hashAlgo, PathFilter & filter, bool repair)
|
2006-11-30 19:35:50 +01:00
|
|
|
|
{
|
2012-10-03 21:09:18 +02:00
|
|
|
|
if (repair) throw Error("repairing is not supported when building through the Nix daemon");
|
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
2012-07-30 23:13:25 +02:00
|
|
|
|
|
2006-12-01 21:51:18 +01:00
|
|
|
|
Path srcPath(absPath(_srcPath));
|
2011-12-01 14:48:48 +01:00
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << wopAddToStore << name
|
2015-07-20 01:16:16 +02:00
|
|
|
|
<< ((hashAlgo == htSHA256 && recursive) ? 0 : 1) /* backwards compatibility hack */
|
|
|
|
|
<< (recursive ? 1 : 0)
|
|
|
|
|
<< printHashType(hashAlgo);
|
2014-06-10 13:45:50 +02:00
|
|
|
|
|
|
|
|
|
try {
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to.written = 0;
|
|
|
|
|
conn->to.warn = true;
|
2016-03-22 14:21:45 +01:00
|
|
|
|
dumpPath(srcPath, conn->to, filter);
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to.warn = false;
|
|
|
|
|
conn->processStderr();
|
2014-06-10 13:45:50 +02:00
|
|
|
|
} catch (SysError & e) {
|
|
|
|
|
/* Daemon closed while we were sending the path. Probably OOM
|
|
|
|
|
or I/O error. */
|
|
|
|
|
if (e.errNo == EPIPE)
|
|
|
|
|
try {
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->processStderr();
|
2014-06-10 13:45:50 +02:00
|
|
|
|
} catch (EndOfFile & e) { }
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
return readStorePath(conn->from);
|
2006-11-30 19:35:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-12-03 16:06:30 +01:00
|
|
|
|
Path RemoteStore::addTextToStore(const string & name, const string & s,
|
2012-10-03 21:09:18 +02:00
|
|
|
|
const PathSet & references, bool repair)
|
2006-11-30 19:35:50 +01:00
|
|
|
|
{
|
2012-10-03 21:09:18 +02:00
|
|
|
|
if (repair) throw Error("repairing is not supported when building through the Nix daemon");
|
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopAddTextToStore << name << s << references;
|
2012-07-30 23:13:25 +02:00
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->processStderr();
|
|
|
|
|
return readStorePath(conn->from);
|
2006-11-30 19:35:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-02-18 01:01:14 +01:00
|
|
|
|
void RemoteStore::buildPaths(const PathSet & drvPaths, BuildMode buildMode)
|
2006-11-30 19:35:50 +01:00
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopBuildPaths;
|
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 13) {
|
|
|
|
|
conn->to << drvPaths;
|
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 15)
|
|
|
|
|
conn->to << buildMode;
|
2015-12-02 18:13:33 +01:00
|
|
|
|
else
|
|
|
|
|
/* Old daemons did not take a 'buildMode' parameter, so we
|
|
|
|
|
need to validate it here on the client side. */
|
|
|
|
|
if (buildMode != bmNormal)
|
|
|
|
|
throw Error("repairing or checking is not supported when building through the Nix daemon");
|
|
|
|
|
} 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)
|
|
|
|
|
drvPaths2.insert(string(i, 0, i.find('!')));
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << drvPaths2;
|
2012-12-29 23:21:46 +01:00
|
|
|
|
}
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->processStderr();
|
|
|
|
|
readInt(conn->from);
|
2006-11-30 19:35:50 +01: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)
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopBuildDerivation << drvPath << drv << buildMode;
|
|
|
|
|
conn->processStderr();
|
2015-09-03 12:56:59 +02:00
|
|
|
|
BuildResult res;
|
|
|
|
|
unsigned int status;
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->from >> status >> res.errorMsg;
|
2015-09-03 12:56:59 +02:00
|
|
|
|
res.status = (BuildResult::Status) status;
|
|
|
|
|
return res;
|
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::ensurePath(const Path & path)
|
2006-11-30 19:35:50 +01:00
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopEnsurePath << path;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
readInt(conn->from);
|
2006-11-30 19:35:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-02 17:41:36 +01:00
|
|
|
|
void RemoteStore::addTempRoot(const Path & path)
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopAddTempRoot << path;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
readInt(conn->from);
|
2006-12-02 17:41:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-05 00:29:16 +01:00
|
|
|
|
void RemoteStore::addIndirectRoot(const Path & path)
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopAddIndirectRoot << path;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
readInt(conn->from);
|
2006-12-05 00:29:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-02 17:41:36 +01:00
|
|
|
|
void RemoteStore::syncWithGC()
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopSyncWithGC;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
readInt(conn->from);
|
2006-12-02 17:41:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-05 02:31:45 +01:00
|
|
|
|
Roots RemoteStore::findRoots()
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopFindRoots;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
unsigned int count = readInt(conn->from);
|
2006-12-05 02:31:45 +01:00
|
|
|
|
Roots result;
|
|
|
|
|
while (count--) {
|
2016-02-23 15:00:59 +01:00
|
|
|
|
Path link = readString(conn->from);
|
|
|
|
|
Path target = readStorePath(conn->from);
|
2006-12-05 02:31:45 +01:00
|
|
|
|
result[link] = target;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-06-18 11:34:17 +02:00
|
|
|
|
void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
|
2006-12-05 03:18:46 +01:00
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
2012-07-30 23:13:25 +02:00
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << wopCollectGarbage << options.action << options.pathsToDelete << options.ignoreLiveness
|
2015-07-20 01:16:16 +02:00
|
|
|
|
<< options.maxFreed << 0;
|
2016-02-23 15:00:59 +01:00
|
|
|
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 5)
|
2009-11-20 18:12:38 +01:00
|
|
|
|
/* removed options */
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->to << 0 << 0;
|
2012-07-30 23:13:25 +02:00
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
conn->processStderr();
|
2012-07-30 23:13:25 +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
|
2016-04-19 18:50:15 +02:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto state_(Store::state.lock());
|
|
|
|
|
state_->pathInfoCache.clear();
|
|
|
|
|
}
|
2006-12-05 03:18:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-09-01 22:21:42 +02:00
|
|
|
|
void RemoteStore::optimiseStore()
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopOptimiseStore;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
readInt(conn->from);
|
2014-09-01 22:21:42 +02:00
|
|
|
|
}
|
2010-05-04 12:45:10 +02:00
|
|
|
|
|
2016-04-08 18:16:53 +02:00
|
|
|
|
|
2015-06-01 23:20:11 +02:00
|
|
|
|
bool RemoteStore::verifyStore(bool checkContents, bool repair)
|
|
|
|
|
{
|
2016-02-23 15:00:59 +01:00
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopVerifyStore << checkContents << repair;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
return readInt(conn->from) != 0;
|
2015-06-01 23:20:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 16:40:16 +01:00
|
|
|
|
|
2016-04-05 15:30:22 +02:00
|
|
|
|
void RemoteStore::addSignatures(const Path & storePath, const StringSet & sigs)
|
|
|
|
|
{
|
|
|
|
|
auto conn(connections->get());
|
|
|
|
|
conn->to << wopAddSignatures << storePath << sigs;
|
|
|
|
|
conn->processStderr();
|
|
|
|
|
readInt(conn->from);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-23 16:40:16 +01:00
|
|
|
|
RemoteStore::Connection::~Connection()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
to.flush();
|
|
|
|
|
fd.close();
|
|
|
|
|
} catch (...) {
|
|
|
|
|
ignoreException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-23 15:00:59 +01:00
|
|
|
|
void RemoteStore::Connection::processStderr(Sink * sink, Source * source)
|
2006-12-03 03:08:13 +01:00
|
|
|
|
{
|
2011-12-15 00:30:06 +01:00
|
|
|
|
to.flush();
|
2006-12-03 03:08:13 +01:00
|
|
|
|
unsigned int msg;
|
2007-02-21 18:34:02 +01:00
|
|
|
|
while ((msg = readInt(from)) == STDERR_NEXT
|
|
|
|
|
|| msg == STDERR_READ || msg == STDERR_WRITE) {
|
|
|
|
|
if (msg == STDERR_WRITE) {
|
|
|
|
|
string s = readString(from);
|
2007-02-21 17:34:00 +01:00
|
|
|
|
if (!sink) throw Error("no sink");
|
2016-05-04 15:46:25 +02:00
|
|
|
|
(*sink)(s);
|
2007-02-21 17:34:00 +01:00
|
|
|
|
}
|
2007-02-21 18:34:02 +01:00
|
|
|
|
else if (msg == STDERR_READ) {
|
|
|
|
|
if (!source) throw Error("no source");
|
2011-12-16 20:44:13 +01:00
|
|
|
|
size_t len = readInt(from);
|
2007-02-21 18:34:02 +01:00
|
|
|
|
unsigned char * buf = new unsigned char[len];
|
|
|
|
|
AutoDeleteArray<unsigned char> d(buf);
|
2011-12-16 23:31:25 +01:00
|
|
|
|
writeString(buf, source->read(buf, len), to);
|
2011-12-15 00:30:06 +01:00
|
|
|
|
to.flush();
|
2007-02-21 18:34:02 +01:00
|
|
|
|
}
|
2016-04-25 15:26:07 +02:00
|
|
|
|
else
|
|
|
|
|
printMsg(lvlError, chomp(readString(from)));
|
2006-12-03 03:08:13 +01:00
|
|
|
|
}
|
2010-12-17 12:28:26 +01:00
|
|
|
|
if (msg == STDERR_ERROR) {
|
|
|
|
|
string error = readString(from);
|
|
|
|
|
unsigned int status = GET_PROTOCOL_MINOR(daemonVersion) >= 8 ? readInt(from) : 1;
|
2011-04-19 12:44:44 +02:00
|
|
|
|
throw Error(format("%1%") % error, status);
|
2010-12-17 12:28:26 +01:00
|
|
|
|
}
|
2006-12-03 03:08:13 +01:00
|
|
|
|
else if (msg != STDERR_LAST)
|
|
|
|
|
throw Error("protocol error processing standard error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-30 19:35:50 +01:00
|
|
|
|
}
|