From 0ef6f72c9cd795181f302948e569d79cc9f97361 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 11 Aug 2025 17:28:01 -0400 Subject: [PATCH] `getUri` should be `const` and on `Store::Config` not `Store` It is a side-effect property of the configuration alone, not the rest of the store. --- src/libcmd/repl.cc | 4 +-- src/libstore-c/nix_api_store.cc | 2 +- src/libstore-tests/legacy-ssh-store.cc | 2 +- src/libstore-tests/nix_api_store.cc | 2 +- src/libstore-tests/ssh-store.cc | 17 ++++------ src/libstore/binary-cache-store.cc | 14 +++++--- .../build/drv-output-substitution-goal.cc | 2 +- src/libstore/build/substitution-goal.cc | 7 ++-- src/libstore/dummy-store.cc | 10 +++--- src/libstore/http-binary-cache-store.cc | 13 +++---- .../nix/store/http-binary-cache-store.hh | 5 +++ .../include/nix/store/legacy-ssh-store.hh | 4 +-- .../nix/store/local-binary-cache-store.hh | 2 ++ .../include/nix/store/local-overlay-store.hh | 10 +++--- src/libstore/include/nix/store/local-store.hh | 4 +-- .../nix/store/s3-binary-cache-store.hh | 2 ++ src/libstore/include/nix/store/ssh-store.hh | 2 ++ src/libstore/include/nix/store/store-api.hh | 15 ++++---- src/libstore/include/nix/store/store-cast.hh | 2 +- .../include/nix/store/uds-remote-store.hh | 4 +-- src/libstore/legacy-ssh-store.cc | 6 ++-- src/libstore/local-binary-cache-store.cc | 10 +++--- src/libstore/local-store.cc | 6 ++-- src/libstore/remote-store.cc | 4 +-- src/libstore/restricted-store.cc | 5 --- src/libstore/s3-binary-cache-store.cc | 16 ++++----- src/libstore/ssh-store.cc | 12 +++---- src/libstore/store-api.cc | 34 ++++++++++--------- src/libstore/uds-remote-store.cc | 13 ++++--- src/nix/config-check.cc | 6 ++-- src/nix/log.cc | 4 +-- src/nix/run.cc | 2 +- src/nix/store-info.cc | 4 +-- 33 files changed, 123 insertions(+), 122 deletions(-) diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index ea3f44a7c..3e3b882c3 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -574,14 +574,14 @@ ProcessLineResult NixRepl::processLine(std::string line) for (auto & sub : subs) { auto * logSubP = dynamic_cast(&*sub); if (!logSubP) { - printInfo("Skipped '%s' which does not support retrieving build logs", sub->getUri()); + printInfo("Skipped '%s' which does not support retrieving build logs", sub->config.getUri()); continue; } auto & logSub = *logSubP; auto log = logSub.getBuildLog(drvPath); if (log) { - printInfo("got build log for '%s' from '%s'", drvPathRaw, logSub.getUri()); + printInfo("got build log for '%s' from '%s'", drvPathRaw, logSub.config.getUri()); logger->writeToStdout(*log); foundLog = true; break; diff --git a/src/libstore-c/nix_api_store.cc b/src/libstore-c/nix_api_store.cc index b7b437e9c..705d8153f 100644 --- a/src/libstore-c/nix_api_store.cc +++ b/src/libstore-c/nix_api_store.cc @@ -62,7 +62,7 @@ nix_err nix_store_get_uri(nix_c_context * context, Store * store, nix_get_string if (context) context->last_err_code = NIX_OK; try { - auto res = store->ptr->getUri(); + auto res = store->ptr->config.getUri(); return call_nix_get_string_callback(res, callback, user_data); } NIXC_CATCH_ERRS diff --git a/src/libstore-tests/legacy-ssh-store.cc b/src/libstore-tests/legacy-ssh-store.cc index c69bd9c28..04c3763ec 100644 --- a/src/libstore-tests/legacy-ssh-store.cc +++ b/src/libstore-tests/legacy-ssh-store.cc @@ -27,6 +27,6 @@ TEST(LegacySSHStore, constructConfig) })); auto store = config->openStore(); - EXPECT_EQ(store->getUri(), "ssh://me@localhost:2222?remote-program=foo%20bar"); + EXPECT_EQ(store->config.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 b0707e9f4..cff889ab9 100644 --- a/src/libstore-tests/nix_api_store.cc +++ b/src/libstore-tests/nix_api_store.cc @@ -104,7 +104,7 @@ TEST_F(nix_api_util_context, nix_store_open_dummy) nix_libstore_init(ctx); Store * store = nix_store_open(ctx, "dummy://", nullptr); ASSERT_EQ(NIX_OK, ctx->last_err_code); - ASSERT_STREQ("dummy", store->ptr->getUri().c_str()); + ASSERT_STREQ("dummy", store->ptr->config.getUri().c_str()); std::string str; nix_store_get_version(ctx, store, OBSERVE_STRING(str)); diff --git a/src/libstore-tests/ssh-store.cc b/src/libstore-tests/ssh-store.cc index 28ea0ee0b..335e4ae85 100644 --- a/src/libstore-tests/ssh-store.cc +++ b/src/libstore-tests/ssh-store.cc @@ -8,9 +8,7 @@ namespace nix { TEST(SSHStore, constructConfig) { - initLibStore(/*loadConfig=*/false); - - auto config = make_ref( + SSHStoreConfig config{ "ssh-ng", "me@localhost:2222", StoreConfig::Params{ @@ -19,20 +17,19 @@ TEST(SSHStore, constructConfig) // 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"); + EXPECT_EQ(config.getUri(), "ssh-ng://me@localhost:2222?remote-program=foo%20bar"); + config.resetOverridden(); + EXPECT_EQ(config.getUri(), "ssh-ng://me@localhost:2222"); } TEST(MountedSSHStore, constructConfig) diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 276d1c78a..c55239413 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -58,7 +58,10 @@ void BinaryCacheStore::init() if (name == "StoreDir") { if (value != storeDir) throw Error( - "binary cache '%s' is for Nix stores with prefix '%s', not '%s'", getUri(), value, storeDir); + "binary cache '%s' is for Nix stores with prefix '%s', not '%s'", + config.getUri(), + value, + storeDir); } else if (name == "WantMassQuery") { config.wantMassQuery.setDefault(value == "1"); } else if (name == "Priority") { @@ -129,7 +132,8 @@ void BinaryCacheStore::writeNarInfo(ref narInfo) } if (diskCache) - diskCache->upsertNarInfo(getUri(), std::string(narInfo->path.hashPart()), std::shared_ptr(narInfo)); + diskCache->upsertNarInfo( + config.getUri(), std::string(narInfo->path.hashPart()), std::shared_ptr(narInfo)); } ref BinaryCacheStore::addToStoreCommon( @@ -427,7 +431,7 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink) void BinaryCacheStore::queryPathInfoUncached( const StorePath & storePath, Callback> callback) noexcept { - auto uri = getUri(); + auto uri = config.getUri(); auto storePathS = printStorePath(storePath); auto act = std::make_shared( *logger, @@ -527,7 +531,7 @@ void BinaryCacheStore::queryRealisationUncached( void BinaryCacheStore::registerDrvOutput(const Realisation & info) { if (diskCache) - diskCache->upsertRealisation(getUri(), info); + diskCache->upsertRealisation(config.getUri(), info); auto filePath = realisationsPrefix + "/" + info.id.to_string() + ".doi"; upsertFile(filePath, info.toJSON().dump(), "application/json"); } @@ -555,7 +559,7 @@ std::optional BinaryCacheStore::getBuildLogExact(const StorePath & { auto logPath = "log/" + std::string(baseNameOf(printStorePath(path))); - debug("fetching build log from binary cache '%s/%s'", getUri(), logPath); + debug("fetching build log from binary cache '%s/%s'", config.getUri(), logPath); return getFile(logPath); } diff --git a/src/libstore/build/drv-output-substitution-goal.cc b/src/libstore/build/drv-output-substitution-goal.cc index 0ddd1c438..3f4b787f7 100644 --- a/src/libstore/build/drv-output-substitution-goal.cc +++ b/src/libstore/build/drv-output-substitution-goal.cc @@ -98,7 +98,7 @@ Goal::Co DrvOutputSubstitutionGoal::init() "substituter '%s' has an incompatible realisation for '%s', ignoring.\n" "Local: %s\n" "Remote: %s", - sub->getUri(), + sub->config.getUri(), depId.to_string(), worker.store.printStorePath(localOutputInfo->outPath), worker.store.printStorePath(depPath)); diff --git a/src/libstore/build/substitution-goal.cc b/src/libstore/build/substitution-goal.cc index 3c9ad6374..e46ad2007 100644 --- a/src/libstore/build/substitution-goal.cc +++ b/src/libstore/build/substitution-goal.cc @@ -101,7 +101,7 @@ Goal::Co PathSubstitutionGoal::init() } else { printError( "asked '%s' for '%s' but got '%s'", - sub->getUri(), + sub->config.getUri(), worker.store.printStorePath(storePath), sub->printStorePath(info->path)); continue; @@ -127,7 +127,7 @@ Goal::Co PathSubstitutionGoal::init() warn( "ignoring substitute for '%s' from '%s', as it's not signed by any of the keys in 'trusted-public-keys'", worker.store.printStorePath(storePath), - sub->getUri()); + sub->config.getUri()); continue; } @@ -217,7 +217,8 @@ Goal::Co PathSubstitutionGoal::tryToRun( /* Wake up the worker loop when we're done. */ Finally updateStats([this]() { outPipe.writeSide.close(); }); - Activity act(*logger, actSubstitute, Logger::Fields{worker.store.printStorePath(storePath), sub->getUri()}); + Activity act( + *logger, actSubstitute, Logger::Fields{worker.store.printStorePath(storePath), sub->config.getUri()}); PushActivity pact(act.id); copyStorePath(*sub, worker.store, subPath, repair, sub->config.isTrusted ? NoCheckSigs : CheckSigs); diff --git a/src/libstore/dummy-store.cc b/src/libstore/dummy-store.cc index 74119a529..bc8f5b6f5 100644 --- a/src/libstore/dummy-store.cc +++ b/src/libstore/dummy-store.cc @@ -32,6 +32,11 @@ struct DummyStoreConfig : public std::enable_shared_from_this, } ref openStore() const override; + + std::string getUri() const override + { + return *uriSchemes().begin(); + } }; struct DummyStore : virtual Store @@ -46,11 +51,6 @@ struct DummyStore : virtual Store { } - std::string getUri() override - { - return *Config::uriSchemes().begin(); - } - void queryPathInfoUncached( const StorePath & path, Callback> callback) noexcept override { diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc index 21a31c3f5..31899f629 100644 --- a/src/libstore/http-binary-cache-store.cc +++ b/src/libstore/http-binary-cache-store.cc @@ -62,11 +62,6 @@ public: diskCache = getNarInfoDiskCache(); } - std::string getUri() override - { - return config->cacheUri; - } - void init() override { // FIXME: do this lazily? @@ -90,7 +85,7 @@ protected: auto state(_state.lock()); if (state->enabled && settings.tryFallback) { int t = 60; - printError("disabling binary cache '%s' for %s seconds", getUri(), t); + printError("disabling binary cache '%s' for %s seconds", config->getUri(), t); state->enabled = false; state->disabledUntil = std::chrono::steady_clock::now() + std::chrono::seconds(t); } @@ -103,10 +98,10 @@ protected: return; if (std::chrono::steady_clock::now() > state->disabledUntil) { state->enabled = true; - debug("re-enabling binary cache '%s'", getUri()); + debug("re-enabling binary cache '%s'", config->getUri()); return; } - throw SubstituterDisabled("substituter '%s' is disabled", getUri()); + throw SubstituterDisabled("substituter '%s' is disabled", config->getUri()); } bool fileExists(const std::string & path) override @@ -159,7 +154,7 @@ protected: getFileTransfer()->download(std::move(request), sink); } catch (FileTransferError & e) { if (e.error == FileTransfer::NotFound || e.error == FileTransfer::Forbidden) - throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache '%s'", path, getUri()); + throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache '%s'", path, config->getUri()); maybeDisable(); throw; } diff --git a/src/libstore/include/nix/store/http-binary-cache-store.hh b/src/libstore/include/nix/store/http-binary-cache-store.hh index f0d85a119..ef13aa7b6 100644 --- a/src/libstore/include/nix/store/http-binary-cache-store.hh +++ b/src/libstore/include/nix/store/http-binary-cache-store.hh @@ -23,6 +23,11 @@ struct HttpBinaryCacheStoreConfig : std::enable_shared_from_this openStore() const override; + + std::string getUri() const override + { + return cacheUri; + } }; } // namespace nix diff --git a/src/libstore/include/nix/store/legacy-ssh-store.hh b/src/libstore/include/nix/store/legacy-ssh-store.hh index b64189af9..e53d18559 100644 --- a/src/libstore/include/nix/store/legacy-ssh-store.hh +++ b/src/libstore/include/nix/store/legacy-ssh-store.hh @@ -53,6 +53,8 @@ struct LegacySSHStoreConfig : std::enable_shared_from_this static std::string doc(); ref openStore() const override; + + std::string getUri() const override; }; struct LegacySSHStore : public virtual Store @@ -71,8 +73,6 @@ struct LegacySSHStore : public virtual Store ref openConnection(); - std::string getUri() override; - void queryPathInfoUncached( const StorePath & path, Callback> callback) noexcept override; diff --git a/src/libstore/include/nix/store/local-binary-cache-store.hh b/src/libstore/include/nix/store/local-binary-cache-store.hh index 3561131d4..5ca5ca43e 100644 --- a/src/libstore/include/nix/store/local-binary-cache-store.hh +++ b/src/libstore/include/nix/store/local-binary-cache-store.hh @@ -26,6 +26,8 @@ struct LocalBinaryCacheStoreConfig : std::enable_shared_from_this openStore() const override; + + std::string getUri() const override; }; } // namespace nix diff --git a/src/libstore/include/nix/store/local-overlay-store.hh b/src/libstore/include/nix/store/local-overlay-store.hh index e5097f3e4..1180f0466 100644 --- a/src/libstore/include/nix/store/local-overlay-store.hh +++ b/src/libstore/include/nix/store/local-overlay-store.hh @@ -88,6 +88,11 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig ref openStore() const override; + std::string getUri() const override + { + return "local-overlay://"; + } + protected: /** * @return The host OS path corresponding to the store path for the @@ -116,11 +121,6 @@ struct LocalOverlayStore : virtual LocalStore LocalOverlayStore(ref); - std::string getUri() override - { - return "local-overlay://"; - } - private: /** * The store beneath us. diff --git a/src/libstore/include/nix/store/local-store.hh b/src/libstore/include/nix/store/local-store.hh index 461562ef1..af243d480 100644 --- a/src/libstore/include/nix/store/local-store.hh +++ b/src/libstore/include/nix/store/local-store.hh @@ -111,6 +111,8 @@ struct LocalStoreConfig : std::enable_shared_from_this, static std::string doc(); ref openStore() const override; + + std::string getUri() const override; }; class LocalStore : public virtual IndirectRootStore, public virtual GcStore @@ -196,8 +198,6 @@ public: * Implementations of abstract store API methods. */ - std::string getUri() override; - bool isValidPathUncached(const StorePath & path) override; StorePathSet queryValidPaths(const StorePathSet & paths, SubstituteFlag maybeSubstitute = NoSubstitute) override; diff --git a/src/libstore/include/nix/store/s3-binary-cache-store.hh b/src/libstore/include/nix/store/s3-binary-cache-store.hh index 584488070..ec3aae149 100644 --- a/src/libstore/include/nix/store/s3-binary-cache-store.hh +++ b/src/libstore/include/nix/store/s3-binary-cache-store.hh @@ -106,6 +106,8 @@ public: static std::string doc(); ref openStore() const override; + + std::string getUri() const override; }; struct S3BinaryCacheStore : virtual BinaryCacheStore diff --git a/src/libstore/include/nix/store/ssh-store.hh b/src/libstore/include/nix/store/ssh-store.hh index 17fea39d5..ff6c3ed69 100644 --- a/src/libstore/include/nix/store/ssh-store.hh +++ b/src/libstore/include/nix/store/ssh-store.hh @@ -33,6 +33,8 @@ struct SSHStoreConfig : std::enable_shared_from_this, static std::string doc(); ref openStore() const override; + + std::string getUri() const override; }; struct MountedSSHStoreConfig : virtual SSHStoreConfig, virtual LocalFSStoreConfig diff --git a/src/libstore/include/nix/store/store-api.hh b/src/libstore/include/nix/store/store-api.hh index f8356be78..8f09fee48 100644 --- a/src/libstore/include/nix/store/store-api.hh +++ b/src/libstore/include/nix/store/store-api.hh @@ -197,6 +197,13 @@ struct StoreConfig : public StoreDirConfig * type. */ virtual ref openStore() const = 0; + + /** + * Render the config back to a "store URL". It should round-trip + * with `resolveStoreConfig` (for stores configs that are + * registered). + */ + virtual std::string getUri() const; }; /** @@ -277,12 +284,6 @@ public: virtual ~Store() {} - /** - * @todo move to `StoreConfig` one we store enough information in - * those to recover the scheme and authority in all cases. - */ - virtual std::string getUri() = 0; - /** * Follow symlinks until we end up with a path in the Nix store. */ @@ -872,7 +873,7 @@ protected: */ [[noreturn]] void unsupported(const std::string & op) { - throw Unsupported("operation '%s' is not supported by store '%s'", op, getUri()); + throw Unsupported("operation '%s' is not supported by store '%s'", op, config.getUri()); } }; diff --git a/src/libstore/include/nix/store/store-cast.hh b/src/libstore/include/nix/store/store-cast.hh index 89775599a..0d7257602 100644 --- a/src/libstore/include/nix/store/store-cast.hh +++ b/src/libstore/include/nix/store/store-cast.hh @@ -17,7 +17,7 @@ T & require(Store & store) { auto * castedStore = dynamic_cast(&store); if (!castedStore) - throw UsageError("%s not supported by store '%s'", T::operationName, store.getUri()); + throw UsageError("%s not supported by store '%s'", T::operationName, store.config.getUri()); return *castedStore; } diff --git a/src/libstore/include/nix/store/uds-remote-store.hh b/src/libstore/include/nix/store/uds-remote-store.hh index e4d0187c8..c77a29a8b 100644 --- a/src/libstore/include/nix/store/uds-remote-store.hh +++ b/src/libstore/include/nix/store/uds-remote-store.hh @@ -44,6 +44,8 @@ struct UDSRemoteStoreConfig : std::enable_shared_from_this } ref openStore() const override; + + std::string getUri() const override; }; struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore @@ -54,8 +56,6 @@ struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore UDSRemoteStore(ref); - std::string getUri() override; - ref getFSAccessor(bool requireValidPath = true) override { return LocalFSStore::getFSAccessor(requireValidPath); diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 43eaac68b..9592994a1 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -88,11 +88,9 @@ ref LegacySSHStore::openConnection() return conn; }; -std::string LegacySSHStore::getUri() +std::string LegacySSHStoreConfig::getUri() const { - return ParsedURL{ - .scheme = *Config::uriSchemes().begin(), .authority = config->authority, .query = config->getQueryParams()} - .to_string(); + return ParsedURL{.scheme = *uriSchemes().begin(), .authority = authority, .query = getQueryParams()}.to_string(); } std::map LegacySSHStore::queryPathInfosUncached(const StorePathSet & paths) diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc index f7511fdce..645a01b09 100644 --- a/src/libstore/local-binary-cache-store.cc +++ b/src/libstore/local-binary-cache-store.cc @@ -23,6 +23,11 @@ std::string LocalBinaryCacheStoreConfig::doc() ; } +std::string LocalBinaryCacheStoreConfig::getUri() const +{ + return "file://" + binaryCacheDir; +} + struct LocalBinaryCacheStore : virtual BinaryCacheStore { using Config = LocalBinaryCacheStoreConfig; @@ -38,11 +43,6 @@ struct LocalBinaryCacheStore : virtual BinaryCacheStore void init() override; - std::string getUri() override - { - return "file://" + config->binaryCacheDir; - } - protected: bool fileExists(const std::string & path) override; diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 48cb8d718..dfffdea6a 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -439,11 +439,11 @@ LocalStore::~LocalStore() } } -std::string LocalStore::getUri() +std::string LocalStoreConfig::getUri() const { std::ostringstream oss; - oss << *config->uriSchemes().begin(); - auto queryParams = config->getQueryParams(); + oss << *uriSchemes().begin(); + auto queryParams = getQueryParams(); if (!queryParams.empty()) oss << "?"; oss << encodeQuery(queryParams); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 2b072980b..3eff339e1 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -53,7 +53,7 @@ RemoteStore::RemoteStore(const Config & config) ref RemoteStore::openConnectionWrapper() { if (failed) - throw Error("opening a connection to remote store '%s' previously failed", getUri()); + throw Error("opening a connection to remote store '%s' previously failed", config.getUri()); try { return openConnection(); } catch (...) { @@ -95,7 +95,7 @@ void RemoteStore::initConnection(Connection & conn) if (ex) std::rethrow_exception(ex); } catch (Error & e) { - throw Error("cannot open connection to remote store '%s': %s", getUri(), e.what()); + throw Error("cannot open connection to remote store '%s': %s", config.getUri(), e.what()); } setOptions(conn); diff --git a/src/libstore/restricted-store.cc b/src/libstore/restricted-store.cc index f191950b5..1fb139dff 100644 --- a/src/libstore/restricted-store.cc +++ b/src/libstore/restricted-store.cc @@ -57,11 +57,6 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor return next->config->realStoreDir; } - std::string getUri() override - { - return next->getUri(); - } - StorePathSet queryAllValidPaths() override; void queryPathInfoUncached( diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc index 0df7e482a..5f91a8129 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -254,6 +254,11 @@ std::string S3BinaryCacheStoreConfig::doc() ; } +std::string S3BinaryCacheStoreConfig::getUri() const +{ + return "s3://" + bucketName; +} + struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStore { Stats stats; @@ -269,19 +274,14 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStore diskCache = getNarInfoDiskCache(); } - std::string getUri() override - { - return "s3://" + config->bucketName; - } - void init() override { - if (auto cacheInfo = diskCache->upToDateCacheExists(getUri())) { + if (auto cacheInfo = diskCache->upToDateCacheExists(config->getUri())) { config->wantMassQuery.setDefault(cacheInfo->wantMassQuery); config->priority.setDefault(cacheInfo->priority); } else { BinaryCacheStore::init(); - diskCache->createCache(getUri(), config->storeDir, config->wantMassQuery, config->priority); + diskCache->createCache(config->getUri(), config->storeDir, config->wantMassQuery, config->priority); } } @@ -519,7 +519,7 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStore sink(*res.data); } else - throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache '%s'", path, getUri()); + throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache '%s'", path, config->getUri()); } StorePathSet queryAllValidPaths() override diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc index a1b27cfb7..d3420186f 100644 --- a/src/libstore/ssh-store.cc +++ b/src/libstore/ssh-store.cc @@ -25,6 +25,11 @@ std::string SSHStoreConfig::doc() ; } +std::string SSHStoreConfig::getUri() const +{ + return ParsedURL{.scheme = *uriSchemes().begin(), .authority = authority, .query = getQueryParams()}.to_string(); +} + struct SSHStore : virtual RemoteStore { using Config = SSHStoreConfig; @@ -41,13 +46,6 @@ struct SSHStore : virtual RemoteStore { } - std::string getUri() override - { - return ParsedURL{ - .scheme = *Config::uriSchemes().begin(), .authority = config->authority, .query = config->getQueryParams()} - .to_string(); - } - // FIXME extend daemon protocol, move implementation to RemoteStore std::optional getBuildLogExact(const StorePath & path) override { diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index b678833e6..a720084a0 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -300,7 +300,7 @@ Store::Store(const Store::Config & config) assertLibStoreInitialized(); } -std::string Store::getUri() +std::string StoreConfig::getUri() const { return ""; } @@ -395,11 +395,11 @@ void Store::querySubstitutablePathInfos(const StorePathCAMap & paths, Substituta "replaced path '%s' with '%s' for substituter '%s'", printStorePath(path.first), sub->printStorePath(subPath), - sub->getUri()); + sub->config.getUri()); } else if (sub->storeDir != storeDir) continue; - debug("checking substituter '%s' for path '%s'", sub->getUri(), sub->printStorePath(subPath)); + debug("checking substituter '%s' for path '%s'", sub->config.getUri(), sub->printStorePath(subPath)); try { auto info = sub->queryPathInfo(subPath); @@ -439,7 +439,7 @@ bool Store::isValidPath(const StorePath & storePath) } if (diskCache) { - auto res = diskCache->lookupNarInfo(getUri(), std::string(storePath.hashPart())); + auto res = diskCache->lookupNarInfo(config.getUri(), std::string(storePath.hashPart())); if (res.first != NarInfoDiskCache::oUnknown) { stats.narInfoReadAverted++; auto state_(state.lock()); @@ -455,7 +455,7 @@ bool Store::isValidPath(const StorePath & storePath) if (diskCache && !valid) // FIXME: handle valid = true case. - diskCache->upsertNarInfo(getUri(), std::string(storePath.hashPart()), 0); + diskCache->upsertNarInfo(config.getUri(), std::string(storePath.hashPart()), 0); return valid; } @@ -509,7 +509,7 @@ std::optional> Store::queryPathInfoFromClie } if (diskCache) { - auto res = diskCache->lookupNarInfo(getUri(), hashPart); + auto res = diskCache->lookupNarInfo(config.getUri(), hashPart); if (res.first != NarInfoDiskCache::oUnknown) { stats.narInfoReadAverted++; { @@ -554,7 +554,7 @@ void Store::queryPathInfo(const StorePath & storePath, CallbackupsertNarInfo(getUri(), hashPart, info); + diskCache->upsertNarInfo(config.getUri(), hashPart, info); { auto state_(state.lock()); @@ -578,7 +578,7 @@ void Store::queryRealisation(const DrvOutput & id, CallbacklookupRealisation(getUri(), id); + auto [cacheOutcome, maybeCachedRealisation] = diskCache->lookupRealisation(config.getUri(), id); switch (cacheOutcome) { case NarInfoDiskCache::oValid: debug("Returning a cached realisation for %s", id.to_string()); @@ -604,9 +604,9 @@ void Store::queryRealisation(const DrvOutput & id, CallbackupsertRealisation(getUri(), *info); + diskCache->upsertRealisation(config.getUri(), *info); else - diskCache->upsertAbsentRealisation(getUri(), id); + diskCache->upsertAbsentRealisation(config.getUri(), id); } (*callbackPtr)(std::shared_ptr(info)); @@ -801,8 +801,8 @@ void copyStorePath( if (!repair && dstStore.isValidPath(storePath)) return; - auto srcUri = srcStore.getUri(); - auto dstUri = dstStore.getUri(); + auto srcUri = srcStore.config.getUri(); + auto dstUri = dstStore.config.getUri(); auto storePathS = srcStore.printStorePath(storePath); Activity act( *logger, lvlInfo, actCopyPath, makeCopyPathMessage(srcUri, dstUri, storePathS), {storePathS, srcUri, dstUri}); @@ -839,7 +839,9 @@ void copyStorePath( }, [&]() { throw EndOfFile( - "NAR for '%s' fetched from '%s' is incomplete", srcStore.printStorePath(storePath), srcStore.getUri()); + "NAR for '%s' fetched from '%s' is incomplete", + srcStore.printStorePath(storePath), + srcStore.config.getUri()); }); dstStore.addToStore(*info, *source, repair, checkSigs); @@ -937,7 +939,7 @@ std::map copyPaths( "replaced path '%s' to '%s' for substituter '%s'", srcStore.printStorePath(storePathForSrc), dstStore.printStorePath(storePathForDst), - dstStore.getUri()); + dstStore.config.getUri()); } return storePathForDst; }; @@ -955,8 +957,8 @@ std::map copyPaths( // We can reasonably assume that the copy will happen whenever we // read the path, so log something about that at that point uint64_t total = 0; - auto srcUri = srcStore.getUri(); - auto dstUri = dstStore.getUri(); + auto srcUri = srcStore.config.getUri(); + auto dstUri = dstStore.config.getUri(); auto storePathS = srcStore.printStorePath(missingPath); Activity act( *logger, diff --git a/src/libstore/uds-remote-store.cc b/src/libstore/uds-remote-store.cc index f8b3d834d..e1881c602 100644 --- a/src/libstore/uds-remote-store.cc +++ b/src/libstore/uds-remote-store.cc @@ -54,15 +54,14 @@ UDSRemoteStore::UDSRemoteStore(ref config) { } -std::string UDSRemoteStore::getUri() +std::string UDSRemoteStoreConfig::getUri() const { - return config->path == settings.nixDaemonSocketFile - ? // FIXME: Not clear why we return daemon here and not default - // to settings.nixDaemonSocketFile - // - // unix:// with no path also works. Change what we return? + return path == settings.nixDaemonSocketFile ? // FIXME: Not clear why we return daemon here and not default + // to settings.nixDaemonSocketFile + // + // unix:// with no path also works. Change what we return? "daemon" - : std::string(*Config::uriSchemes().begin()) + "://" + config->path; + : std::string(*uriSchemes().begin()) + "://" + path; } void UDSRemoteStore::Connection::closeWrite() diff --git a/src/nix/config-check.cc b/src/nix/config-check.cc index 7fcb7be7e..685795487 100644 --- a/src/nix/config-check.cc +++ b/src/nix/config-check.cc @@ -71,7 +71,7 @@ struct CmdConfigCheck : StoreCommand void run(ref store) override { - logger->log("Running checks against store uri: " + store->getUri()); + logger->log("Running checks against store uri: " + store->config.getUri()); if (store.dynamic_pointer_cast()) { success &= checkNixInPath(); @@ -171,9 +171,9 @@ struct CmdConfigCheck : StoreCommand { if (auto trustedMay = store->isTrustedClient()) { std::string_view trusted = trustedMay.value() ? "trusted" : "not trusted"; - checkInfo(fmt("You are %s by store uri: %s", trusted, store->getUri())); + checkInfo(fmt("You are %s by store uri: %s", trusted, store->config.getUri())); } else { - checkInfo(fmt("Store uri: %s doesn't have a notion of trusted user", store->getUri())); + checkInfo(fmt("Store uri: %s doesn't have a notion of trusted user", store->config.getUri())); } } }; diff --git a/src/nix/log.cc b/src/nix/log.cc index 56e44645b..2b697c609 100644 --- a/src/nix/log.cc +++ b/src/nix/log.cc @@ -48,7 +48,7 @@ struct CmdLog : InstallableCommand for (auto & sub : subs) { auto * logSubP = dynamic_cast(&*sub); if (!logSubP) { - printInfo("Skipped '%s' which does not support retrieving build logs", sub->getUri()); + printInfo("Skipped '%s' which does not support retrieving build logs", sub->config.getUri()); continue; } auto & logSub = *logSubP; @@ -57,7 +57,7 @@ struct CmdLog : InstallableCommand if (!log) continue; logger->stop(); - printInfo("got build log for '%s' from '%s'", installable->what(), logSub.getUri()); + printInfo("got build log for '%s' from '%s'", installable->what(), logSub.config.getUri()); writeFull(getStandardOutput(), *log); return; } diff --git a/src/nix/run.cc b/src/nix/run.cc index bde2cacd8..cd7784cee 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -77,7 +77,7 @@ void execProgramInStore( auto store2 = store.dynamic_pointer_cast(); if (!store2) - throw Error("store '%s' is not a local store so it does not support command execution", store->getUri()); + throw Error("store '%s' is not a local store so it does not support command execution", store->config.getUri()); if (store->storeDir != store2->getRealStoreDir()) { Strings helperArgs = { diff --git a/src/nix/store-info.cc b/src/nix/store-info.cc index 2132dc465..92fcef663 100644 --- a/src/nix/store-info.cc +++ b/src/nix/store-info.cc @@ -24,7 +24,7 @@ struct CmdInfoStore : StoreCommand, MixJSON void run(ref store) override { if (!json) { - notice("Store URL: %s", store->getUri()); + notice("Store URL: %s", store->config.getUri()); store->connect(); if (auto version = store->getVersion()) notice("Version: %s", *version); @@ -34,7 +34,7 @@ struct CmdInfoStore : StoreCommand, MixJSON nlohmann::json res; Finally printRes([&]() { printJSON(res); }); - res["url"] = store->getUri(); + res["url"] = store->config.getUri(); store->connect(); if (auto version = store->getVersion()) res["version"] = *version;