diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc index 771eb42ee561c87f6a8b72e9513616c34620e7d2..392945ca771de9b6253c99600fc7edb5884f074d 100644 --- a/src/libstore/http-binary-cache-store.cc +++ b/src/libstore/http-binary-cache-store.cc @@ -85,7 +85,10 @@ protected: }; -static RegisterStoreImplementation regStore([](const std::string & uri) -> std::shared_ptr<Store> { +static RegisterStoreImplementation regStore([]( + const std::string & uri, const StoreParams & params) + -> std::shared_ptr<Store> +{ if (std::string(uri, 0, 7) != "http://" && std::string(uri, 0, 8) != "https://") return 0; auto store = std::make_shared<HttpBinaryCacheStore>(std::shared_ptr<Store>(0), diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc index 7968c98b9558cfea215aed98c43080e18289d5c0..2ec9a0d1045c68977269cc5e49ccada2517945c7 100644 --- a/src/libstore/local-binary-cache-store.cc +++ b/src/libstore/local-binary-cache-store.cc @@ -16,6 +16,11 @@ public: void init() override; + std::string getUri() override + { + return "file://" + binaryCacheDir; + } + protected: bool fileExists(const std::string & path) override; @@ -78,7 +83,10 @@ ref<Store> openLocalBinaryCacheStore(std::shared_ptr<Store> localStore, return store; } -static RegisterStoreImplementation regStore([](const std::string & uri) -> std::shared_ptr<Store> { +static RegisterStoreImplementation regStore([]( + const std::string & uri, const StoreParams & params) + -> std::shared_ptr<Store> +{ if (std::string(uri, 0, 7) != "file://") return 0; return openLocalBinaryCacheStore(std::shared_ptr<Store>(0), settings.get("binary-cache-secret-key-file", string("")), diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 45ffbad67a58387dc8a938507b7fc887b044f598..01a11f11f65d20f176948c1381e274b9d75e6b4b 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -229,6 +229,12 @@ LocalStore::~LocalStore() } +std::string LocalStore::getUri() +{ + return "local"; +} + + int LocalStore::getSchema() { int curSchema = 0; diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index abc4f719be1e6fac0aeaa42efb24e72f222e69ab..6f2341decfbd95047604fdd0dcf9100d07103608 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -87,6 +87,8 @@ public: /* Implementations of abstract store API methods. */ + std::string getUri() override; + bool isValidPathUncached(const Path & path) override; PathSet queryValidPaths(const PathSet & paths) override; diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 4663291b9171b81e253432b7ceca0c017a17bee8..5a254a6104f40c881336c8a041d608d9da28cef0 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -49,6 +49,12 @@ RemoteStore::RemoteStore(size_t maxConnections) } +std::string RemoteStore::getUri() +{ + return "daemon"; +} + + ref<RemoteStore::Connection> RemoteStore::openConnection() { auto conn = make_ref<Connection>(); diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index 4ea8e8a5be4d9b303d1e21b677783a8fdf63b90c..8e45a7449e2ea7919952c089ecd14599892808ba 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -26,6 +26,8 @@ public: /* Implementations of abstract store API methods. */ + std::string getUri() override; + bool isValidPathUncached(const Path & path) override; PathSet queryValidPaths(const PathSet & paths) override; diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc index 6fadf7be28c9bf4fb97c933e1cde4a19c0f6c929..cd88a3271244df6e6ae91c03882a78e085f5d4d7 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -239,7 +239,10 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore }; -static RegisterStoreImplementation regStore([](const std::string & uri) -> std::shared_ptr<Store> { +static RegisterStoreImplementation regStore([]( + const std::string & uri, const StoreParams & params) + -> std::shared_ptr<Store> +{ if (std::string(uri, 0, 5) != "s3://") return 0; auto store = std::make_shared<S3BinaryCacheStoreImpl>(std::shared_ptr<Store>(0), settings.get("binary-cache-secret-key-file", string("")), diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 2763f5ad4199fba5914c80d3a213738139cb3fa1..463e132e029948320a722dc8085844b014d8a84f 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -461,10 +461,22 @@ namespace nix { RegisterStoreImplementation::Implementations * RegisterStoreImplementation::implementations = 0; -ref<Store> openStoreAt(const std::string & uri) +ref<Store> openStoreAt(const std::string & uri_) { + auto uri(uri_); + StoreParams params; + auto q = uri.find('?'); + if (q != std::string::npos) { + for (auto s : tokenizeString<Strings>(uri.substr(q + 1), "&")) { + auto e = s.find('='); + if (e != std::string::npos) + params[s.substr(0, e)] = s.substr(e + 1); + } + uri = uri_.substr(0, q); + } + for (auto fun : *RegisterStoreImplementation::implementations) { - auto store = fun(uri); + auto store = fun(uri, params); if (store) return ref<Store>(store); } @@ -478,7 +490,10 @@ ref<Store> openStore() } -static RegisterStoreImplementation regStore([](const std::string & uri) -> std::shared_ptr<Store> { +static RegisterStoreImplementation regStore([]( + const std::string & uri, const StoreParams & params) + -> std::shared_ptr<Store> +{ enum { mDaemon, mLocal, mAuto } mode; if (uri == "daemon") mode = mDaemon; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 87b8e884759c50be495e1a777f51ec0bfa81babe..cdde0be7b91cb93b97af0b15f6161623b96e0c53 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -192,7 +192,7 @@ public: virtual ~Store() { } - virtual std::string getUri(); + virtual std::string getUri() = 0; /* Check whether a path is valid. */ bool isValidPath(const Path & path); @@ -540,7 +540,10 @@ std::list<ref<Store>> getDefaultSubstituters(); /* Store implementation registration. */ -typedef std::function<std::shared_ptr<Store>(const std::string & uri)> OpenStore; +typedef std::map<std::string, std::string> StoreParams; + +typedef std::function<std::shared_ptr<Store>( + const std::string & uri, const StoreParams & params)> OpenStore; struct RegisterStoreImplementation {