1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

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.
This commit is contained in:
John Ericson 2025-08-11 17:28:01 -04:00
parent f93d25c0e7
commit 0ef6f72c9c
33 changed files with 123 additions and 122 deletions

View file

@ -574,14 +574,14 @@ ProcessLineResult NixRepl::processLine(std::string line)
for (auto & sub : subs) { for (auto & sub : subs) {
auto * logSubP = dynamic_cast<LogStore *>(&*sub); auto * logSubP = dynamic_cast<LogStore *>(&*sub);
if (!logSubP) { 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; continue;
} }
auto & logSub = *logSubP; auto & logSub = *logSubP;
auto log = logSub.getBuildLog(drvPath); auto log = logSub.getBuildLog(drvPath);
if (log) { 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); logger->writeToStdout(*log);
foundLog = true; foundLog = true;
break; break;

View file

@ -62,7 +62,7 @@ nix_err nix_store_get_uri(nix_c_context * context, Store * store, nix_get_string
if (context) if (context)
context->last_err_code = NIX_OK; context->last_err_code = NIX_OK;
try { try {
auto res = store->ptr->getUri(); auto res = store->ptr->config.getUri();
return call_nix_get_string_callback(res, callback, user_data); return call_nix_get_string_callback(res, callback, user_data);
} }
NIXC_CATCH_ERRS NIXC_CATCH_ERRS

View file

@ -27,6 +27,6 @@ TEST(LegacySSHStore, constructConfig)
})); }));
auto store = config->openStore(); 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 } // namespace nix

View file

@ -104,7 +104,7 @@ TEST_F(nix_api_util_context, nix_store_open_dummy)
nix_libstore_init(ctx); nix_libstore_init(ctx);
Store * store = nix_store_open(ctx, "dummy://", nullptr); Store * store = nix_store_open(ctx, "dummy://", nullptr);
ASSERT_EQ(NIX_OK, ctx->last_err_code); 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; std::string str;
nix_store_get_version(ctx, store, OBSERVE_STRING(str)); nix_store_get_version(ctx, store, OBSERVE_STRING(str));

View file

@ -8,9 +8,7 @@ namespace nix {
TEST(SSHStore, constructConfig) TEST(SSHStore, constructConfig)
{ {
initLibStore(/*loadConfig=*/false); SSHStoreConfig config{
auto config = make_ref<SSHStoreConfig>(
"ssh-ng", "ssh-ng",
"me@localhost:2222", "me@localhost:2222",
StoreConfig::Params{ StoreConfig::Params{
@ -19,20 +17,19 @@ TEST(SSHStore, constructConfig)
// TODO #11106, no more split on space // TODO #11106, no more split on space
"foo bar", "foo bar",
}, },
}); },
};
EXPECT_EQ( EXPECT_EQ(
config->remoteProgram.get(), config.remoteProgram.get(),
(Strings{ (Strings{
"foo", "foo",
"bar", "bar",
})); }));
auto store = config->openStore(); EXPECT_EQ(config.getUri(), "ssh-ng://me@localhost:2222?remote-program=foo%20bar");
EXPECT_EQ(store->getUri(), "ssh-ng://me@localhost:2222?remote-program=foo%20bar"); config.resetOverridden();
config->resetOverridden(); EXPECT_EQ(config.getUri(), "ssh-ng://me@localhost:2222");
store = config->openStore();
EXPECT_EQ(store->getUri(), "ssh-ng://me@localhost:2222");
} }
TEST(MountedSSHStore, constructConfig) TEST(MountedSSHStore, constructConfig)

View file

