diff --git a/src/libstore-tests/legacy-ssh-store.cc b/src/libstore-tests/legacy-ssh-store.cc index 2ff5e69ed..c69bd9c28 100644 --- a/src/libstore-tests/legacy-ssh-store.cc +++ b/src/libstore-tests/legacy-ssh-store.cc @@ -6,21 +6,27 @@ namespace nix { TEST(LegacySSHStore, constructConfig) { - LegacySSHStoreConfig config{ + initLibStore(/*loadConfig=*/false); + + auto config = make_ref( "ssh", - "localhost", + "me@localhost:2222", StoreConfig::Params{ { "remote-program", // TODO #11106, no more split on space "foo bar", }, - }}; + }); + EXPECT_EQ( - config.remoteProgram.get(), + config->remoteProgram.get(), (Strings{ "foo", "bar", })); + + auto store = config->openStore(); + EXPECT_EQ(store->getUri(), "ssh://me@localhost:2222?remote-program=foo%20bar"); } } // namespace nix diff --git a/src/libstore-tests/nix_api_store.cc b/src/libstore-tests/nix_api_store.cc index 05373cb88..b0707e9f4 100644 --- a/src/libstore-tests/nix_api_store.cc +++ b/src/libstore-tests/nix_api_store.cc @@ -5,6 +5,7 @@ #include "nix/store/tests/nix_api_store.hh" #include "nix/util/tests/string_callback.hh" +#include "nix/util/url.hh" #include "store-tests-config.hh" @@ -23,7 +24,13 @@ TEST_F(nix_api_store_test, nix_store_get_uri) std::string str; auto ret = nix_store_get_uri(ctx, store, OBSERVE_STRING(str)); ASSERT_EQ(NIX_OK, ret); - ASSERT_STREQ("local", str.c_str()); + auto expectedStoreURI = "local?" + + nix::encodeQuery({ + {"log", nixLogDir}, + {"state", nixStateDir}, + {"store", nixStoreDir}, + }); + ASSERT_EQ(expectedStoreURI, str); } TEST_F(nix_api_util_context, nix_store_get_storedir_default) diff --git a/src/libstore-tests/ssh-store.cc b/src/libstore-tests/ssh-store.cc index 3c2af311f..28ea0ee0b 100644 --- a/src/libstore-tests/ssh-store.cc +++ b/src/libstore-tests/ssh-store.cc @@ -8,24 +8,31 @@ namespace nix { TEST(SSHStore, constructConfig) { - SSHStoreConfig config{ - "ssh", - "localhost", + initLibStore(/*loadConfig=*/false); + + auto config = make_ref( + "ssh-ng", + "me@localhost:2222", StoreConfig::Params{ { "remote-program", // TODO #11106, no more split on space "foo bar", }, - }, - }; + }); EXPECT_EQ( - config.remoteProgram.get(), + config->remoteProgram.get(), (Strings{ "foo", "bar", })); + + auto store = config->openStore(); + EXPECT_EQ(store->getUri(), "ssh-ng://me@localhost:2222?remote-program=foo%20bar"); + config->resetOverridden(); + store = config->openStore(); + EXPECT_EQ(store->getUri(), "ssh-ng://me@localhost:2222"); } TEST(MountedSSHStore, constructConfig) diff --git a/src/libstore/include/nix/store/store-api.hh b/src/libstore/include/nix/store/store-api.hh index 3fbb539a1..f8356be78 100644 --- a/src/libstore/include/nix/store/store-api.hh +++ b/src/libstore/include/nix/store/store-api.hh @@ -126,6 +126,19 @@ struct StoreConfig : public StoreDirConfig return ""; } + /** + * Get overridden store reference query parameters. + */ + StringMap getQueryParams() const + { + auto queryParams = std::map{}; + getSettings(queryParams, /*overriddenOnly=*/true); + StringMap res; + for (const auto & [name, info] : queryParams) + res.insert({name, info.value}); + return res; + } + /** * An experimental feature this type store is gated, if it is to be * experimental. diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 075702f93..43eaac68b 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -90,7 +90,9 @@ ref LegacySSHStore::openConnection() std::string LegacySSHStore::getUri() { - return *Config::uriSchemes().begin() + "://" + config->authority.to_string(); + return ParsedURL{ + .scheme = *Config::uriSchemes().begin(), .authority = config->authority, .query = config->getQueryParams()} + .to_string(); } std::map LegacySSHStore::queryPathInfosUncached(const StorePathSet & paths) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 685402cfe..48cb8d718 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -16,6 +16,7 @@ #include "nix/store/posix-fs-canonicalise.hh" #include "nix/util/posix-source-accessor.hh" #include "nix/store/keys.hh" +#include "nix/util/url.hh" #include "nix/util/users.hh" #include "nix/store/store-open.hh" #include "nix/store/store-registration.hh" @@ -440,7 +441,13 @@ LocalStore::~LocalStore() std::string LocalStore::getUri() { - return "local"; + std::ostringstream oss; + oss << *config->uriSchemes().begin(); + auto queryParams = config->getQueryParams(); + if (!queryParams.empty()) + oss << "?"; + oss << encodeQuery(queryParams); + return std::move(oss).str(); } int LocalStore::getSchema() diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc index 875a4fea5..a1b27cfb7 100644 --- a/src/libstore/ssh-store.cc +++ b/src/libstore/ssh-store.cc @@ -43,7 +43,9 @@ struct SSHStore : virtual RemoteStore std::string getUri() override { - return *Config::uriSchemes().begin() + "://" + host; + return ParsedURL{ + .scheme = *Config::uriSchemes().begin(), .authority = config->authority, .query = config->getQueryParams()} + .to_string(); } // FIXME extend daemon protocol, move implementation to RemoteStore @@ -66,8 +68,6 @@ protected: ref openConnection() override; - std::string host; - std::vector extraRemoteProgramArgs; SSHMaster master;