Skip to content

Commit

Permalink
Convert UDSRemoteStore
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jul 18, 2024
1 parent 74620b9 commit 469ac00
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
34 changes: 13 additions & 21 deletions src/libstore/uds-remote-store.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "uds-remote-store.hh"
#include "unix-domain-socket.hh"
#include "worker-protocol.hh"
#include "store-registration.hh"

#include <sys/types.h>
#include <sys/stat.h>
Expand All @@ -20,13 +21,13 @@ namespace nix {
UDSRemoteStoreConfig::UDSRemoteStoreConfig(
std::string_view scheme,
std::string_view authority,
const Params & params)
const StoreReference::Params & params)
: StoreConfig(params)
, LocalFSStoreConfig(params)
, RemoteStoreConfig(params)
, path{authority.empty() ? settings.nixDaemonSocketFile : authority}
{
if (scheme != UDSRemoteStoreConfig::scheme) {
if (uriSchemes().count(std::string{scheme}) == 0) {
throw UsageError("Scheme must be 'unix'");
}
}
Expand All @@ -40,23 +41,14 @@ std::string UDSRemoteStoreConfig::doc()
}


// A bit gross that we now pass empty string but this is knowing that
// empty string will later default to the same nixDaemonSocketFile. Why
// don't we just wire it all through? I believe there are cases where it
// will live reload so we want to continue to account for that.
UDSRemoteStore::UDSRemoteStore(const Params & params)
: UDSRemoteStore(scheme, "", params)
{}


UDSRemoteStore::UDSRemoteStore(std::string_view scheme, std::string_view authority, const Params & params)
: StoreConfig(params)
, LocalFSStoreConfig(params)
, RemoteStoreConfig(params)
, UDSRemoteStoreConfig(scheme, authority, params)
, Store(params)
, LocalFSStore(params)
, RemoteStore(params)
UDSRemoteStore::UDSRemoteStore(const Config & config)
: Store::Config{config}
, LocalFSStore::Config{config}
, RemoteStore::Config{config}
, UDSRemoteStore::Config{config}
, Store(static_cast<const Store::Config &>(*this))
, LocalFSStore(static_cast<const LocalFSStore::Config &>(*this))
, RemoteStore(static_cast<const RemoteStore::Config &>(*this))
{
}

Expand All @@ -69,7 +61,7 @@ std::string UDSRemoteStore::getUri()
//
// unix:// with no path also works. Change what we return?
"daemon"
: std::string(scheme) + "://" + path;
: std::string(*uriSchemes().begin()) + "://" + path;
}


Expand Down Expand Up @@ -106,6 +98,6 @@ void UDSRemoteStore::addIndirectRoot(const Path & path)
}


static RegisterStoreImplementation<UDSRemoteStore, UDSRemoteStoreConfig> regUDSRemoteStore;
static RegisterStoreImplementation<UDSRemoteStore> regUDSRemoteStore;

}
30 changes: 17 additions & 13 deletions src/libstore/uds-remote-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@
namespace nix {

struct UDSRemoteStoreConfig :
virtual LocalFSStoreConfig,
virtual RemoteStoreConfig
virtual LocalFSStore::Config,
virtual RemoteStore::Config
{
// TODO(fzakaria): Delete this constructor once moved over to the factory pattern
// outlined in https://github.com/NixOS/nix/issues/10766
using LocalFSStoreConfig::LocalFSStoreConfig;
using RemoteStoreConfig::RemoteStoreConfig;
struct Descriptions :
virtual LocalFSStore::Config::Descriptions,
virtual RemoteStore::Config::Descriptions
{
Descriptions();
};

static const Descriptions descriptions;

/**
* @param authority is the socket path.
*/
UDSRemoteStoreConfig(
std::string_view scheme,
std::string_view authority,
const Params & params);
const StoreReference::Params & params);

const std::string name() override { return "Local Daemon Store"; }

Expand All @@ -36,20 +40,20 @@ struct UDSRemoteStoreConfig :
*/
Path path;

private:
static constexpr char const * scheme = "unix";

public:
static std::set<std::string> uriSchemes()
{ return {scheme}; }
{ return {"unix"}; }

ref<Store> openStore() const override;
};

struct UDSRemoteStore :
virtual UDSRemoteStoreConfig,
virtual IndirectRootStore,
virtual RemoteStore
{
UDSRemoteStore(const UDSRemoteStoreConfig &);
using Config = UDSRemoteStoreConfig;

UDSRemoteStore(const Config &);

std::string getUri() override;

Expand Down

0 comments on commit 469ac00

Please sign in to comment.