@ -58,7 +58,10 @@ void BinaryCacheStore::init()
if (name == "StoreDir") { if (name == "StoreDir") {
if (value != storeDir) if (value != storeDir)
throw Error( 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") { } else if (name == "WantMassQuery") {
config.wantMassQuery.setDefault(value == "1"); config.wantMassQuery.setDefault(value == "1");
} else if (name == "Priority") { } else if (name == "Priority") {
@ -129,7 +132,8 @@ void BinaryCacheStore::writeNarInfo(ref<NarInfo> narInfo)
} }
if (diskCache) if (diskCache)
diskCache->upsertNarInfo(getUri(), std::string(narInfo->path.hashPart()), std::shared_ptr<NarInfo>(narInfo)); diskCache->upsertNarInfo(
config.getUri(), std::string(narInfo->path.hashPart()), std::shared_ptr<NarInfo>(narInfo));
} }
ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon( ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
@ -427,7 +431,7 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
void BinaryCacheStore::queryPathInfoUncached( void BinaryCacheStore::queryPathInfoUncached(
const StorePath & storePath, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept const StorePath & storePath, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
{ {
auto uri = getUri(); auto uri = config.getUri();
auto storePathS = printStorePath(storePath); auto storePathS = printStorePath(storePath);
auto act = std::make_shared<Activity>( auto act = std::make_shared<Activity>(
*logger, *logger,
@ -527,7 +531,7 @@ void BinaryCacheStore::queryRealisationUncached(
void BinaryCacheStore::registerDrvOutput(const Realisation & info) void BinaryCacheStore::registerDrvOutput(const Realisation & info)
{ {
if (diskCache) if (diskCache)
diskCache->upsertRealisation(getUri(), info); diskCache->upsertRealisation(config.getUri(), info);
auto filePath = realisationsPrefix + "/" + info.id.to_string() + ".doi"; auto filePath = realisationsPrefix + "/" + info.id.to_string() + ".doi";
upsertFile(filePath, info.toJSON().dump(), "application/json"); upsertFile(filePath, info.toJSON().dump(), "application/json");
} }
@ -555,7 +559,7 @@ std::optional<std::string> BinaryCacheStore::getBuildLogExact(const StorePath &
{ {
auto logPath = "log/" + std::string(baseNameOf(printStorePath(path))); 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); return getFile(logPath);
} }

View file

@ -98,7 +98,7 @@ Goal::Co DrvOutputSubstitutionGoal::init()
"substituter '%s' has an incompatible realisation for '%s', ignoring.\n" "substituter '%s' has an incompatible realisation for '%s', ignoring.\n"
"Local: %s\n" "Local: %s\n"
"Remote: %s", "Remote: %s",
sub->getUri(), sub->config.getUri(),
depId.to_string(), depId.to_string(),
worker.store.printStorePath(localOutputInfo->outPath), worker.store.printStorePath(localOutputInfo->outPath),
worker.store.printStorePath(depPath)); worker.store.printStorePath(depPath));

View file

@ -101,7 +101,7 @@ Goal::Co PathSubstitutionGoal::init()
} else { } else {
printError( printError(
"asked '%s' for '%s' but got '%s'", "asked '%s' for '%s' but got '%s'",
sub->getUri(), sub->config.getUri(),
worker.store.printStorePath(storePath), worker.store.printStorePath(storePath),
sub->printStorePath(info->path)); sub->printStorePath(info->path));
continue; continue;
@ -127,7 +127,7 @@ Goal::Co PathSubstitutionGoal::init()
warn( warn(
"ignoring substitute for '%s' from '%s', as it's not signed by any of the keys in 'trusted-public-keys'", "ignoring substitute for '%s' from '%s', as it's not signed by any of the keys in 'trusted-public-keys'",
worker.store.printStorePath(storePath), worker.store.printStorePath(storePath),
sub->getUri()); sub->config.getUri());
continue; continue;
} }
@ -217,7 +217,8 @@ Goal::Co PathSubstitutionGoal::tryToRun(
/* Wake up the worker loop when we're done. */ /* Wake up the worker loop when we're done. */
Finally updateStats([this]() { outPipe.writeSide.close(); }); 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); PushActivity pact(act.id);
copyStorePath(*sub, worker.store, subPath, repair, sub->config.isTrusted ? NoCheckSigs : CheckSigs); copyStorePath(*sub, worker.store, subPath, repair, sub->config.isTrusted ? NoCheckSigs : CheckSigs);

View file

@ -32,6 +32,11 @@ struct DummyStoreConfig : public std::enable_shared_from_this<DummyStoreConfig>,
} }
ref<Store> openStore() const override; ref<Store> openStore() const override;
std::string getUri() const override
{
return *uriSchemes().begin();
}
}; };
struct DummyStore : virtual Store struct DummyStore : virtual Store
@ -46,11 +51,6 @@ struct DummyStore : virtual Store
{ {
} }
std::string getUri() override
{
return *Config::uriSchemes().begin();
}
void queryPathInfoUncached( void queryPathInfoUncached(
const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override
{ {

View file

@ -62,11 +62,6 @@ public:
diskCache = getNarInfoDiskCache(); diskCache = getNarInfoDiskCache();
} }
std::string getUri() override
{
return config->cacheUri;
}
void init() override void init() override
{ {
// FIXME: do this lazily? // FIXME: do this lazily?
@ -90,7 +85,7 @@ protected:
auto state(_state.lock()); auto state(_state.lock());
if (state->enabled && settings.tryFallback) { if (state->enabled && settings.tryFallback) {
int t = 60; 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->enabled = false;
state->disabledUntil = std::chrono::steady_clock::now() + std::chrono::seconds(t); state->disabledUntil = std::chrono::steady_clock::now() + std::chrono::seconds(t);
} }
@ -103,10 +98,10 @@ protected:
return; return;
if (std::chrono::steady_clock::now() > state->disabledUntil) { if (std::chrono::steady_clock::now() > state->disabledUntil) {
state->enabled = true; state->enabled = true;
debug("re-enabling binary cache '%s'", getUri()); debug("re-enabling binary cache '%s'", config->getUri());
return; return;
} }
throw SubstituterDisabled("substituter '%s' is disabled", getUri()); throw SubstituterDisabled("substituter '%s' is disabled", config->getUri());
} }
bool fileExists(const std::string & path) override bool fileExists(const std::string & path) override
@ -159,7 +154,7 @@ protected:
getFileTransfer()->download(std::move(request), sink); getFileTransfer()->download(std::move(request), sink);
} catch (FileTransferError & e) { } catch (FileTransferError & e) {
if (e.error == FileTransfer::NotFound || e.error == FileTransfer::Forbidden) 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(); maybeDisable();
throw; throw;
} }

