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
7 changes: 4 additions & 3 deletions src/libcmd/common-eval-args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ EvalSettings evalSettings{
auto flakeRef = parseFlakeRef(fetchSettings, std::string{rest}, {}, true, false);
debug("fetching flake search path element '%s''", rest);
auto [accessor, lockedRef] =
flakeRef.resolve(fetchSettings, state.store).lazyFetch(fetchSettings, state.store);
flakeRef.resolve(fetchSettings, *state.store).lazyFetch(fetchSettings, *state.store);
auto storePath = nix::fetchToStore(
state.fetchSettings,
*state.store,
Expand Down Expand Up @@ -180,15 +180,16 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * baseDir)
{
if (EvalSettings::isPseudoUrl(s)) {
auto accessor = fetchers::downloadTarball(state.store, state.fetchSettings, EvalSettings::resolvePseudoUrl(s));
auto accessor = fetchers::downloadTarball(*state.store, state.fetchSettings, EvalSettings::resolvePseudoUrl(s));
auto storePath = fetchToStore(state.fetchSettings, *state.store, SourcePath(accessor), FetchMode::Copy);
return state.storePath(storePath);
}

else if (hasPrefix(s, "flake:")) {
experimentalFeatureSettings.require(Xp::Flakes);
auto flakeRef = parseFlakeRef(fetchSettings, std::string(s.substr(6)), {}, true, false);
auto [accessor, lockedRef] = flakeRef.resolve(fetchSettings, state.store).lazyFetch(fetchSettings, state.store);
auto [accessor, lockedRef] =
flakeRef.resolve(fetchSettings, *state.store).lazyFetch(fetchSettings, *state.store);
auto storePath = nix::fetchToStore(
state.fetchSettings, *state.store, SourcePath(accessor), FetchMode::Copy, lockedRef.input.getName());
state.allowPath(storePath);
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void completeFlakeRef(AddCompletions & completions, ref<Store> store, std::strin
Args::completeDir(completions, 0, prefix);

/* Look for registry entries that match the prefix. */
for (auto & registry : fetchers::getRegistries(fetchSettings, store)) {
for (auto & registry : fetchers::getRegistries(fetchSettings, *store)) {
for (auto & entry : registry->entries) {
auto from = entry.from.to_string();
if (!hasPrefix(prefix, "flake:") && hasPrefix(from, "flake:")) {
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3188,7 +3188,7 @@ std::optional<SourcePath> EvalState::resolveLookupPathPath(const LookupPath::Pat

if (EvalSettings::isPseudoUrl(value)) {
try {
auto accessor = fetchers::downloadTarball(store, fetchSettings, EvalSettings::resolvePseudoUrl(value));
auto accessor = fetchers::downloadTarball(*store, fetchSettings, EvalSettings::resolvePseudoUrl(value));
auto storePath = fetchToStore(fetchSettings, *store, SourcePath(accessor), FetchMode::Copy);
return finish(this->storePath(storePath));
} catch (Error & e) {
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/primops/fetchMercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value ** ar
attrs.insert_or_assign("rev", rev->gitRev());
auto input = fetchers::Input::fromAttrs(state.fetchSettings, std::move(attrs));

auto [storePath, input2] = input.fetchToStore(state.fetchSettings, state.store);
auto [storePath, input2] = input.fetchToStore(state.fetchSettings, *state.store);

auto attrs2 = state.buildBindings(8);
state.mkStorePathString(storePath, attrs2.alloc(state.s.outPath));
Expand Down
8 changes: 4 additions & 4 deletions src/libexpr/primops/fetchTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void fetchTree(
}

if (!state.settings.pureEval && !input.isDirect() && experimentalFeatureSettings.isEnabled(Xp::Flakes))
input = lookupInRegistries(state.fetchSettings, state.store, input, fetchers::UseRegistries::Limited).first;
input = lookupInRegistries(state.fetchSettings, *state.store, input, fetchers::UseRegistries::Limited).first;

if (state.settings.pureEval && !input.isLocked(state.fetchSettings)) {
if (input.getNarHash())
Expand All @@ -220,7 +220,7 @@ static void fetchTree(
}

auto cachedInput =
state.inputCache->getAccessor(state.fetchSettings, state.store, input, fetchers::UseRegistries::No);
state.inputCache->getAccessor(state.fetchSettings, *state.store, input, fetchers::UseRegistries::No);

auto storePath = state.mountInput(cachedInput.lockedInput, input, cachedInput.accessor);

Expand Down Expand Up @@ -582,10 +582,10 @@ static void fetch(
auto storePath = unpack ? fetchToStore(
state.fetchSettings,
*state.store,
fetchers::downloadTarball(state.store, state.fetchSettings, *url),
fetchers::downloadTarball(*state.store, state.fetchSettings, *url),
FetchMode::Copy,
name)
: fetchers::downloadFile(state.store, state.fetchSettings, *url, name).storePath;
: fetchers::downloadFile(*state.store, state.fetchSettings, *url, name).storePath;

if (expectedHash) {
auto hash = unpack ? state.store->queryPathInfo(storePath)->narHash
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers-tests/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ TEST_F(GitTest, submodulePeriodSupport)
{"ref", "main"},
});

auto [accessor, i] = input.getAccessor(settings, store);
auto [accessor, i] = input.getAccessor(settings, *store);

ASSERT_EQ(accessor->readFile(CanonPath("deps/sub/lib.txt")), "hello from submodule\n");
}
41 changes: 26 additions & 15 deletions src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "nix/fetchers/fetch-settings.hh"
#include "nix/fetchers/fetch-to-store.hh"
#include "nix/util/url.hh"
#include "nix/util/archive.hh"

#include <nlohmann/json.hpp>

Expand Down Expand Up @@ -119,7 +120,7 @@ Input Input::fromAttrs(const Settings & settings, Attrs && attrs)
return std::move(*res);
}

std::optional<std::string> Input::getFingerprint(ref<Store> store) const
std::optional<std::string> Input::getFingerprint(Store & store) const
{
if (!scheme)
return std::nullopt;
Expand Down Expand Up @@ -198,7 +199,7 @@ bool Input::contains(const Input & other) const
}

// FIXME: remove
std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, ref<Store> store) const
std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, Store & store) const
{
if (!scheme)
throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs()));
Expand All @@ -208,9 +209,9 @@ std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, ref<S
auto [accessor, result] = getAccessorUnchecked(settings, store);

auto storePath =
nix::fetchToStore(settings, *store, SourcePath(accessor), FetchMode::Copy, result.getName());
nix::fetchToStore(settings, store, SourcePath(accessor), FetchMode::Copy, result.getName());

auto narHash = store->queryPathInfo(storePath)->narHash;
auto narHash = store.queryPathInfo(storePath)->narHash;
result.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));

result.attrs.insert_or_assign("__final", Explicit<bool>(true));
Expand Down Expand Up @@ -297,7 +298,7 @@ void Input::checkLocks(Input specified, Input & result)
}
}

std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, ref<Store> store) const
std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, Store & store) const
{
try {
auto [accessor, result] = getAccessorUnchecked(settings, store);
Expand All @@ -313,7 +314,7 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settin
}
}

std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings & settings, ref<Store> store) const
std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings & settings, Store & store) const
{
// FIXME: cache the accessor

Expand All @@ -333,13 +334,13 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings
*/
if (isFinal() && getNarHash()) {
try {
auto storePath = computeStorePath(*store);
auto storePath = computeStorePath(store);

store->ensurePath(storePath);
store.ensurePath(storePath);

debug("using substituted/cached input '%s' in '%s'", to_string(), store->printStorePath(storePath));
debug("using substituted/cached input '%s' in '%s'", to_string(), store.printStorePath(storePath));

auto accessor = store->requireStoreObjectAccessor(storePath);
auto accessor = store.requireStoreObjectAccessor(storePath);

accessor->fingerprint = getFingerprint(store);

Expand All @@ -349,7 +350,7 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings
if (accessor->fingerprint) {
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
auto cacheKey = makeFetchToStoreCacheKey(getName(), *accessor->fingerprint, method, "/");
settings.getCache()->upsert(cacheKey, *store, {}, storePath);
settings.getCache()->upsert(cacheKey, store, {}, storePath);
}

accessor->setPathDisplay("«" + to_string() + "»");
Expand Down Expand Up @@ -377,10 +378,10 @@ Input Input::applyOverrides(std::optional<std::string> ref, std::optional<Hash>
return scheme->applyOverrides(*this, ref, rev);
}

void Input::clone(const Settings & settings, const Path & destDir) const
void Input::clone(const Settings & settings, Store & store, const std::filesystem::path & destDir) const
{
assert(scheme);
scheme->clone(settings, *this, destDir);
scheme->clone(settings, store, *this, destDir);
}

std::optional<std::filesystem::path> Input::getSourcePath() const
Expand Down Expand Up @@ -493,9 +494,19 @@ void InputScheme::putFile(
throw Error("input '%s' does not support modifying file '%s'", input.to_string(), path);
}

void InputScheme::clone(const Settings & settings, const Input & input, const Path & destDir) const
void InputScheme::clone(
const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir) const
{
throw Error("do not know how to clone input '%s'", input.to_string());
if (std::filesystem::exists(destDir))
throw Error("cannot clone into existing path %s", destDir);

auto [accessor, input2] = getAccessor(settings, store, input);

Activity act(*logger, lvlTalkative, actUnknown, fmt("copying '%s' to %s...", input2.to_string(), destDir));

auto source = sinkToSource([&](Sink & sink) { accessor->dumpPath(CanonPath::root, sink); });

restorePath(destDir, *source);
}

std::optional<ExperimentalFeature> InputScheme::experimentalFeature() const
Expand Down
11 changes: 6 additions & 5 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ struct GitInputScheme : InputScheme
return res;
}

void clone(const Settings & settings, const Input & input, const Path & destDir) const override
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
const override
{
auto repoInfo = getRepoInfo(input);

Expand Down Expand Up @@ -623,7 +624,7 @@ struct GitInputScheme : InputScheme
}

std::pair<ref<SourceAccessor>, Input>
getAccessorFromCommit(const Settings & settings, ref<Store> store, RepoInfo & repoInfo, Input && input) const
getAccessorFromCommit(const Settings & settings, Store & store, RepoInfo & repoInfo, Input && input) const
{
assert(!repoInfo.workdirInfo.isDirty);

Expand Down Expand Up @@ -797,7 +798,7 @@ struct GitInputScheme : InputScheme
}

std::pair<ref<SourceAccessor>, Input>
getAccessorFromWorkdir(const Settings & settings, ref<Store> store, RepoInfo & repoInfo, Input && input) const
getAccessorFromWorkdir(const Settings & settings, Store & store, RepoInfo & repoInfo, Input && input) const
{
auto repoPath = repoInfo.getPath().value();

Expand Down Expand Up @@ -881,7 +882,7 @@ struct GitInputScheme : InputScheme
}

std::pair<ref<SourceAccessor>, Input>
getAccessor(const Settings & settings, ref<Store> store, const Input & _input) const override
getAccessor(const Settings & settings, Store & store, const Input & _input) const override
{
Input input(_input);

Expand All @@ -903,7 +904,7 @@ struct GitInputScheme : InputScheme
return {accessor, std::move(final)};
}

std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
std::optional<std::string> getFingerprint(Store & store, const Input & input) const override
{
auto makeFingerprint = [&](const Hash & rev) {
return rev.gitRev() + (getSubmodulesAttr(input) ? ";s" : "") + (getExportIgnoreAttr(input) ? ";e" : "")
Expand Down
Loading
Loading