aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/store-api.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r--src/libstore/store-api.cc47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index f365406cb..f7f6c9696 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -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()))