View file

@ -23,6 +23,11 @@ struct HttpBinaryCacheStoreConfig : std::enable_shared_from_this<HttpBinaryCache
static std::string doc(); static std::string doc();
ref<Store> openStore() const override; ref<Store> openStore() const override;
std::string getUri() const override
{
return cacheUri;
}
}; };
} // namespace nix } // namespace nix

View file

@ -53,6 +53,8 @@ struct LegacySSHStoreConfig : std::enable_shared_from_this<LegacySSHStoreConfig>
static std::string doc(); static std::string doc();
ref<Store> openStore() const override; ref<Store> openStore() const override;
std::string getUri() const override;
}; };
struct LegacySSHStore : public virtual Store struct LegacySSHStore : public virtual Store
@ -71,8 +73,6 @@ struct LegacySSHStore : public virtual Store
ref<Connection> openConnection(); ref<Connection> openConnection();
std::string getUri() override;
void queryPathInfoUncached( void queryPathInfoUncached(
const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override; const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;

View file

@ -26,6 +26,8 @@ struct LocalBinaryCacheStoreConfig : std::enable_shared_from_this<LocalBinaryCac
static std::string doc(); static std::string doc();
ref<Store> openStore() const override; ref<Store> openStore() const override;
std::string getUri() const override;
}; };
} // namespace nix } // namespace nix

View file

@ -88,6 +88,11 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig
ref<Store> openStore() const override; ref<Store> openStore() const override;
std::string getUri() const override
{
return "local-overlay://";
}
protected: protected:
/** /**
* @return The host OS path corresponding to the store path for the * @return The host OS path corresponding to the store path for the
@ -116,11 +121,6 @@ struct LocalOverlayStore : virtual LocalStore
LocalOverlayStore(ref<const Config>); LocalOverlayStore(ref<const Config>);
std::string getUri() override
{
return "local-overlay://";
}
private: private:
/** /**
* The store beneath us. * The store beneath us.

View file

@ -111,6 +111,8 @@ struct LocalStoreConfig : std::enable_shared_from_this<LocalStoreConfig>,
static std::string doc(); static std::string doc();
ref<Store> openStore() const override; ref<Store> openStore() const override;
std::string getUri() const override;
}; };
class LocalStore : public virtual IndirectRootStore, public virtual GcStore class LocalStore : public virtual IndirectRootStore, public virtual GcStore
@ -196,8 +198,6 @@ public:
* Implementations of abstract store API methods. * Implementations of abstract store API methods.
*/ */
std::string getUri() override;
bool isValidPathUncached(const StorePath & path) override; bool isValidPathUncached(const StorePath & path) override;
StorePathSet queryValidPaths(const StorePathSet & paths, SubstituteFlag maybeSubstitute = NoSubstitute) override; StorePathSet queryValidPaths(const StorePathSet & paths, SubstituteFlag maybeSubstitute = NoSubstitute) override;

