about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-10-24T13·16+0200
committerEelco Dolstra <edolstra@gmail.com>2017-10-24T13·32+0200
commitd16fd2497374671c92cb877f9570d65783a77d99 (patch)
treece2a871f4d9e5a65108768f1f8584cd545cbd6ac
parent3460e4cf007017e89096b4fad083692666b87a20 (diff)
Allow shorter syntax for chroot stores
You can now say '--store /tmp/nix' instead of '--store local?root=/tmp/nix'.
-rw-r--r--src/build-remote/build-remote.cc10
-rw-r--r--src/libstore/machines.cc6
-rw-r--r--src/libstore/store-api.cc10
-rw-r--r--tests/build-remote.sh6
-rw-r--r--tests/linux-sandbox.sh2
5 files changed, 23 insertions, 11 deletions
diff --git a/src/build-remote/build-remote.cc b/src/build-remote/build-remote.cc
index 419e720537..6e05e16554 100644
--- a/src/build-remote/build-remote.cc
+++ b/src/build-remote/build-remote.cc
@@ -176,9 +176,13 @@ int main (int argc, char * * argv)
 
                     Activity act(*logger, lvlTalkative, actUnknown, fmt("connecting to '%s'", bestMachine->storeUri));
 
-                    Store::Params storeParams{{"max-connections", "1"}, {"log-fd", "4"}};
-                    if (bestMachine->sshKey != "")
-                        storeParams["ssh-key"] = bestMachine->sshKey;
+                    Store::Params storeParams;
+                    if (hasPrefix(storeUri, "ssh://")) {
+                        storeParams["max-connections"] ="1";
+                        storeParams["log-fd"] = "4";
+                        if (bestMachine->sshKey != "")
+                            storeParams["ssh-key"] = bestMachine->sshKey;
+                    }
 
                     sshStore = openStore(bestMachine->storeUri, storeParams);
                     sshStore->connect();
diff --git a/src/libstore/machines.cc b/src/libstore/machines.cc
index d2faf45357..edd03d1478 100644
--- a/src/libstore/machines.cc
+++ b/src/libstore/machines.cc
@@ -17,7 +17,11 @@ Machine::Machine(decltype(storeUri) storeUri,
     storeUri(
         // Backwards compatibility: if the URI is a hostname,
         // prepend ssh://.
-        storeUri.find("://") != std::string::npos || hasPrefix(storeUri, "local") || hasPrefix(storeUri, "remote") || hasPrefix(storeUri, "auto")
+        storeUri.find("://") != std::string::npos
+        || hasPrefix(storeUri, "local")
+        || hasPrefix(storeUri, "remote")
+        || hasPrefix(storeUri, "auto")
+        || hasPrefix(storeUri, "/")
         ? storeUri
         : "ssh://" + storeUri),
     systemTypes(systemTypes),
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 17237a0354..c57e42fec0 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -843,7 +843,7 @@ StoreType getStoreType(const std::string & uri, const std::string & stateDir)
 {
     if (uri == "daemon") {
         return tDaemon;
-    } else if (uri == "local") {
+    } else if (uri == "local" || hasPrefix(uri, "/")) {
         return tLocal;
     } else if (uri == "" || uri == "auto") {
         if (access(stateDir.c_str(), R_OK | W_OK) == 0)
@@ -865,8 +865,12 @@ static RegisterStoreImplementation regStore([](
     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));
+        case tLocal: {
+            Store::Params params2 = params;
+            if (hasPrefix(uri, "/"))
+                params2["root"] = uri;
+            return std::shared_ptr<Store>(std::make_shared<LocalStore>(params2));
+        }
         default:
             return nullptr;
     }
diff --git a/tests/build-remote.sh b/tests/build-remote.sh
index 603b57c59e..cf3bb46331 100644
--- a/tests/build-remote.sh
+++ b/tests/build-remote.sh
@@ -11,7 +11,7 @@ rm -rf $TEST_ROOT/store0 $TEST_ROOT/store1
 
 nix build -f build-hook.nix -o $TEST_ROOT/result --max-jobs 0 \
   --sandbox-paths /nix/store --sandbox-build-dir /build-tmp \
-  --builders "local?root=$TEST_ROOT/store0; local?root=$TEST_ROOT/store1 - - 1 1 foo"
+  --builders "$TEST_ROOT/store0; $TEST_ROOT/store1 - - 1 1 foo"
 
 outPath=$TEST_ROOT/result
 
@@ -19,5 +19,5 @@ cat $outPath/foobar | grep FOOBAR
 
 # Ensure that input1 was built on store1 due to the required feature.
 p=$(readlink -f $outPath/input-2)
-(! nix path-info --store local?root=$TEST_ROOT/store0 --all | grep dependencies.builder1.sh)
-nix path-info --store local?root=$TEST_ROOT/store1 --all | grep dependencies.builder1.sh
+(! nix path-info --store $TEST_ROOT/store0 --all | grep dependencies.builder1.sh)
+nix path-info --store $TEST_ROOT/store1 --all | grep dependencies.builder1.sh
diff --git a/tests/linux-sandbox.sh b/tests/linux-sandbox.sh
index 7f4e83b560..0691c30be1 100644
--- a/tests/linux-sandbox.sh
+++ b/tests/linux-sandbox.sh
@@ -14,7 +14,7 @@ chmod -R u+w $TEST_ROOT/store0 || true
 rm -rf $TEST_ROOT/store0
 
 export NIX_STORE_DIR=/my/store
-export NIX_REMOTE="local?root=$TEST_ROOT/store0"
+export NIX_REMOTE=$TEST_ROOT/store0
 
 outPath=$(nix-build dependencies.nix --no-out-link --option sandbox-paths /nix/store)