forked from lix-project/lix
Merge pull request #3829 from obsidiansystems/remove-storetype-delegate-regStore
Remove storetype delegate reg store -- contains #3736
This commit is contained in:
commit
649d3aaf24
|
@ -97,7 +97,16 @@ RemoteStore::RemoteStore(const Params & params)
|
||||||
, RemoteStoreConfig(params)
|
, RemoteStoreConfig(params)
|
||||||
, connections(make_ref<Pool<Connection>>(
|
, connections(make_ref<Pool<Connection>>(
|
||||||
std::max(1, (int) maxConnections),
|
std::max(1, (int) maxConnections),
|
||||||
[this]() { return openConnectionWrapper(); },
|
[this]() {
|
||||||
|
auto conn = openConnectionWrapper();
|
||||||
|
try {
|
||||||
|
initConnection(*conn);
|
||||||
|
} catch (...) {
|
||||||
|
failed = true;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
|
},
|
||||||
[this](const ref<Connection> & r) {
|
[this](const ref<Connection> & r) {
|
||||||
return
|
return
|
||||||
r->to.good()
|
r->to.good()
|
||||||
|
@ -182,8 +191,6 @@ ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
|
||||||
|
|
||||||
conn->startTime = std::chrono::steady_clock::now();
|
conn->startTime = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
initConnection(*conn);
|
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,8 +106,6 @@ public:
|
||||||
|
|
||||||
void flushBadConnections();
|
void flushBadConnections();
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
struct Connection
|
struct Connection
|
||||||
{
|
{
|
||||||
AutoCloseFD fd;
|
AutoCloseFD fd;
|
||||||
|
@ -123,6 +121,8 @@ protected:
|
||||||
|
|
||||||
ref<Connection> openConnectionWrapper();
|
ref<Connection> openConnectionWrapper();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
virtual ref<Connection> openConnection() = 0;
|
virtual ref<Connection> openConnection() = 0;
|
||||||
|
|
||||||
void initConnection(Connection & conn);
|
void initConnection(Connection & conn);
|
||||||
|
|
|
@ -80,7 +80,6 @@ ref<RemoteStore::Connection> SSHStore::openConnection()
|
||||||
+ (remoteStore.get() == "" ? "" : " --store " + shellEscape(remoteStore.get())));
|
+ (remoteStore.get() == "" ? "" : " --store " + shellEscape(remoteStore.get())));
|
||||||
conn->to = FdSink(conn->sshConn->in.get());
|
conn->to = FdSink(conn->sshConn->in.get());
|
||||||
conn->from = FdSource(conn->sshConn->out.get());
|
conn->from = FdSource(conn->sshConn->out.get());
|
||||||
initConnection(*conn);
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1040,38 +1040,26 @@ static bool isNonUriPath(const std::string & spec) {
|
||||||
&& spec.find("/") != std::string::npos;
|
&& spec.find("/") != std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
StoreType getStoreType(const std::string & uri, const std::string & stateDir)
|
|
||||||
{
|
|
||||||
if (uri == "daemon") {
|
|
||||||
return tDaemon;
|
|
||||||
} else if (uri == "local" || isNonUriPath(uri)) {
|
|
||||||
return tLocal;
|
|
||||||
} else if (uri == "" || uri == "auto") {
|
|
||||||
if (access(stateDir.c_str(), R_OK | W_OK) == 0)
|
|
||||||
return tLocal;
|
|
||||||
else if (pathExists(settings.nixDaemonSocketFile))
|
|
||||||
return tDaemon;
|
|
||||||
else
|
|
||||||
return tLocal;
|
|
||||||
} else {
|
|
||||||
return tOther;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Store> openFromNonUri(const std::string & uri, const Store::Params & params)
|
std::shared_ptr<Store> openFromNonUri(const std::string & uri, const Store::Params & params)
|
||||||
{
|
{
|
||||||
switch (getStoreType(uri, get(params, "state").value_or(settings.nixStateDir))) {
|
if (uri == "" || uri == "auto") {
|
||||||
case tDaemon:
|
auto stateDir = get(params, "state").value_or(settings.nixStateDir);
|
||||||
return std::shared_ptr<Store>(std::make_shared<UDSRemoteStore>(params));
|
if (access(stateDir.c_str(), R_OK | W_OK) == 0)
|
||||||
case tLocal: {
|
return std::make_shared<LocalStore>(params);
|
||||||
Store::Params params2 = params;
|
else if (pathExists(settings.nixDaemonSocketFile))
|
||||||
if (isNonUriPath(uri)) {
|
return std::make_shared<UDSRemoteStore>(params);
|
||||||
params2["root"] = absPath(uri);
|
else
|
||||||
}
|
return std::make_shared<LocalStore>(params);
|
||||||
return std::shared_ptr<Store>(std::make_shared<LocalStore>(params2));
|
} else if (uri == "daemon") {
|
||||||
}
|
return std::make_shared<UDSRemoteStore>(params);
|
||||||
default:
|
} else if (uri == "local") {
|
||||||
return nullptr;
|
return std::make_shared<LocalStore>(params);
|
||||||
|
} else if (isNonUriPath(uri)) {
|
||||||
|
Store::Params params2 = params;
|
||||||
|
params2["root"] = absPath(uri);
|
||||||
|
return std::make_shared<LocalStore>(params2);
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -791,16 +791,6 @@ ref<Store> openStore(const std::string & uri = settings.storeUri.get(),
|
||||||
const Store::Params & extraParams = Store::Params());
|
const Store::Params & extraParams = Store::Params());
|
||||||
|
|
||||||
|
|
||||||
enum StoreType {
|
|
||||||
tDaemon,
|
|
||||||
tLocal,
|
|
||||||
tOther
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
StoreType getStoreType(const std::string & uri = settings.storeUri.get(),
|
|
||||||
const std::string & stateDir = settings.nixStateDir);
|
|
||||||
|
|
||||||
/* Return the default substituter stores, defined by the
|
/* Return the default substituter stores, defined by the
|
||||||
‘substituters’ option and various legacy options. */
|
‘substituters’ option and various legacy options. */
|
||||||
std::list<ref<Store>> getDefaultSubstituters();
|
std::list<ref<Store>> getDefaultSubstituters();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
#include "local-store.hh"
|
#include "local-store.hh"
|
||||||
|
#include "remote-store.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "serialise.hh"
|
#include "serialise.hh"
|
||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
|
@ -285,44 +286,28 @@ static int _main(int argc, char * * argv)
|
||||||
initPlugins();
|
initPlugins();
|
||||||
|
|
||||||
if (stdio) {
|
if (stdio) {
|
||||||
if (getStoreType() == tDaemon) {
|
if (auto store = openUncachedStore().dynamic_pointer_cast<RemoteStore>()) {
|
||||||
// Forward on this connection to the real daemon
|
auto conn = store->openConnectionWrapper();
|
||||||
auto socketPath = settings.nixDaemonSocketFile;
|
int from = conn->from.fd;
|
||||||
auto s = socket(PF_UNIX, SOCK_STREAM, 0);
|
int to = conn->to.fd;
|
||||||
if (s == -1)
|
|
||||||
throw SysError("creating Unix domain socket");
|
|
||||||
|
|
||||||
auto socketDir = dirOf(socketPath);
|
auto nfds = std::max(from, STDIN_FILENO) + 1;
|
||||||
if (chdir(socketDir.c_str()) == -1)
|
|
||||||
throw SysError("changing to socket directory '%1%'", socketDir);
|
|
||||||
|
|
||||||
auto socketName = std::string(baseNameOf(socketPath));
|
|
||||||
auto addr = sockaddr_un{};
|
|
||||||
addr.sun_family = AF_UNIX;
|
|
||||||
if (socketName.size() + 1 >= sizeof(addr.sun_path))
|
|
||||||
throw Error("socket name %1% is too long", socketName);
|
|
||||||
strcpy(addr.sun_path, socketName.c_str());
|
|
||||||
|
|
||||||
if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) == -1)
|
|
||||||
throw SysError("cannot connect to daemon at %1%", socketPath);
|
|
||||||
|
|
||||||
auto nfds = (s > STDIN_FILENO ? s : STDIN_FILENO) + 1;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(s, &fds);
|
FD_SET(from, &fds);
|
||||||
FD_SET(STDIN_FILENO, &fds);
|
FD_SET(STDIN_FILENO, &fds);
|
||||||
if (select(nfds, &fds, nullptr, nullptr, nullptr) == -1)
|
if (select(nfds, &fds, nullptr, nullptr, nullptr) == -1)
|
||||||
throw SysError("waiting for data from client or server");
|
throw SysError("waiting for data from client or server");
|
||||||
if (FD_ISSET(s, &fds)) {
|
if (FD_ISSET(from, &fds)) {
|
||||||
auto res = splice(s, nullptr, STDOUT_FILENO, nullptr, SSIZE_MAX, SPLICE_F_MOVE);
|
auto res = splice(from, nullptr, STDOUT_FILENO, nullptr, SSIZE_MAX, SPLICE_F_MOVE);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
throw SysError("splicing data from daemon socket to stdout");
|
throw SysError("splicing data from daemon socket to stdout");
|
||||||
else if (res == 0)
|
else if (res == 0)
|
||||||
throw EndOfFile("unexpected EOF from daemon socket");
|
throw EndOfFile("unexpected EOF from daemon socket");
|
||||||
}
|
}
|
||||||
if (FD_ISSET(STDIN_FILENO, &fds)) {
|
if (FD_ISSET(STDIN_FILENO, &fds)) {
|
||||||
auto res = splice(STDIN_FILENO, nullptr, s, nullptr, SSIZE_MAX, SPLICE_F_MOVE);
|
auto res = splice(STDIN_FILENO, nullptr, to, nullptr, SSIZE_MAX, SPLICE_F_MOVE);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
throw SysError("splicing data from stdin to daemon socket");
|
throw SysError("splicing data from stdin to daemon socket");
|
||||||
else if (res == 0)
|
else if (res == 0)
|
||||||
|
|
|
@ -49,9 +49,7 @@ struct CmdDoctor : StoreCommand
|
||||||
{
|
{
|
||||||
logger->log("Running checks against store uri: " + store->getUri());
|
logger->log("Running checks against store uri: " + store->getUri());
|
||||||
|
|
||||||
auto type = getStoreType();
|
if (store.dynamic_pointer_cast<LocalFSStore>()) {
|
||||||
|
|
||||||
if (type < tOther) {
|
|
||||||
success &= checkNixInPath();
|
success &= checkNixInPath();
|
||||||
success &= checkProfileRoots(store);
|
success &= checkProfileRoots(store);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ nix_tests = \
|
||||||
linux-sandbox.sh \
|
linux-sandbox.sh \
|
||||||
build-dry.sh \
|
build-dry.sh \
|
||||||
build-remote-input-addressed.sh \
|
build-remote-input-addressed.sh \
|
||||||
|
ssh-relay.sh \
|
||||||
nar-access.sh \
|
nar-access.sh \
|
||||||
structured-attrs.sh \
|
structured-attrs.sh \
|
||||||
fetchGit.sh \
|
fetchGit.sh \
|
||||||
|
|
16
tests/ssh-relay.sh
Normal file
16
tests/ssh-relay.sh
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
source common.sh
|
||||||
|
|
||||||
|
echo foo > $TEST_ROOT/hello.sh
|
||||||
|
|
||||||
|
ssh_localhost=ssh://localhost
|
||||||
|
remote_store=?remote-store=$ssh_localhost
|
||||||
|
|
||||||
|
store=$ssh_localhost
|
||||||
|
|
||||||
|
store+=$remote_store
|
||||||
|
store+=$remote_store
|
||||||
|
store+=$remote_store
|
||||||
|
|
||||||
|
out=$(nix add-to-store --store "$store" $TEST_ROOT/hello.sh)
|
||||||
|
|
||||||
|
[ foo = $(< $out) ]
|
Loading…
Reference in a new issue