Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move uriSchemes to *StoreConfig #11112

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libstore/dummy-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ struct DummyStoreConfig : virtual StoreConfig {
#include "dummy-store.md"
;
}

static std::set<std::string> uriSchemes() {
return {"dummy"};
}
};

struct DummyStore : public virtual DummyStoreConfig, public virtual Store
Expand Down Expand Up @@ -54,10 +58,6 @@ struct DummyStore : public virtual DummyStoreConfig, public virtual Store
return Trusted;
}

static std::set<std::string> uriSchemes() {
return {"dummy"};
}

std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
{ unsupported("queryPathFromHashPart"); }

Expand Down
8 changes: 0 additions & 8 deletions src/libstore/http-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public v
}
}

static std::set<std::string> uriSchemes()
{
static bool forceHttp = getEnv("_NIX_FORCE_HTTP") == "1";
auto ret = std::set<std::string>({"http", "https"});
if (forceHttp) ret.insert("file");
return ret;
}

protected:

void maybeDisable()
Expand Down
9 changes: 9 additions & 0 deletions src/libstore/http-binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ struct HttpBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
return "HTTP Binary Cache Store";
}

static std::set<std::string> uriSchemes()
{
static bool forceHttp = getEnv("_NIX_FORCE_HTTP") == "1";
auto ret = std::set<std::string>({"http", "https"});
if (forceHttp)
ret.insert("file");
return ret;
}

std::string doc() override;
};

Expand Down
4 changes: 2 additions & 2 deletions src/libstore/legacy-ssh-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct LegacySSHStoreConfig : virtual CommonSSHStoreConfig

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

static std::set<std::string> uriSchemes() { return {"ssh"}; }

std::string doc() override;
};

Expand All @@ -46,8 +48,6 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor

SSHMaster master;

static std::set<std::string> uriSchemes() { return {"ssh"}; }

LegacySSHStore(
std::string_view scheme,
std::string_view host,
Expand Down
4 changes: 1 addition & 3 deletions src/libstore/local-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ struct LocalBinaryCacheStore : virtual LocalBinaryCacheStoreConfig, virtual Bina
return "file://" + binaryCacheDir;
}

static std::set<std::string> uriSchemes();

protected:

bool fileExists(const std::string & path) override;
Expand Down Expand Up @@ -121,7 +119,7 @@ bool LocalBinaryCacheStore::fileExists(const std::string & path)
return pathExists(binaryCacheDir + "/" + path);
}

std::set<std::string> LocalBinaryCacheStore::uriSchemes()
std::set<std::string> LocalBinaryCacheStoreConfig::uriSchemes()
{
if (getEnv("_NIX_FORCE_HTTP") == "1")
return {};
Expand Down
2 changes: 2 additions & 0 deletions src/libstore/local-binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct LocalBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
return "Local Binary Cache Store";
}

static std::set<std::string> uriSchemes();

std::string doc() override;
};

Expand Down
10 changes: 5 additions & 5 deletions src/libstore/local-overlay-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig
return ExperimentalFeature::LocalOverlayStore;
}

static std::set<std::string> uriSchemes()
{
return { "local-overlay" };
}

std::string doc() override;

protected:
Expand Down Expand Up @@ -102,11 +107,6 @@ public:

LocalOverlayStore(std::string_view scheme, PathView path, const Params & params);

static std::set<std::string> uriSchemes()
{
return { "local-overlay" };
}

std::string getUri() override
{
return "local-overlay://";
Expand Down
6 changes: 3 additions & 3 deletions src/libstore/local-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ struct LocalStoreConfig : virtual LocalFSStoreConfig

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

static std::set<std::string> uriSchemes()
{ return {"local"}; }

std::string doc() override;
};

Expand Down Expand Up @@ -149,9 +152,6 @@ public:

~LocalStore();

static std::set<std::string> uriSchemes()
{ return {"local"}; }

/**
* Implementations of abstract store API methods.
*/
Expand Down
3 changes: 0 additions & 3 deletions src/libstore/s3-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,6 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStoreConfig, public virtual
{
return std::nullopt;
}

static std::set<std::string> uriSchemes() { return {"s3"}; }

};

static RegisterStoreImplementation<S3BinaryCacheStoreImpl, S3BinaryCacheStoreConfig> regS3BinaryCacheStore;
Expand Down
5 changes: 5 additions & 0 deletions src/libstore/s3-binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public:
return "S3 Binary Cache Store";
}

static std::set<std::string> uriSchemes()
{
return {"s3"};
}

std::string doc() override;
};

Expand Down
7 changes: 0 additions & 7 deletions src/libstore/ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class SSHStore : public virtual SSHStoreConfig, public virtual RemoteStore
{
}

static std::set<std::string> uriSchemes() { return {"ssh-ng"}; }

std::string getUri() override
{
return *uriSchemes().begin() + "://" + host;
Expand Down Expand Up @@ -154,11 +152,6 @@ class MountedSSHStore : public virtual MountedSSHStoreConfig, public virtual SSH
};
}

static std::set<std::string> uriSchemes()
{
return {"mounted-ssh-ng"};
}

std::string getUri() override
{
return *uriSchemes().begin() + "://" + host;
Expand Down
10 changes: 10 additions & 0 deletions src/libstore/ssh-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ struct SSHStoreConfig : virtual RemoteStoreConfig, virtual CommonSSHStoreConfig
return "Experimental SSH Store";
}

static std::set<std::string> uriSchemes()
{
return {"ssh-ng"};
}

std::string doc() override;
};

Expand All @@ -40,6 +45,11 @@ struct MountedSSHStoreConfig : virtual SSHStoreConfig, virtual LocalFSStoreConfi
return "Experimental SSH Store with filesystem mounted";
}

static std::set<std::string> uriSchemes()
{
return {"mounted-ssh-ng"};
}

std::string doc() override;

std::optional<ExperimentalFeature> experimentalFeature() const override
Expand Down
6 changes: 5 additions & 1 deletion src/libstore/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ public:

virtual ~Store() { }

/**
* @todo move to `StoreConfig` one we store enough information in
* those to recover the scheme and authority in all cases.
*/
virtual std::string getUri() = 0;

/**
Expand Down Expand Up @@ -897,7 +901,7 @@ struct Implementations
{
if (!registered) registered = new std::vector<StoreFactory>();
StoreFactory factory{
.uriSchemes = T::uriSchemes(),
.uriSchemes = TConfig::uriSchemes(),
.create =
([](auto scheme, auto uri, auto & params)
-> std::shared_ptr<Store>
Expand Down
7 changes: 4 additions & 3 deletions src/libstore/uds-remote-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ struct UDSRemoteStoreConfig : virtual LocalFSStoreConfig, virtual RemoteStoreCon

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

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

class UDSRemoteStore : public virtual UDSRemoteStoreConfig
Expand All @@ -59,9 +63,6 @@ public:

std::string getUri() override;

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

ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override
{ return LocalFSStore::getFSAccessor(requireValidPath); }

Expand Down
Loading