diff --git a/src/libcmd/common-eval-args.cc b/src/libcmd/common-eval-args.cc index 82deb0b71..2cbea16e0 100644 --- a/src/libcmd/common-eval-args.cc +++ b/src/libcmd/common-eval-args.cc @@ -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, @@ -180,7 +180,7 @@ 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); } @@ -188,7 +188,8 @@ SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * bas 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); diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 8a8269c6b..4548c9725 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -410,7 +410,7 @@ void completeFlakeRef(AddCompletions & completions, ref 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:")) { diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 8b068e8c7..dbbc8626f 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -3188,7 +3188,7 @@ std::optional 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) { diff --git a/src/libexpr/primops/fetchMercurial.cc b/src/libexpr/primops/fetchMercurial.cc index e1a9c8679..2174275ec 100644 --- a/src/libexpr/primops/fetchMercurial.cc +++ b/src/libexpr/primops/fetchMercurial.cc @@ -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)); diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index 82744bf0b..6fd2fe76b 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -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()) @@ -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); @@ -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 diff --git a/src/libfetchers-tests/git.cc b/src/libfetchers-tests/git.cc index e8092b86c..abc3dd74c 100644 --- a/src/libfetchers-tests/git.cc +++ b/src/libfetchers-tests/git.cc @@ -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"); } diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index 9ebad6220..f491cd6ab 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -120,7 +120,7 @@ Input Input::fromAttrs(const Settings & settings, Attrs && attrs) return std::move(*res); } -std::optional Input::getFingerprint(ref store) const +std::optional Input::getFingerprint(Store & store) const { if (!scheme) return std::nullopt; @@ -199,7 +199,7 @@ bool Input::contains(const Input & other) const } // FIXME: remove -std::pair Input::fetchToStore(const Settings & settings, ref store) const +std::pair Input::fetchToStore(const Settings & settings, Store & store) const { if (!scheme) throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs())); @@ -209,9 +209,9 @@ std::pair Input::fetchToStore(const Settings & settings, refqueryPathInfo(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(true)); @@ -298,7 +298,7 @@ void Input::checkLocks(Input specified, Input & result) } } -std::pair, Input> Input::getAccessor(const Settings & settings, ref store) const +std::pair, Input> Input::getAccessor(const Settings & settings, Store & store) const { try { auto [accessor, result] = getAccessorUnchecked(settings, store); @@ -314,7 +314,7 @@ std::pair, Input> Input::getAccessor(const Settings & settin } } -std::pair, Input> Input::getAccessorUnchecked(const Settings & settings, ref store) const +std::pair, Input> Input::getAccessorUnchecked(const Settings & settings, Store & store) const { // FIXME: cache the accessor @@ -334,13 +334,13 @@ std::pair, 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); @@ -350,7 +350,7 @@ std::pair, 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() + "»"); @@ -378,7 +378,7 @@ Input Input::applyOverrides(std::optional ref, std::optional return scheme->applyOverrides(*this, ref, rev); } -void Input::clone(const Settings & settings, ref store, const std::filesystem::path & destDir) const +void Input::clone(const Settings & settings, Store & store, const std::filesystem::path & destDir) const { assert(scheme); scheme->clone(settings, store, *this, destDir); @@ -495,7 +495,7 @@ void InputScheme::putFile( } void InputScheme::clone( - const Settings & settings, ref store, const Input & input, const std::filesystem::path & destDir) const + const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir) const { if (std::filesystem::exists(destDir)) throw Error("cannot clone into existing path %s", destDir); diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 1f926a86c..0ffb5e2e8 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -278,7 +278,7 @@ struct GitInputScheme : InputScheme return res; } - void clone(const Settings & settings, ref store, const Input & input, const std::filesystem::path & destDir) + void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir) const override { auto repoInfo = getRepoInfo(input); @@ -624,7 +624,7 @@ struct GitInputScheme : InputScheme } std::pair, Input> - getAccessorFromCommit(const Settings & settings, ref store, RepoInfo & repoInfo, Input && input) const + getAccessorFromCommit(const Settings & settings, Store & store, RepoInfo & repoInfo, Input && input) const { assert(!repoInfo.workdirInfo.isDirty); @@ -798,7 +798,7 @@ struct GitInputScheme : InputScheme } std::pair, Input> - getAccessorFromWorkdir(const Settings & settings, ref store, RepoInfo & repoInfo, Input && input) const + getAccessorFromWorkdir(const Settings & settings, Store & store, RepoInfo & repoInfo, Input && input) const { auto repoPath = repoInfo.getPath().value(); @@ -882,7 +882,7 @@ struct GitInputScheme : InputScheme } std::pair, Input> - getAccessor(const Settings & settings, ref store, const Input & _input) const override + getAccessor(const Settings & settings, Store & store, const Input & _input) const override { Input input(_input); @@ -904,7 +904,7 @@ struct GitInputScheme : InputScheme return {accessor, std::move(final)}; } - std::optional getFingerprint(ref store, const Input & input) const override + std::optional getFingerprint(Store & store, const Input & input) const override { auto makeFingerprint = [&](const Hash & rev) { return rev.gitRev() + (getSubmodulesAttr(input) ? ";s" : "") + (getExportIgnoreAttr(input) ? ";e" : "") diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index 1d8e0225e..3cce28e04 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -233,7 +233,7 @@ struct GitArchiveInputScheme : InputScheme std::optional treeHash; }; - virtual RefInfo getRevFromRef(const Settings & settings, nix::ref store, const Input & input) const = 0; + virtual RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const = 0; virtual DownloadUrl getDownloadUrl(const Settings & settings, const Input & input) const = 0; @@ -243,7 +243,7 @@ struct GitArchiveInputScheme : InputScheme time_t lastModified; }; - std::pair downloadArchive(const Settings & settings, ref store, Input input) const + std::pair downloadArchive(const Settings & settings, Store & store, Input input) const { if (!maybeGetStrAttr(input.attrs, "ref")) input.attrs.insert_or_assign("ref", "HEAD"); @@ -316,7 +316,7 @@ struct GitArchiveInputScheme : InputScheme } std::pair, Input> - getAccessor(const Settings & settings, ref store, const Input & _input) const override + getAccessor(const Settings & settings, Store & store, const Input & _input) const override { auto [input, tarballInfo] = downloadArchive(settings, store, _input); @@ -345,7 +345,7 @@ struct GitArchiveInputScheme : InputScheme return Xp::Flakes; } - std::optional getFingerprint(ref store, const Input & input) const override + std::optional getFingerprint(Store & store, const Input & input) const override { if (auto rev = input.getRev()) return rev->gitRev(); @@ -387,7 +387,7 @@ struct GitHubInputScheme : GitArchiveInputScheme return getStrAttr(input.attrs, "repo"); } - RefInfo getRevFromRef(const Settings & settings, nix::ref store, const Input & input) const override + RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override { auto host = getHost(input); auto url = fmt( @@ -401,7 +401,7 @@ struct GitHubInputScheme : GitArchiveInputScheme auto downloadResult = downloadFile(store, settings, url, "source", headers); auto json = nlohmann::json::parse( - store->requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root)); + store.requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root)); return RefInfo{ .rev = Hash::parseAny(std::string{json["sha"]}, HashAlgorithm::SHA1), @@ -426,7 +426,7 @@ struct GitHubInputScheme : GitArchiveInputScheme return DownloadUrl{parseURL(url), headers}; } - void clone(const Settings & settings, ref store, const Input & input, const std::filesystem::path & destDir) + void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir) const override { auto host = getHost(input); @@ -462,7 +462,7 @@ struct GitLabInputScheme : GitArchiveInputScheme return std::make_pair(token.substr(0, fldsplit), token.substr(fldsplit + 1)); } - RefInfo getRevFromRef(const Settings & settings, nix::ref store, const Input & input) const override + RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override { auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com"); // See rate limiting note below @@ -477,7 +477,7 @@ struct GitLabInputScheme : GitArchiveInputScheme auto downloadResult = downloadFile(store, settings, url, "source", headers); auto json = nlohmann::json::parse( - store->requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root)); + store.requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root)); if (json.is_array() && json.size() >= 1 && json[0]["id"] != nullptr) { return RefInfo{.rev = Hash::parseAny(std::string(json[0]["id"]), HashAlgorithm::SHA1)}; @@ -508,7 +508,7 @@ struct GitLabInputScheme : GitArchiveInputScheme return DownloadUrl{parseURL(url), headers}; } - void clone(const Settings & settings, ref store, const Input & input, const std::filesystem::path & destDir) + void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir) const override { auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com"); @@ -538,7 +538,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme // Once it is implemented, however, should work as expected. } - RefInfo getRevFromRef(const Settings & settings, nix::ref store, const Input & input) const override + RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override { // TODO: In the future, when the sourcehut graphql API is implemented for mercurial // and with anonymous access, this method should use it instead. @@ -554,7 +554,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme std::string refUri; if (ref == "HEAD") { auto downloadFileResult = downloadFile(store, settings, fmt("%s/HEAD", base_url), "source", headers); - auto contents = store->requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root); + auto contents = store.requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root); auto remoteLine = git::parseLsRemoteLine(getLine(contents).first); if (!remoteLine) { @@ -567,7 +567,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme std::regex refRegex(refUri); auto downloadFileResult = downloadFile(store, settings, fmt("%s/info/refs", base_url), "source", headers); - auto contents = store->requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root); + auto contents = store.requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root); std::istringstream is(contents); std::string line; @@ -598,7 +598,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme return DownloadUrl{parseURL(url), headers}; } - void clone(const Settings & settings, ref store, const Input & input, const std::filesystem::path & destDir) + void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir) const override { auto host = maybeGetStrAttr(input.attrs, "host").value_or("git.sr.ht"); diff --git a/src/libfetchers/include/nix/fetchers/fetchers.hh b/src/libfetchers/include/nix/fetchers/fetchers.hh index 1c126564f..2a7c6429a 100644 --- a/src/libfetchers/include/nix/fetchers/fetchers.hh +++ b/src/libfetchers/include/nix/fetchers/fetchers.hh @@ -113,7 +113,7 @@ public: * Fetch the entire input into the Nix store, returning the * location in the Nix store and the locked input. */ - std::pair fetchToStore(const Settings & settings, ref store) const; + std::pair fetchToStore(const Settings & settings, Store & store) const; /** * Check the locking attributes in `result` against @@ -133,17 +133,17 @@ public: * input without copying it to the store. Also return a possibly * unlocked input. */ - std::pair, Input> getAccessor(const Settings & settings, ref store) const; + std::pair, Input> getAccessor(const Settings & settings, Store & store) const; private: - std::pair, Input> getAccessorUnchecked(const Settings & settings, ref store) const; + std::pair, Input> getAccessorUnchecked(const Settings & settings, Store & store) const; public: Input applyOverrides(std::optional ref, std::optional rev) const; - void clone(const Settings & settings, ref store, const std::filesystem::path & destDir) const; + void clone(const Settings & settings, Store & store, const std::filesystem::path & destDir) const; std::optional getSourcePath() const; @@ -173,7 +173,7 @@ public: * * This is not a stable identifier between Nix versions, but not guaranteed to change either. */ - std::optional getFingerprint(ref store) const; + std::optional getFingerprint(Store & store) const; }; /** @@ -216,8 +216,8 @@ struct InputScheme virtual Input applyOverrides(const Input & input, std::optional ref, std::optional rev) const; - virtual void clone( - const Settings & settings, ref store, const Input & input, const std::filesystem::path & destDir) const; + virtual void + clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir) const; virtual std::optional getSourcePath(const Input & input) const; @@ -228,7 +228,7 @@ struct InputScheme std::optional commitMsg) const; virtual std::pair, Input> - getAccessor(const Settings & settings, ref store, const Input & input) const = 0; + getAccessor(const Settings & settings, Store & store, const Input & input) const = 0; /** * Is this `InputScheme` part of an experimental feature? @@ -240,7 +240,7 @@ struct InputScheme return true; } - virtual std::optional getFingerprint(ref store, const Input & input) const + virtual std::optional getFingerprint(Store & store, const Input & input) const { return std::nullopt; } diff --git a/src/libfetchers/include/nix/fetchers/input-cache.hh b/src/libfetchers/include/nix/fetchers/input-cache.hh index ad702dfda..463927cea 100644 --- a/src/libfetchers/include/nix/fetchers/input-cache.hh +++ b/src/libfetchers/include/nix/fetchers/input-cache.hh @@ -16,7 +16,7 @@ struct InputCache }; CachedResult - getAccessor(const Settings & settings, ref store, const Input & originalInput, UseRegistries useRegistries); + getAccessor(const Settings & settings, Store & store, const Input & originalInput, UseRegistries useRegistries); struct CachedInput { diff --git a/src/libfetchers/include/nix/fetchers/registry.hh b/src/libfetchers/include/nix/fetchers/registry.hh index cfdf3130b..a403f0318 100644 --- a/src/libfetchers/include/nix/fetchers/registry.hh +++ b/src/libfetchers/include/nix/fetchers/registry.hh @@ -57,7 +57,7 @@ std::shared_ptr getCustomRegistry(const Settings & settings, const Pat Path getUserRegistryPath(); -Registries getRegistries(const Settings & settings, ref store); +Registries getRegistries(const Settings & settings, Store & store); void overrideRegistry(const Settings & settings, const Input & from, const Input & to, const Attrs & extraAttrs); @@ -72,6 +72,6 @@ enum class UseRegistries : int { * use the registries for which the filter function returns true. */ std::pair -lookupInRegistries(const Settings & settings, ref store, const Input & input, UseRegistries useRegistries); +lookupInRegistries(const Settings & settings, Store & store, const Input & input, UseRegistries useRegistries); } // namespace nix::fetchers diff --git a/src/libfetchers/include/nix/fetchers/tarball.hh b/src/libfetchers/include/nix/fetchers/tarball.hh index be816a24c..e9e569d3c 100644 --- a/src/libfetchers/include/nix/fetchers/tarball.hh +++ b/src/libfetchers/include/nix/fetchers/tarball.hh @@ -25,7 +25,7 @@ struct DownloadFileResult }; DownloadFileResult downloadFile( - ref store, + Store & store, const Settings & settings, const std::string & url, const std::string & name, @@ -43,6 +43,6 @@ struct DownloadTarballResult * Download and import a tarball into the Git cache. The result is the * Git tree hash of the root directory. */ -ref downloadTarball(ref store, const Settings & settings, const std::string & url); +ref downloadTarball(Store & store, const Settings & settings, const std::string & url); } // namespace nix::fetchers diff --git a/src/libfetchers/indirect.cc b/src/libfetchers/indirect.cc index 66eef14dd..9fb781282 100644 --- a/src/libfetchers/indirect.cc +++ b/src/libfetchers/indirect.cc @@ -107,7 +107,7 @@ struct IndirectInputScheme : InputScheme } std::pair, Input> - getAccessor(const Settings & settings, ref store, const Input & input) const override + getAccessor(const Settings & settings, Store & store, const Input & input) const override { throw Error("indirect input '%s' cannot be fetched directly", input.to_string()); } diff --git a/src/libfetchers/input-cache.cc b/src/libfetchers/input-cache.cc index 6da15bd3d..652d5ce79 100644 --- a/src/libfetchers/input-cache.cc +++ b/src/libfetchers/input-cache.cc @@ -6,7 +6,7 @@ namespace nix::fetchers { InputCache::CachedResult InputCache::getAccessor( - const Settings & settings, ref store, const Input & originalInput, UseRegistries useRegistries) + const Settings & settings, Store & store, const Input & originalInput, UseRegistries useRegistries) { auto fetched = lookup(originalInput); Input resolvedInput = originalInput; diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index 433690c7b..134377b6d 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -154,7 +154,7 @@ struct MercurialInputScheme : InputScheme return {isLocal, isLocal ? renderUrlPathEnsureLegal(url.path) : url.to_string()}; } - StorePath fetchToStore(const Settings & settings, ref store, Input & input) const + StorePath fetchToStore(const Settings & settings, Store & store, Input & input) const { auto origRev = input.getRev(); @@ -205,7 +205,7 @@ struct MercurialInputScheme : InputScheme return files.count(file); }; - auto storePath = store->addToStore( + auto storePath = store.addToStore( input.getName(), {getFSSourceAccessor(), CanonPath(actualPath)}, ContentAddressMethod::Raw::NixArchive, @@ -226,7 +226,7 @@ struct MercurialInputScheme : InputScheme "Hash '%s' is not supported by Mercurial. Only sha1 is supported.", rev.to_string(HashFormat::Base16, true)); - return Cache::Key{"hgRev", {{"store", store->storeDir}, {"name", name}, {"rev", input.getRev()->gitRev()}}}; + return Cache::Key{"hgRev", {{"store", store.storeDir}, {"name", name}, {"rev", input.getRev()->gitRev()}}}; }; auto makeResult = [&](const Attrs & infoAttrs, const StorePath & storePath) -> StorePath { @@ -246,7 +246,7 @@ struct MercurialInputScheme : InputScheme /* If we have a rev, check if we have a cached store path. */ if (auto rev = input.getRev()) { - if (auto res = settings.getCache()->lookupStorePath(revInfoKey(*rev), *store)) + if (auto res = settings.getCache()->lookupStorePath(revInfoKey(*rev), store)) return makeResult(res->value, res->storePath); } @@ -300,7 +300,7 @@ struct MercurialInputScheme : InputScheme /* Now that we have the rev, check the cache again for a cached store path. */ - if (auto res = settings.getCache()->lookupStorePath(revInfoKey(rev), *store)) + if (auto res = settings.getCache()->lookupStorePath(revInfoKey(rev), store)) return makeResult(res->value, res->storePath); Path tmpDir = createTempDir(); @@ -310,7 +310,7 @@ struct MercurialInputScheme : InputScheme deletePath(tmpDir + "/.hg_archival.txt"); - auto storePath = store->addToStore(name, {getFSSourceAccessor(), CanonPath(tmpDir)}); + auto storePath = store.addToStore(name, {getFSSourceAccessor(), CanonPath(tmpDir)}); Attrs infoAttrs({ {"revCount", (uint64_t) revCount}, @@ -319,18 +319,18 @@ struct MercurialInputScheme : InputScheme if (!origRev) settings.getCache()->upsert(refToRevKey, {{"rev", rev.gitRev()}}); - settings.getCache()->upsert(revInfoKey(rev), *store, infoAttrs, storePath); + settings.getCache()->upsert(revInfoKey(rev), store, infoAttrs, storePath); return makeResult(infoAttrs, std::move(storePath)); } std::pair, Input> - getAccessor(const Settings & settings, ref store, const Input & _input) const override + getAccessor(const Settings & settings, Store & store, const Input & _input) const override { Input input(_input); auto storePath = fetchToStore(settings, store, input); - auto accessor = store->requireStoreObjectAccessor(storePath); + auto accessor = store.requireStoreObjectAccessor(storePath); accessor->setPathDisplay("«" + input.to_string() + "»"); @@ -342,7 +342,7 @@ struct MercurialInputScheme : InputScheme return (bool) input.getRev(); } - std::optional getFingerprint(ref store, const Input & input) const override + std::optional getFingerprint(Store & store, const Input & input) const override { if (auto rev = input.getRev()) return rev->gitRev(); diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index 520534bf5..de4d439dd 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -117,7 +117,7 @@ struct PathInputScheme : InputScheme } std::pair, Input> - getAccessor(const Settings & settings, ref store, const Input & _input) const override + getAccessor(const Settings & settings, Store & store, const Input & _input) const override { Input input(_input); auto path = getStrAttr(input.attrs, "path"); @@ -125,31 +125,31 @@ struct PathInputScheme : InputScheme auto absPath = getAbsPath(input); // FIXME: check whether access to 'path' is allowed. - auto storePath = store->maybeParseStorePath(absPath.string()); + auto storePath = store.maybeParseStorePath(absPath.string()); if (storePath) - store->addTempRoot(*storePath); + store.addTempRoot(*storePath); time_t mtime = 0; - if (!storePath || storePath->name() != "source" || !store->isValidPath(*storePath)) { + if (!storePath || storePath->name() != "source" || !store.isValidPath(*storePath)) { Activity act(*logger, lvlTalkative, actUnknown, fmt("copying %s to the store", absPath)); // FIXME: try to substitute storePath. auto src = sinkToSource( [&](Sink & sink) { mtime = dumpPathAndGetMtime(absPath.string(), sink, defaultPathFilter); }); - storePath = store->addToStoreFromDump(*src, "source"); + storePath = store.addToStoreFromDump(*src, "source"); } - auto accessor = store->requireStoreObjectAccessor(*storePath); + auto accessor = store.requireStoreObjectAccessor(*storePath); // To prevent `fetchToStore()` copying the path again to Nix // store, pre-create an entry in the fetcher cache. - auto info = store->queryPathInfo(*storePath); + auto info = store.queryPathInfo(*storePath); accessor->fingerprint = - fmt("path:%s", store->queryPathInfo(*storePath)->narHash.to_string(HashFormat::SRI, true)); + fmt("path:%s", store.queryPathInfo(*storePath)->narHash.to_string(HashFormat::SRI, true)); settings.getCache()->upsert( makeFetchToStoreCacheKey( input.getName(), *accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, "/"), - *store, + store, {}, *storePath); diff --git a/src/libfetchers/registry.cc b/src/libfetchers/registry.cc index 48293095d..b2c8dc237 100644 --- a/src/libfetchers/registry.cc +++ b/src/libfetchers/registry.cc @@ -136,7 +136,7 @@ void overrideRegistry(const Settings & settings, const Input & from, const Input getFlagRegistry(settings)->add(from, to, extraAttrs); } -static std::shared_ptr getGlobalRegistry(const Settings & settings, ref store) +static std::shared_ptr getGlobalRegistry(const Settings & settings, Store & store) { static auto reg = [&]() { auto path = settings.flakeRegistry.get(); @@ -149,9 +149,9 @@ static std::shared_ptr getGlobalRegistry(const Settings & settings, re [&] -> SourcePath { if (!isAbsolute(path)) { auto storePath = downloadFile(store, settings, path, "flake-registry.json").storePath; - if (auto store2 = store.dynamic_pointer_cast()) + if (auto store2 = dynamic_cast(&store)) store2->addPermRoot(storePath, getCacheDir() + "/flake-registry.json"); - return {store->requireStoreObjectAccessor(storePath)}; + return {store.requireStoreObjectAccessor(storePath)}; } else { return SourcePath{getFSSourceAccessor(), CanonPath{path}}.resolveSymlinks(); } @@ -162,7 +162,7 @@ static std::shared_ptr getGlobalRegistry(const Settings & settings, re return reg; } -Registries getRegistries(const Settings & settings, ref store) +Registries getRegistries(const Settings & settings, Store & store) { Registries registries; registries.push_back(getFlagRegistry(settings)); @@ -173,7 +173,7 @@ Registries getRegistries(const Settings & settings, ref store) } std::pair -lookupInRegistries(const Settings & settings, ref store, const Input & _input, UseRegistries useRegistries) +lookupInRegistries(const Settings & settings, Store & store, const Input & _input, UseRegistries useRegistries) { Attrs extraAttrs; int n = 0; diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index 1891c6964..a02d8d467 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -13,7 +13,7 @@ namespace nix::fetchers { DownloadFileResult downloadFile( - ref store, + Store & store, const Settings & settings, const std::string & url, const std::string & name, @@ -28,7 +28,7 @@ DownloadFileResult downloadFile( {"name", name}, }}}; - auto cached = settings.getCache()->lookupStorePath(key, *store); + auto cached = settings.getCache()->lookupStorePath(key, store); auto useCached = [&]() -> DownloadFileResult { return { @@ -74,7 +74,7 @@ DownloadFileResult downloadFile( dumpString(res.data, sink); auto hash = hashString(HashAlgorithm::SHA256, res.data); auto info = ValidPathInfo::makeFromCA( - *store, + store, name, FixedOutputInfo{ .method = FileIngestionMethod::Flat, @@ -84,7 +84,7 @@ DownloadFileResult downloadFile( hashString(HashAlgorithm::SHA256, sink.s)); info.narSize = sink.s.size(); auto source = StringSource{sink.s}; - store->addToStore(info, source, NoRepair, NoCheckSigs); + store.addToStore(info, source, NoRepair, NoCheckSigs); storePath = std::move(info.path); } @@ -93,7 +93,7 @@ DownloadFileResult downloadFile( key.second.insert_or_assign("url", url); assert(!res.urls.empty()); infoAttrs.insert_or_assign("url", *res.urls.rbegin()); - settings.getCache()->upsert(key, *store, infoAttrs, *storePath); + settings.getCache()->upsert(key, store, infoAttrs, *storePath); } return { @@ -214,7 +214,7 @@ static DownloadTarballResult downloadTarball_( return attrsToResult(infoAttrs); } -ref downloadTarball(ref store, const Settings & settings, const std::string & url) +ref downloadTarball(Store & store, const Settings & settings, const std::string & url) { /* Go through Input::getAccessor() to ensure that the resulting accessor has a fingerprint. */ @@ -341,7 +341,7 @@ struct FileInputScheme : CurlInputScheme } std::pair, Input> - getAccessor(const Settings & settings, ref store, const Input & _input) const override + getAccessor(const Settings & settings, Store & store, const Input & _input) const override { auto input(_input); @@ -351,10 +351,10 @@ struct FileInputScheme : CurlInputScheme tarballs. */ auto file = downloadFile(store, settings, getStrAttr(input.attrs, "url"), input.getName()); - auto narHash = store->queryPathInfo(file.storePath)->narHash; + auto narHash = store.queryPathInfo(file.storePath)->narHash; input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true)); - auto accessor = ref{store->getFSAccessor(file.storePath)}; + auto accessor = ref{store.getFSAccessor(file.storePath)}; accessor->setPathDisplay("«" + input.to_string() + "»"); @@ -379,7 +379,7 @@ struct TarballInputScheme : CurlInputScheme } std::pair, Input> - getAccessor(const Settings & settings, ref store, const Input & _input) const override + getAccessor(const Settings & settings, Store & store, const Input & _input) const override { auto input(_input); @@ -404,7 +404,7 @@ struct TarballInputScheme : CurlInputScheme return {result.accessor, input}; } - std::optional getFingerprint(ref store, const Input & input) const override + std::optional getFingerprint(Store & store, const Input & input) const override { if (auto narHash = input.getNarHash()) return narHash->to_string(HashFormat::SRI, true); diff --git a/src/libflake/flake.cc b/src/libflake/flake.cc index b206ff13b..6e5fa6ca1 100644 --- a/src/libflake/flake.cc +++ b/src/libflake/flake.cc @@ -373,7 +373,7 @@ static Flake getFlake( { // Fetch a lazy tree first. auto cachedInput = - state.inputCache->getAccessor(state.fetchSettings, state.store, originalRef.input, useRegistries); + state.inputCache->getAccessor(state.fetchSettings, *state.store, originalRef.input, useRegistries); auto subdir = fetchers::maybeGetStrAttr(cachedInput.extraAttrs, "dir").value_or(originalRef.subdir); auto resolvedRef = FlakeRef(std::move(cachedInput.resolvedInput), subdir); @@ -390,7 +390,7 @@ static Flake getFlake( // FIXME: need to remove attrs that are invalidated by the changed input attrs, such as 'narHash'. newLockedRef.input.attrs.erase("narHash"); auto cachedInput2 = state.inputCache->getAccessor( - state.fetchSettings, state.store, newLockedRef.input, fetchers::UseRegistries::No); + state.fetchSettings, *state.store, newLockedRef.input, fetchers::UseRegistries::No); cachedInput.accessor = cachedInput2.accessor; lockedRef = FlakeRef(std::move(cachedInput2.lockedInput), newLockedRef.subdir); } @@ -756,7 +756,7 @@ lockFlake(const Settings & settings, EvalState & state, const FlakeRef & topRef, return {*resolvedPath, *input.ref}; } else { auto cachedInput = state.inputCache->getAccessor( - state.fetchSettings, state.store, input.ref->input, useRegistriesInputs); + state.fetchSettings, *state.store, input.ref->input, useRegistriesInputs); auto lockedRef = FlakeRef(std::move(cachedInput.lockedInput), input.ref->subdir); @@ -975,7 +975,7 @@ void callFlake(EvalState & state, const LockedFlake & lockedFlake, Value & vRes) state.callFunction(*vCallFlake, args, vRes, noPos); } -std::optional LockedFlake::getFingerprint(ref store, const fetchers::Settings & fetchSettings) const +std::optional LockedFlake::getFingerprint(Store & store, const fetchers::Settings & fetchSettings) const { if (lockFile.isUnlocked(fetchSettings)) return std::nullopt; @@ -1005,7 +1005,7 @@ Flake::~Flake() {} ref openEvalCache(EvalState & state, ref lockedFlake) { auto fingerprint = state.settings.useEvalCache && state.settings.pureEval - ? lockedFlake->getFingerprint(state.store, state.fetchSettings) + ? lockedFlake->getFingerprint(*state.store, state.fetchSettings) : std::nullopt; auto rootLoader = [&state, lockedFlake]() { /* For testing whether the evaluation cache is diff --git a/src/libflake/flakeref.cc b/src/libflake/flakeref.cc index 1cce46b25..8c955c72d 100644 --- a/src/libflake/flakeref.cc +++ b/src/libflake/flakeref.cc @@ -64,8 +64,8 @@ std::ostream & operator<<(std::ostream & str, const FlakeRef & flakeRef) return str; } -FlakeRef FlakeRef::resolve( - const fetchers::Settings & fetchSettings, ref store, fetchers::UseRegistries useRegistries) const +FlakeRef +FlakeRef::resolve(const fetchers::Settings & fetchSettings, Store & store, fetchers::UseRegistries useRegistries) const { auto [input2, extraAttrs] = lookupInRegistries(fetchSettings, store, input, useRegistries); return FlakeRef(std::move(input2), fetchers::maybeGetStrAttr(extraAttrs, "dir").value_or(subdir)); @@ -289,7 +289,7 @@ FlakeRef FlakeRef::fromAttrs(const fetchers::Settings & fetchSettings, const fet } std::pair, FlakeRef> -FlakeRef::lazyFetch(const fetchers::Settings & fetchSettings, ref store) const +FlakeRef::lazyFetch(const fetchers::Settings & fetchSettings, Store & store) const { auto [accessor, lockedInput] = input.getAccessor(fetchSettings, store); return {accessor, FlakeRef(std::move(lockedInput), subdir)}; diff --git a/src/libflake/include/nix/flake/flake.hh b/src/libflake/include/nix/flake/flake.hh index 79a50f0f7..09255fbef 100644 --- a/src/libflake/include/nix/flake/flake.hh +++ b/src/libflake/include/nix/flake/flake.hh @@ -135,7 +135,7 @@ struct LockedFlake */ std::map, SourcePath> nodePaths; - std::optional getFingerprint(ref store, const fetchers::Settings & fetchSettings) const; + std::optional getFingerprint(Store & store, const fetchers::Settings & fetchSettings) const; }; struct LockFlags diff --git a/src/libflake/include/nix/flake/flakeref.hh b/src/libflake/include/nix/flake/flakeref.hh index bcc73b30c..91c93af41 100644 --- a/src/libflake/include/nix/flake/flakeref.hh +++ b/src/libflake/include/nix/flake/flakeref.hh @@ -73,13 +73,12 @@ struct FlakeRef FlakeRef resolve( const fetchers::Settings & fetchSettings, - ref store, + Store & store, fetchers::UseRegistries useRegistries = fetchers::UseRegistries::All) const; static FlakeRef fromAttrs(const fetchers::Settings & fetchSettings, const fetchers::Attrs & attrs); - std::pair, FlakeRef> - lazyFetch(const fetchers::Settings & fetchSettings, ref store) const; + std::pair, FlakeRef> lazyFetch(const fetchers::Settings & fetchSettings, Store & store) const; /** * Canonicalize a flakeref for the purpose of comparing "old" and diff --git a/src/nix/flake-prefetch-inputs.cc b/src/nix/flake-prefetch-inputs.cc index 77ec41193..4ea6342c3 100644 --- a/src/nix/flake-prefetch-inputs.cc +++ b/src/nix/flake-prefetch-inputs.cc @@ -45,7 +45,7 @@ struct CmdFlakePrefetchInputs : FlakeCommand if (auto lockedNode = dynamic_cast(&node)) { try { Activity act(*logger, lvlInfo, actUnknown, fmt("fetching '%s'", lockedNode->lockedRef)); - auto accessor = lockedNode->lockedRef.input.getAccessor(fetchSettings, store).first; + auto accessor = lockedNode->lockedRef.input.getAccessor(fetchSettings, *store).first; fetchToStore( fetchSettings, *store, accessor, FetchMode::Copy, lockedNode->lockedRef.input.getName()); } catch (Error & e) { diff --git a/src/nix/flake.cc b/src/nix/flake.cc index b1a52fc83..be19b5317 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -240,7 +240,7 @@ struct CmdFlakeMetadata : FlakeCommand, MixJSON j["lastModified"] = *lastModified; j["path"] = storePath; j["locks"] = lockedFlake.lockFile.toJSON().first; - if (auto fingerprint = lockedFlake.getFingerprint(store, fetchSettings)) + if (auto fingerprint = lockedFlake.getFingerprint(*store, fetchSettings)) j["fingerprint"] = fingerprint->to_string(HashFormat::Base16, false); printJSON(j); } else { @@ -260,7 +260,7 @@ struct CmdFlakeMetadata : FlakeCommand, MixJSON logger->cout( ANSI_BOLD "Last modified:" ANSI_NORMAL " %s", std::put_time(std::localtime(&*lastModified), "%F %T")); - if (auto fingerprint = lockedFlake.getFingerprint(store, fetchSettings)) + if (auto fingerprint = lockedFlake.getFingerprint(*store, fetchSettings)) logger->cout( ANSI_BOLD "Fingerprint:" ANSI_NORMAL " %s", fingerprint->to_string(HashFormat::Base16, false)); @@ -1049,7 +1049,7 @@ struct CmdFlakeClone : FlakeCommand if (destDir.empty()) throw Error("missing flag '--dest'"); - getFlakeRef().resolve(fetchSettings, store).input.clone(fetchSettings, store, destDir); + getFlakeRef().resolve(fetchSettings, *store).input.clone(fetchSettings, *store, destDir); } }; @@ -1100,7 +1100,7 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun, MixNoCheckSigs std::optional storePath; if (!(*inputNode)->lockedRef.input.isRelative()) { storePath = dryRun ? (*inputNode)->lockedRef.input.computeStorePath(*store) - : (*inputNode)->lockedRef.input.fetchToStore(fetchSettings, store).first; + : (*inputNode)->lockedRef.input.fetchToStore(fetchSettings, *store).first; sources.insert(*storePath); } if (json) { @@ -1498,8 +1498,8 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON void run(ref store) override { auto originalRef = getFlakeRef(); - auto resolvedRef = originalRef.resolve(fetchSettings, store); - auto [accessor, lockedRef] = resolvedRef.lazyFetch(getEvalState()->fetchSettings, store); + auto resolvedRef = originalRef.resolve(fetchSettings, *store); + auto [accessor, lockedRef] = resolvedRef.lazyFetch(getEvalState()->fetchSettings, *store); auto storePath = fetchToStore(getEvalState()->fetchSettings, *store, accessor, FetchMode::Copy, lockedRef.input.getName()); auto hash = store->queryPathInfo(storePath)->narHash; diff --git a/src/nix/nix-channel/nix-channel.cc b/src/nix/nix-channel/nix-channel.cc index 2029da28a..6d9a0ea58 100644 --- a/src/nix/nix-channel/nix-channel.cc +++ b/src/nix/nix-channel/nix-channel.cc @@ -121,7 +121,7 @@ static void update(const StringSet & channelNames) // We want to download the url to a file to see if it's a tarball while also checking if we // got redirected in the process, so that we can grab the various parts of a nix channel // definition from a consistent location if the redirect changes mid-download. - auto result = fetchers::downloadFile(store, fetchSettings, url, std::string(baseNameOf(url))); + auto result = fetchers::downloadFile(*store, fetchSettings, url, std::string(baseNameOf(url))); url = result.effectiveUrl; bool unpacked = false; @@ -139,10 +139,10 @@ static void update(const StringSet & channelNames) if (!unpacked) { // Download the channel tarball. try { - result = fetchers::downloadFile(store, fetchSettings, url + "/nixexprs.tar.xz", "nixexprs.tar.xz"); + result = fetchers::downloadFile(*store, fetchSettings, url + "/nixexprs.tar.xz", "nixexprs.tar.xz"); } catch (FileTransferError & e) { result = - fetchers::downloadFile(store, fetchSettings, url + "/nixexprs.tar.bz2", "nixexprs.tar.bz2"); + fetchers::downloadFile(*store, fetchSettings, url + "/nixexprs.tar.bz2", "nixexprs.tar.bz2"); } } // Regardless of where it came from, add the expression representing this channel to accumulated expression diff --git a/src/nix/registry.cc b/src/nix/registry.cc index 6bd1083df..91a73ff2f 100644 --- a/src/nix/registry.cc +++ b/src/nix/registry.cc @@ -68,7 +68,7 @@ struct CmdRegistryList : StoreCommand { using namespace fetchers; - auto registries = getRegistries(fetchSettings, store); + auto registries = getRegistries(fetchSettings, *store); for (auto & registry : registries) { for (auto & entry : registry->entries) { @@ -189,8 +189,8 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand auto registry = getRegistry(); auto ref = parseFlakeRef(fetchSettings, url); auto lockedRef = parseFlakeRef(fetchSettings, locked); - auto resolvedInput = lockedRef.resolve(fetchSettings, store).input; - auto resolved = resolvedInput.getAccessor(fetchSettings, store).second; + auto resolvedInput = lockedRef.resolve(fetchSettings, *store).input; + auto resolved = resolvedInput.getAccessor(fetchSettings, *store).second; if (!resolved.isLocked(fetchSettings)) warn("flake '%s' is not locked", resolved.to_string()); fetchers::Attrs extraAttrs;