Allow shorter syntax for chroot stores

You can now say '--store /tmp/nix' instead of '--store local?root=/tmp/nix'.
This commit is contained in:
Eelco Dolstra 2017-10-24 15:16:18 +02:00
parent 3460e4cf00
commit d16fd24973
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
5 changed files with 23 additions and 11 deletions

View file

@ -176,9 +176,13 @@ int main (int argc, char * * argv)
Activity act(*logger, lvlTalkative, actUnknown, fmt("connecting to '%s'", bestMachine->storeUri)); Activity act(*logger, lvlTalkative, actUnknown, fmt("connecting to '%s'", bestMachine->storeUri));
Store::Params storeParams{{"max-connections", "1"}, {"log-fd", "4"}}; Store::Params storeParams;
if (hasPrefix(storeUri, "ssh://")) {
storeParams["max-connections"] ="1";
storeParams["log-fd"] = "4";
if (bestMachine->sshKey != "") if (bestMachine->sshKey != "")
storeParams["ssh-key"] = bestMachine->sshKey; storeParams["ssh-key"] = bestMachine->sshKey;
}
sshStore = openStore(bestMachine->storeUri, storeParams); sshStore = openStore(bestMachine->storeUri, storeParams);
sshStore->connect(); sshStore->connect();

View file

@ -17,7 +17,11 @@ Machine::Machine(decltype(storeUri) storeUri,
storeUri( storeUri(
// Backwards compatibility: if the URI is a hostname, // Backwards compatibility: if the URI is a hostname,
// prepend ssh://. // 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 ? storeUri
: "ssh://" + storeUri), : "ssh://" + storeUri),
systemTypes(systemTypes), systemTypes(systemTypes),

View file

@ -843,7 +843,7 @@ StoreType getStoreType(const std::string & uri, const std::string & stateDir)
{ {
if (uri == "daemon") { if (uri == "daemon") {
return tDaemon; return tDaemon;
} else if (uri == "local") { } else if (uri == "local" || hasPrefix(uri, "/")) {
return tLocal; return tLocal;
} else if (uri == "" || uri == "auto") { } else if (uri == "" || uri == "auto") {
if (access(stateDir.c_str(), R_OK | W_OK) == 0) 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))) { switch (getStoreType(uri, get(params, "state", settings.nixStateDir))) {
case tDaemon: case tDaemon:
return std::shared_ptr<Store>(std::make_shared<UDSRemoteStore>(params)); return std::shared_ptr<Store>(std::make_shared<UDSRemoteStore>(params));
case tLocal: case tLocal: {
return std::shared_ptr<Store>(std::make_shared<LocalStore>(params)); Store::Params params2 = params;
if (hasPrefix(uri, "/"))
params2["root"] = uri;
return std::shared_ptr<Store>(std::make_shared<LocalStore>(params2));
}
default: default:
return nullptr; return nullptr;
} }

View file

@ -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 \ nix build -f build-hook.nix -o $TEST_ROOT/result --max-jobs 0 \
--sandbox-paths /nix/store --sandbox-build-dir /build-tmp \ --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 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. # Ensure that input1 was built on store1 due to the required feature.
p=$(readlink -f $outPath/input-2) p=$(readlink -f $outPath/input-2)
(! nix path-info --store local?root=$TEST_ROOT/store0 --all | grep dependencies.builder1.sh) (! nix path-info --store $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/store1 --all | grep dependencies.builder1.sh

View file

@ -14,7 +14,7 @@ chmod -R u+w $TEST_ROOT/store0 || true
rm -rf $TEST_ROOT/store0 rm -rf $TEST_ROOT/store0
export NIX_STORE_DIR=/my/store 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) outPath=$(nix-build dependencies.nix --no-out-link --option sandbox-paths /nix/store)