mirror of
https://github.com/NixOS/nix.git
synced 2025-12-06 00:51:00 +01:00
lockFlake(): Allow registry lookups for the top-level flake
Fixes #13050.
This commit is contained in:
parent
dda265f09a
commit
68de26d38a
11 changed files with 53 additions and 26 deletions
|
|
@ -14,6 +14,8 @@ std::shared_ptr<Registry> Registry::read(
|
|||
const Settings & settings,
|
||||
const Path & path, RegistryType type)
|
||||
{
|
||||
debug("reading registry '%s'", path);
|
||||
|
||||
auto registry = std::make_shared<Registry>(settings, type);
|
||||
|
||||
if (!pathExists(path))
|
||||
|
|
@ -179,29 +181,36 @@ Registries getRegistries(const Settings & settings, ref<Store> store)
|
|||
std::pair<Input, Attrs> lookupInRegistries(
|
||||
ref<Store> store,
|
||||
const Input & _input,
|
||||
const RegistryFilter & filter)
|
||||
UseRegistries useRegistries)
|
||||
{
|
||||
Attrs extraAttrs;
|
||||
int n = 0;
|
||||
Input input(_input);
|
||||
|
||||
if (useRegistries == UseRegistries::No)
|
||||
return {input, extraAttrs};
|
||||
|
||||
restart:
|
||||
|
||||
n++;
|
||||
if (n > 100) throw Error("cycle detected in flake registry for '%s'", input.to_string());
|
||||
|
||||
for (auto & registry : getRegistries(*input.settings, store)) {
|
||||
if (filter && !filter(registry->type)) continue;
|
||||
if (useRegistries == UseRegistries::Limited
|
||||
&& !(registry->type == fetchers::Registry::Flag || registry->type == fetchers::Registry::Global))
|
||||
continue;
|
||||
// FIXME: O(n)
|
||||
for (auto & entry : registry->entries) {
|
||||
if (entry.exact) {
|
||||
if (entry.from == input) {
|
||||
debug("resolved flakeref '%s' against registry %d exactly", input.to_string(), registry->type);
|
||||
input = entry.to;
|
||||
extraAttrs = entry.extraAttrs;
|
||||
goto restart;
|
||||
}
|
||||
} else {
|
||||
if (entry.from.contains(input)) {
|
||||
debug("resolved flakeref '%s' against registry %d", input.to_string(), registry->type);
|
||||
input = entry.to.applyOverrides(
|
||||
!entry.from.getRef() && input.getRef() ? input.getRef() : std::optional<std::string>(),
|
||||
!entry.from.getRev() && input.getRev() ? input.getRev() : std::optional<Hash>());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue