Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,14 @@ ProcessLineResult NixRepl::processLine(std::string line)
for (auto & sub : subs) {
auto * logSubP = dynamic_cast<LogStore *>(&*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;
Expand Down
2 changes: 1 addition & 1 deletion src/libstore-c/nix_api_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libstore-tests/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/libstore-tests/nix_api_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
17 changes: 7 additions & 10 deletions src/libstore-tests/ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ namespace nix {

TEST(SSHStore, constructConfig)
{
initLibStore(/*loadConfig=*/false);

auto config = make_ref<SSHStoreConfig>(
SSHStoreConfig config{
"ssh-ng",
"me@localhost:2222",
StoreConfig::Params{
Expand All @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -129,7 +132,8 @@ void BinaryCacheStore::writeNarInfo(ref<NarInfo> narInfo)
}

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(
Expand Down Expand Up @@ -427,7 +431,7 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
void BinaryCacheStore::queryPathInfoUncached(
const StorePath & storePath, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept
{
auto uri = getUri();
auto uri = config.getUri();
auto storePathS = printStorePath(storePath);
auto act = std::make_shared<Activity>(
*logger,
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -555,7 +559,7 @@ std::optional<std::string> 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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/build/drv-output-substitution-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
7 changes: 4 additions & 3 deletions src/libstore/build/substitution-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/libstore/dummy-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ struct DummyStoreConfig : public std::enable_shared_from_this<DummyStoreConfig>,
}

ref<Store> openStore() const override;

std::string getUri() const override
{
return *uriSchemes().begin();
}
};

struct DummyStore : virtual Store
Expand All @@ -46,11 +51,6 @@ struct DummyStore : virtual Store
{
}

std::string getUri() override
{
return *Config::uriSchemes().begin();
}

void queryPathInfoUncached(
const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override
{
Expand Down
13 changes: 4 additions & 9 deletions src/libstore/http-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ class HttpBinaryCacheStore : public virtual BinaryCacheStore
diskCache = getNarInfoDiskCache();
}

std::string getUri() override
{
return config->cacheUri;
}

void init() override
{
// FIXME: do this lazily?
Expand All @@ -90,7 +85,7 @@ class HttpBinaryCacheStore : public virtual BinaryCacheStore
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);
}
Expand All @@ -103,10 +98,10 @@ class HttpBinaryCacheStore : public virtual BinaryCacheStore
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
Expand Down Expand Up @@ -159,7 +154,7 @@ class HttpBinaryCacheStore : public virtual BinaryCacheStore
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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/libstore/include/nix/store/http-binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ struct HttpBinaryCacheStoreConfig : std::enable_shared_from_this<HttpBinaryCache
static std::string doc();

ref<Store> openStore() const override;

std::string getUri() const override
{
return cacheUri;
}
};

} // namespace nix
4 changes: 2 additions & 2 deletions src/libstore/include/nix/store/legacy-ssh-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct LegacySSHStoreConfig : std::enable_shared_from_this<LegacySSHStoreConfig>
static std::string doc();

ref<Store> openStore() const override;

std::string getUri() const override;
};

struct LegacySSHStore : public virtual Store
Expand All @@ -71,8 +73,6 @@ struct LegacySSHStore : public virtual Store

ref<Connection> openConnection();

std::string getUri() override;

void queryPathInfoUncached(
const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;

Expand Down
2 changes: 2 additions & 0 deletions src/libstore/include/nix/store/local-binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct LocalBinaryCacheStoreConfig : std::enable_shared_from_this<LocalBinaryCac
static std::string doc();

ref<Store> openStore() const override;

std::string getUri() const override;
};

} // namespace nix
10 changes: 5 additions & 5 deletions src/libstore/include/nix/store/local-overlay-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig

ref<Store> openStore() const override;

std::string getUri() const override
{
return "local-overlay://";
}

protected:
/**
* @return The host OS path corresponding to the store path for the
Expand Down Expand Up @@ -116,11 +121,6 @@ struct LocalOverlayStore : virtual LocalStore

LocalOverlayStore(ref<const Config>);

std::string getUri() override
{
return "local-overlay://";
}

private:
/**
* The store beneath us.
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/include/nix/store/local-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ struct LocalStoreConfig : std::enable_shared_from_this<LocalStoreConfig>,
static std::string doc();

ref<Store> openStore() const override;

std::string getUri() const override;
};

class LocalStore : public virtual IndirectRootStore, public virtual GcStore
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/libstore/include/nix/store/s3-binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public:
static std::string doc();

ref<Store> openStore() const override;

std::string getUri() const override;
};

struct S3BinaryCacheStore : virtual BinaryCacheStore
Expand Down
2 changes: 2 additions & 0 deletions src/libstore/include/nix/store/ssh-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct SSHStoreConfig : std::enable_shared_from_this<SSHStoreConfig>,
static std::string doc();

ref<Store> openStore() const override;

std::string getUri() const override;
};

struct MountedSSHStoreConfig : virtual SSHStoreConfig, virtual LocalFSStoreConfig
Expand Down
15 changes: 8 additions & 7 deletions src/libstore/include/nix/store/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ struct StoreConfig : public StoreDirConfig
* type.
*/
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;
};

/**
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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());
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/include/nix/store/store-cast.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ T & require(Store & store)
{
auto * castedStore = dynamic_cast<T *>(&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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/libstore/include/nix/store/uds-remote-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ struct UDSRemoteStoreConfig : std::enable_shared_from_this<UDSRemoteStoreConfig>
}

ref<Store> openStore() const override;

std::string getUri() const override;
};

struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore
Expand All @@ -54,8 +56,6 @@ struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore

UDSRemoteStore(ref<const Config>);

std::string getUri() override;

ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override
{
return LocalFSStore::getFSAccessor(requireValidPath);
Expand Down
Loading
Loading