View file

@ -106,6 +106,8 @@ public:
static std::string doc(); static std::string doc();
ref<Store> openStore() const override; ref<Store> openStore() const override;
std::string getUri() const override;
}; };
struct S3BinaryCacheStore : virtual BinaryCacheStore struct S3BinaryCacheStore : virtual BinaryCacheStore

View file

@ -33,6 +33,8 @@ struct SSHStoreConfig : std::enable_shared_from_this<SSHStoreConfig>,
static std::string doc(); static std::string doc();
ref<Store> openStore() const override; ref<Store> openStore() const override;
std::string getUri() const override;
}; };
struct MountedSSHStoreConfig : virtual SSHStoreConfig, virtual LocalFSStoreConfig struct MountedSSHStoreConfig : virtual SSHStoreConfig, virtual LocalFSStoreConfig

View file

@ -197,6 +197,13 @@ struct StoreConfig : public StoreDirConfig
* type. * type.
*/ */
virtual ref<Store> openStore() const = 0; virtual ref<Store> 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() {} 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. * 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) [[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());
} }
}; };

View file

@ -17,7 +17,7 @@ T & require(Store & store)
{ {
auto * castedStore = dynamic_cast<T *>(&store); auto * castedStore = dynamic_cast<T *>(&store);
if (!castedStore) 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; return *castedStore;
} }

View file

@ -44,6 +44,8 @@ struct UDSRemoteStoreConfig : std::enable_shared_from_this<UDSRemoteStoreConfig>
} }
ref<Store> openStore() const override; ref<Store> openStore() const override;
std::string getUri() const override;
}; };
struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore
@ -54,8 +56,6 @@ struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore
UDSRemoteStore(ref<const Config>); UDSRemoteStore(ref<const Config>);
std::string getUri() override;
ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override
{ {
return LocalFSStore::getFSAccessor(requireValidPath); return LocalFSStore::getFSAccessor(requireValidPath);

View file

@ -88,11 +88,9 @@ ref<LegacySSHStore::Connection> LegacySSHStore::openConnection()
return conn; return conn;
}; };
std::string LegacySSHStore::getUri() std::string LegacySSHStoreConfig::getUri() const
{ {
return ParsedURL{ return ParsedURL{.scheme = *uriSchemes().begin(), .authority = authority, .query = getQueryParams()}.to_string();
.scheme = *Config::uriSchemes().begin(), .authority = config->authority, .query = config->getQueryParams()}
.to_string();
} }
std::map<StorePath, UnkeyedValidPathInfo> LegacySSHStore::queryPathInfosUncached(const StorePathSet & paths) std::map<StorePath, UnkeyedValidPathInfo> LegacySSHStore::queryPathInfosUncached(const StorePathSet & paths)

View file

