1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 08:31:16 +02:00

Allow parameters in store URIs

This is to allow store-specific configuration,
e.g. s3://my-cache?compression=bzip2&secret-key=/path/to/key.
This commit is contained in:
Eelco Dolstra 2016-04-29 16:26:16 +02:00
parent aa3bc3d5dc
commit 95d20dfde9
9 changed files with 56 additions and 8 deletions

View file

@ -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;