1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 08:31:16 +02:00
This commit is contained in:
Eelco Dolstra 2016-11-09 18:57:22 +01:00
commit 4b8f1b0ec0
15 changed files with 465 additions and 91 deletions

View file

@ -606,7 +606,7 @@ namespace nix {
RegisterStoreImplementation::Implementations * RegisterStoreImplementation::implementations = 0;
ref<Store> openStoreAt(const std::string & uri_)
ref<Store> openStore(const std::string & uri_)
{
auto uri(uri_);
Store::Params params;
@ -629,9 +629,22 @@ ref<Store> openStoreAt(const std::string & uri_)
}
ref<Store> openStore()
StoreType getStoreType(const std::string & uri, const std::string & stateDir)
{
return openStoreAt(getEnv("NIX_REMOTE"));
if (uri == "daemon") {
return tDaemon;
} else if (uri == "local") {
return tLocal;
} else if (uri == "") {
if (access(stateDir.c_str(), R_OK | W_OK) == 0)
return tLocal;
else if (pathExists(settings.nixDaemonSocketFile))
return tDaemon;
else
return tLocal;
} else {
return tOther;
}
}
@ -639,26 +652,14 @@ static RegisterStoreImplementation regStore([](
const std::string & uri, const Store::Params & params)
-> std::shared_ptr<Store>
{
enum { mDaemon, mLocal, mAuto } mode;
if (uri == "daemon") mode = mDaemon;
else if (uri == "local") mode = mLocal;
else if (uri == "") mode = mAuto;
else return 0;
if (mode == mAuto) {
auto stateDir = get(params, "state", settings.nixStateDir);
if (access(stateDir.c_str(), R_OK | W_OK) == 0)
mode = mLocal;
else if (pathExists(settings.nixDaemonSocketFile))
mode = mDaemon;
else
mode = mLocal;
switch (getStoreType(uri, get(params, "state", settings.nixStateDir))) {
case tDaemon:
return std::shared_ptr<Store>(std::make_shared<UDSRemoteStore>(params));
case tLocal:
return std::shared_ptr<Store>(std::make_shared<LocalStore>(params));
default:
return nullptr;
}
return mode == mDaemon
? std::shared_ptr<Store>(std::make_shared<RemoteStore>(params))
: std::shared_ptr<Store>(std::make_shared<LocalStore>(params));
});
@ -679,7 +680,7 @@ std::list<ref<Store>> getDefaultSubstituters()
auto addStore = [&](const std::string & uri) {
if (done.count(uri)) return;
done.insert(uri);
state->stores.push_back(openStoreAt(uri));
state->stores.push_back(openStore(uri));
};
for (auto uri : settings.get("substituters", Strings()))