@ -23,6 +23,11 @@ std::string LocalBinaryCacheStoreConfig::doc()
; ;
} }
std::string LocalBinaryCacheStoreConfig::getUri() const
{
return "file://" + binaryCacheDir;
}
struct LocalBinaryCacheStore : virtual BinaryCacheStore struct LocalBinaryCacheStore : virtual BinaryCacheStore
{ {
using Config = LocalBinaryCacheStoreConfig; using Config = LocalBinaryCacheStoreConfig;
@ -38,11 +43,6 @@ struct LocalBinaryCacheStore : virtual BinaryCacheStore
void init() override; void init() override;
std::string getUri() override
{
return "file://" + config->binaryCacheDir;
}
protected: protected:
bool fileExists(const std::string & path) override; bool fileExists(const std::string & path) override;

View file

@ -439,11 +439,11 @@ LocalStore::~LocalStore()
} }
} }
std::string LocalStore::getUri() std::string LocalStoreConfig::getUri() const
{ {
std::ostringstream oss; std::ostringstream oss;
oss << *config->uriSchemes().begin(); oss << *uriSchemes().begin();
auto queryParams = config->getQueryParams(); auto queryParams = getQueryParams();
if (!queryParams.empty()) if (!queryParams.empty())
oss << "?"; oss << "?";
oss << encodeQuery(queryParams); oss << encodeQuery(queryParams);

View file

@ -53,7 +53,7 @@ RemoteStore::RemoteStore(const Config & config)
ref<RemoteStore::Connection> RemoteStore::openConnectionWrapper() ref<RemoteStore::Connection> RemoteStore::openConnectionWrapper()
{ {
if (failed) 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 { try {
return openConnection(); return openConnection();
} catch (...) { } catch (...) {
@ -95,7 +95,7 @@ void RemoteStore::initConnection(Connection & conn)
if (ex) if (ex)
std::rethrow_exception(ex); std::rethrow_exception(ex);
} catch (Error & e) { } 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); setOptions(conn);

View file

@ -57,11 +57,6 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor
return next->config->realStoreDir; return next->config->realStoreDir;
} }
std::string getUri() override
{
return next->getUri();
}
StorePathSet queryAllValidPaths() override; StorePathSet queryAllValidPaths() override;
void queryPathInfoUncached( void queryPathInfoUncached(

View file

@ -254,6 +254,11 @@ std::string S3BinaryCacheStoreConfig::doc()
; ;
} }
std::string S3BinaryCacheStoreConfig::getUri() const
{
return "s3://" + bucketName;
}
struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStore struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStore
{ {
Stats stats; Stats stats;
@ -269,19 +274,14 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStore
diskCache = getNarInfoDiskCache(); diskCache = getNarInfoDiskCache();
} }
std::string getUri() override
{
return "s3://" + config->bucketName;
}
void init() override void init() override
{ {
if (auto cacheInfo = diskCache->upToDateCacheExists(getUri())) { if (auto cacheInfo = diskCache->upToDateCacheExists(config->getUri())) {
config->wantMassQuery.setDefault(cacheInfo->wantMassQuery); config->wantMassQuery.setDefault(cacheInfo->wantMassQuery);
config->priority.setDefault(cacheInfo->priority); config->priority.setDefault(cacheInfo->priority);
} else { } else {
BinaryCacheStore::init(); 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); sink(*res.data);
} else } 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 StorePathSet queryAllValidPaths() override

View file

@ -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 struct SSHStore : virtual RemoteStore
{ {
using Config = SSHStoreConfig; 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 // FIXME extend daemon protocol, move implementation to RemoteStore
std::optional<std::string> getBuildLogExact(const StorePath & path) override std::optional<std::string> getBuildLogExact(const StorePath & path) override
{ {

View file

@ -300,7 +300,7 @@ Store::Store(const Store::Config & config)
assertLibStoreInitialized(); assertLibStoreInitialized();
} }
std::string Store::getUri() std::string StoreConfig::getUri() const
{ {
return ""; return "";
} }
@ -395,11 +395,11 @@ void Store::querySubstitutablePathInfos(const StorePathCAMap & paths, Substituta
"replaced path '%s' with '%s' for substituter '%s'", "replaced path '%s' with '%s' for substituter '%s'",
printStorePath(path.first), printStorePath(path.first),
sub->printStorePath(subPath), sub->printStorePath(subPath),
sub->getUri()); sub->config.getUri());
} else if (sub->storeDir != storeDir) } else if (sub->storeDir != storeDir)
continue; 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 { try {
auto info = sub->queryPathInfo(subPath); auto info = sub->queryPathInfo(subPath);
@ -439,7 +439,7 @@ bool Store::isValidPath(const StorePath & storePath)
} }
if (diskCache) { 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) { if (res.first != NarInfoDiskCache::oUnknown) {
stats.narInfoReadAverted++; stats.narInfoReadAverted++;
auto state_(state.lock()); auto state_(state.lock());
@ -455,7 +455,7 @@ bool Store::isValidPath(const StorePath & storePath)
if (diskCache && !valid) if (diskCache && !valid)
// FIXME: handle valid = true case. // FIXME: handle valid = true case.
diskCache->upsertNarInfo(getUri(), std::string(storePath.hashPart()), 0); diskCache->upsertNarInfo(config.getUri(), std::string(storePath.hashPart()), 0);
return valid; return valid;
} }
@ -509,7 +509,7 @@ std::optional<std::shared_ptr<const ValidPathInfo>> Store::queryPathInfoFromClie
} }
if (diskCache) { if (diskCache) {
auto res = diskCache->lookupNarInfo(getUri(), hashPart); auto res = diskCache->lookupNarInfo(config.getUri(), hashPart);
if (res.first != NarInfoDiskCache::oUnknown) { if (res.first != NarInfoDiskCache::oUnknown) {
stats.narInfoReadAverted++; stats.narInfoReadAverted++;
{ {
@ -554,7 +554,7 @@ void Store::queryPathInfo(const StorePath & storePath, Callback<ref<const ValidP
auto info = fut.get(); auto info = fut.get();
if (diskCache) if (diskCache)
diskCache->upsertNarInfo(getUri(), hashPart, info); diskCache->upsertNarInfo(config.getUri(), hashPart, info);
{ {
auto state_(state.lock()); auto state_(state.lock());
@ -578,7 +578,7 @@ void Store::queryRealisation(const DrvOutput & id, Callback<std::shared_ptr<cons
try { try {
if (diskCache) { if (diskCache) {
auto [cacheOutcome, maybeCachedRealisation] = diskCache->lookupRealisation(getUri(), id); auto [cacheOutcome, maybeCachedRealisation] = diskCache->lookupRealisation(config.getUri(), id);
switch (cacheOutcome) { switch (cacheOutcome) {
case NarInfoDiskCache::oValid: case NarInfoDiskCache::oValid:
debug("Returning a cached realisation for %s", id.to_string()); debug("Returning a cached realisation for %s", id.to_string());
@ -604,9 +604,9 @@ void Store::queryRealisation(const DrvOutput & id, Callback<std::shared_ptr<cons
if (diskCache) { if (diskCache) {
if (info) if (info)
diskCache->upsertRealisation(getUri(), *info); diskCache->upsertRealisation(config.getUri(), *info);
else else
diskCache->upsertAbsentRealisation(getUri(), id); diskCache->upsertAbsentRealisation(config.getUri(), id);
} }
(*callbackPtr)(std::shared_ptr<const Realisation>(info)); (*callbackPtr)(std::shared_ptr<const Realisation>(info));
@ -801,8 +801,8 @@ void copyStorePath(
if (!repair && dstStore.isValidPath(storePath)) if (!repair && dstStore.isValidPath(storePath))
return; return;
auto srcUri = srcStore.getUri(); auto srcUri = srcStore.config.getUri();
auto dstUri = dstStore.getUri(); auto dstUri = dstStore.config.getUri();
auto storePathS = srcStore.printStorePath(storePath); auto storePathS = srcStore.printStorePath(storePath);
Activity act( Activity act(
*logger, lvlInfo, actCopyPath, makeCopyPathMessage(srcUri, dstUri, storePathS), {storePathS, srcUri, dstUri}); *logger, lvlInfo, actCopyPath, makeCopyPathMessage(srcUri, dstUri, storePathS), {storePathS, srcUri, dstUri});
@ -839,7 +839,9 @@ void copyStorePath(
}, },
[&]() { [&]() {
throw EndOfFile( 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); dstStore.addToStore(*info, *source, repair, checkSigs);
@ -937,7 +939,7 @@ std::map<StorePath, StorePath> copyPaths(
"replaced path '%s' to '%s' for substituter '%s'", "replaced path '%s' to '%s' for substituter '%s'",
srcStore.printStorePath(storePathForSrc), srcStore.printStorePath(storePathForSrc),
dstStore.printStorePath(storePathForDst), dstStore.printStorePath(storePathForDst),
dstStore.getUri()); dstStore.config.getUri());
} }
return storePathForDst; return storePathForDst;
}; };
@ -955,8 +957,8 @@ std::map<StorePath, StorePath> copyPaths(
// We can reasonably assume that the copy will happen whenever we // We can reasonably assume that the copy will happen whenever we
// read the path, so log something about that at that point // read the path, so log something about that at that point
uint64_t total = 0; uint64_t total = 0;
auto srcUri = srcStore.getUri(); auto srcUri = srcStore.config.getUri();
auto dstUri = dstStore.getUri(); auto dstUri = dstStore.config.getUri();
auto storePathS = srcStore.printStorePath(missingPath); auto storePathS = srcStore.printStorePath(missingPath);
Activity act( Activity act(
*logger, *logger,

View file

@ -54,15 +54,14 @@ UDSRemoteStore::UDSRemoteStore(ref<const Config> config)
{ {
} }
std::string UDSRemoteStore::getUri() std::string UDSRemoteStoreConfig::getUri() const
{ {
return config->path == settings.nixDaemonSocketFile return path == settings.nixDaemonSocketFile ? // FIXME: Not clear why we return daemon here and not default
? // FIXME: Not clear why we return daemon here and not default // to settings.nixDaemonSocketFile
// to settings.nixDaemonSocketFile //
// // unix:// with no path also works. Change what we return?
// unix:// with no path also works. Change what we return?
"daemon" "daemon"
: std::string(*Config::uriSchemes().begin()) + "://" + config->path; : std::string(*uriSchemes().begin()) + "://" + path;
} }
void UDSRemoteStore::Connection::closeWrite() void UDSRemoteStore::Connection::closeWrite()

View file

@ -71,7 +71,7 @@ struct CmdConfigCheck : StoreCommand
void run(ref<Store> store) override void run(ref<Store> 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<LocalFSStore>()) { if (store.dynamic_pointer_cast<LocalFSStore>()) {
success &= checkNixInPath(); success &= checkNixInPath();
@ -171,9 +171,9 @@ struct CmdConfigCheck : StoreCommand
{ {
if (auto trustedMay = store->isTrustedClient()) { if (auto trustedMay = store->isTrustedClient()) {
std::string_view trusted = trustedMay.value() ? "trusted" : "not trusted"; 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 { } 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()));
} }
} }
}; };

View file

@ -48,7 +48,7 @@ struct CmdLog : InstallableCommand
for (auto & sub : subs) { for (auto & sub : subs) {
auto * logSubP = dynamic_cast<LogStore *>(&*sub); auto * logSubP = dynamic_cast<LogStore *>(&*sub);
if (!logSubP) { 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; continue;
} }
auto & logSub = *logSubP; auto & logSub = *logSubP;
@ -57,7 +57,7 @@ struct CmdLog : InstallableCommand
if (!log) if (!log)
continue; continue;
logger->stop(); 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); writeFull(getStandardOutput(), *log);
return; return;
} }

View file

@ -77,7 +77,7 @@ void execProgramInStore(
auto store2 = store.dynamic_pointer_cast<LocalFSStore>(); auto store2 = store.dynamic_pointer_cast<LocalFSStore>();
if (!store2) 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()) { if (store->storeDir != store2->getRealStoreDir()) {
Strings helperArgs = { Strings helperArgs = {

View file

@ -24,7 +24,7 @@ struct CmdInfoStore : StoreCommand, MixJSON
void run(ref<Store> store) override void run(ref<Store> store) override
{ {
if (!json) { if (!json) {
notice("Store URL: %s", store->getUri()); notice("Store URL: %s", store->config.getUri());
store->connect(); store->connect();
if (auto version = store->getVersion()) if (auto version = store->getVersion())
notice("Version: %s", *version); notice("Version: %s", *version);
@ -34,7 +34,7 @@ struct CmdInfoStore : StoreCommand, MixJSON
nlohmann::json res; nlohmann::json res;
Finally printRes([&]() { printJSON(res); }); Finally printRes([&]() { printJSON(res); });
res["url"] = store->getUri(); res["url"] = store->config.getUri();
store->connect(); store->connect();
if (auto version = store->getVersion()) if (auto version = store->getVersion())
res["version"] = *version; res["version"] = *version;