mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-15 18:56:16 +02:00
470c0501eb
In particular `local://<path>` and `unix://` (without any path) now work, and mean the same things as `local` and `daemon`, respectively. We thus now have the opportunity to desguar `local` and `daemon` early. This will allow me to make a change to https://github.com/NixOS/nix/pull/9839 requested during review to desugar those earlier. Co-authored-by: Théophane Hufschmitt <7226587+thufschmitt@users.noreply.github.com>
99 lines
1.9 KiB
C++
99 lines
1.9 KiB
C++
#include "uds-remote-store.hh"
|
|
#include "unix-domain-socket.hh"
|
|
#include "worker-protocol.hh"
|
|
|
|
#include <cstring>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
#ifdef _WIN32
|
|
# include <winsock2.h>
|
|
# include <afunix.h>
|
|
#else
|
|
# include <sys/socket.h>
|
|
# include <sys/un.h>
|
|
#endif
|
|
|
|
namespace nix {
|
|
|
|
std::string UDSRemoteStoreConfig::doc()
|
|
{
|
|
return
|
|
#include "uds-remote-store.md"
|
|
;
|
|
}
|
|
|
|
|
|
UDSRemoteStore::UDSRemoteStore(const Params & params)
|
|
: StoreConfig(params)
|
|
, LocalFSStoreConfig(params)
|
|
, RemoteStoreConfig(params)
|
|
, UDSRemoteStoreConfig(params)
|
|
, Store(params)
|
|
, LocalFSStore(params)
|
|
, RemoteStore(params)
|
|
{
|
|
}
|
|
|
|
|
|
UDSRemoteStore::UDSRemoteStore(
|
|
std::string_view scheme,
|
|
PathView socket_path,
|
|
const Params & params)
|
|
: UDSRemoteStore(params)
|
|
{
|
|
if (!socket_path.empty())
|
|
path.emplace(socket_path);
|
|
}
|
|
|
|
|
|
std::string UDSRemoteStore::getUri()
|
|
{
|
|
if (path) {
|
|
return std::string("unix://") + *path;
|
|
} else {
|
|
// unix:// with no path also works. Change what we return?
|
|
return "daemon";
|
|
}
|
|
}
|
|
|
|
|
|
void UDSRemoteStore::Connection::closeWrite()
|
|
{
|
|
shutdown(toSocket(fd.get()), SHUT_WR);
|
|
}
|
|
|
|
|
|
ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
|
|
{
|
|
auto conn = make_ref<Connection>();
|
|
|
|
/* Connect to a daemon that does the privileged work for us. */
|
|
conn->fd = createUnixDomainSocket();
|
|
|
|
nix::connect(toSocket(conn->fd.get()), path ? *path : settings.nixDaemonSocketFile);
|
|
|
|
conn->from.fd = conn->fd.get();
|
|
conn->to.fd = conn->fd.get();
|
|
|
|
conn->startTime = std::chrono::steady_clock::now();
|
|
|
|
return conn;
|
|
}
|
|
|
|
|
|
void UDSRemoteStore::addIndirectRoot(const Path & path)
|
|
{
|
|
auto conn(getConnection());
|
|
conn->to << WorkerProto::Op::AddIndirectRoot << path;
|
|
conn.processStderr();
|
|
readInt(conn->from);
|
|
}
|
|
|
|
|
|
static RegisterStoreImplementation<UDSRemoteStore, UDSRemoteStoreConfig> regUDSRemoteStore;
|
|
|
|
}
|