aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/ssh-store.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/ssh-store.cc')
-rw-r--r--src/libstore/ssh-store.cc54
1 files changed, 19 insertions, 35 deletions
diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc
index caae6b596..6d6eca98d 100644
--- a/src/libstore/ssh-store.cc
+++ b/src/libstore/ssh-store.cc
@@ -8,19 +8,25 @@
namespace nix {
-static std::string uriScheme = "ssh-ng://";
+struct SSHStoreConfig : virtual RemoteStoreConfig
+{
+ using RemoteStoreConfig::RemoteStoreConfig;
+
+ const Setting<Path> sshKey{(StoreConfig*) this, "", "ssh-key", "path to an SSH private key"};
+ const Setting<bool> compress{(StoreConfig*) this, false, "compress", "whether to compress the connection"};
+ const Setting<Path> remoteProgram{(StoreConfig*) this, "nix-daemon", "remote-program", "path to the nix-daemon executable on the remote system"};
+ const Setting<std::string> remoteStore{(StoreConfig*) this, "", "remote-store", "URI of the store on the remote system"};
+
+ const std::string name() override { return "SSH Store"; }
+};
-class SSHStore : public RemoteStore
+class SSHStore : public virtual RemoteStore, public virtual SSHStoreConfig
{
public:
- const Setting<Path> sshKey{(Store*) this, "", "ssh-key", "path to an SSH private key"};
- const Setting<bool> compress{(Store*) this, false, "compress", "whether to compress the connection"};
- const Setting<Path> remoteProgram{(Store*) this, "nix-daemon", "remote-program", "path to the nix-daemon executable on the remote system"};
- const Setting<std::string> remoteStore{(Store*) this, "", "remote-store", "URI of the store on the remote system"};
-
- SSHStore(const std::string & host, const Params & params)
- : Store(params)
+ SSHStore(const std::string & scheme, const std::string & host, const Params & params)
+ : StoreConfig(params)
+ , Store(params)
, RemoteStore(params)
, host(host)
, master(
@@ -32,18 +38,16 @@ public:
{
}
+ static std::set<std::string> uriSchemes() { return {"ssh-ng"}; }
+
std::string getUri() override
{
- return uriScheme + host;
+ return *uriSchemes().begin() + "://" + host;
}
bool sameMachine() override
{ return false; }
- void narFromPath(const StorePath & path, Sink & sink) override;
-
- ref<FSAccessor> getFSAccessor() override;
-
private:
struct Connection : RemoteStore::Connection
@@ -68,19 +72,6 @@ private:
};
};
-void SSHStore::narFromPath(const StorePath & path, Sink & sink)
-{
- auto conn(connections->get());
- conn->to << wopNarFromPath << printStorePath(path);
- conn->processStderr();
- copyNAR(conn->from, sink);
-}
-
-ref<FSAccessor> SSHStore::getFSAccessor()
-{
- return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()));
-}
-
ref<RemoteStore::Connection> SSHStore::openConnection()
{
auto conn = make_ref<Connection>();
@@ -89,16 +80,9 @@ ref<RemoteStore::Connection> SSHStore::openConnection()
+ (remoteStore.get() == "" ? "" : " --store " + shellEscape(remoteStore.get())));
conn->to = FdSink(conn->sshConn->in.get());
conn->from = FdSource(conn->sshConn->out.get());
- initConnection(*conn);
return conn;
}
-static RegisterStoreImplementation regStore([](
- const std::string & uri, const Store::Params & params)
- -> std::shared_ptr<Store>
-{
- if (std::string(uri, 0, uriScheme.size()) != uriScheme) return 0;
- return std::make_shared<SSHStore>(std::string(uri, uriScheme.size()), params);
-});
+static RegisterStoreImplementation<SSHStore, SSHStoreConfig> regStore;
}