diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-01-31T09·19+0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-01-31T09·28+0100 |
commit | 9e7c1a4bbdbe6129dd9dc385776612c307d3d1bb (patch) | |
tree | 4c213493e9c6fa1045df1b4192061602e31c78eb /src/libstore/store-api.cc | |
parent | 4fa08f3edb413e65816441acfb6c3befee730a06 (diff) |
Use the daemon when we don't have write access to the Nix database
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r-- | src/libstore/store-api.cc | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index a73ebd824264..f5035d3230fd 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -311,10 +311,22 @@ std::shared_ptr<StoreAPI> store; std::shared_ptr<StoreAPI> openStore(bool reserveSpace) { - if (getEnv("NIX_REMOTE") == "") - return std::shared_ptr<StoreAPI>(new LocalStore(reserveSpace)); - else - return std::shared_ptr<StoreAPI>(new RemoteStore()); + enum { mDaemon, mLocal, mAuto } mode; + + mode = getEnv("NIX_REMOTE") == "daemon" ? mDaemon : mAuto; + + if (mode == mAuto) { + if (LocalStore::haveWriteAccess()) + mode = mLocal; + else if (pathExists(settings.nixDaemonSocketFile)) + mode = mDaemon; + else + mode = mLocal; + } + + return mode == mDaemon + ? (std::shared_ptr<StoreAPI>) std::make_shared<RemoteStore>() + : std::make_shared<LocalStore>(reserveSpace); } |