From ba46c7d0f268622e29f94b99a8171e9a5be8b8b8 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Sun, 7 Sep 2025 15:27:14 +0200 Subject: [PATCH] Fix flake registry ignoring `dir` parameter This broke in e3042f10afb5f4e64ef9a5e08bef52b168cb4bf1. (cherry picked from commit bccdb95a8661829322676d74a7344404467838fa) --- src/libfetchers/include/nix/fetchers/input-cache.hh | 1 + src/libfetchers/input-cache.cc | 6 ++++-- src/libflake/flake.cc | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libfetchers/include/nix/fetchers/input-cache.hh b/src/libfetchers/include/nix/fetchers/input-cache.hh index b2fc84245..ee2fa20c4 100644 --- a/src/libfetchers/include/nix/fetchers/input-cache.hh +++ b/src/libfetchers/include/nix/fetchers/input-cache.hh @@ -11,6 +11,7 @@ struct InputCache ref accessor; Input resolvedInput; Input lockedInput; + Attrs extraAttrs; }; CachedResult getAccessor(ref store, const Input & originalInput, UseRegistries useRegistries); diff --git a/src/libfetchers/input-cache.cc b/src/libfetchers/input-cache.cc index 1422c1d9a..c415b5417 100644 --- a/src/libfetchers/input-cache.cc +++ b/src/libfetchers/input-cache.cc @@ -8,6 +8,7 @@ namespace nix::fetchers { InputCache::CachedResult InputCache::getAccessor(ref store, const Input & originalInput, UseRegistries useRegistries) { + Attrs extraAttrs; auto fetched = lookup(originalInput); Input resolvedInput = originalInput; @@ -17,7 +18,8 @@ InputCache::getAccessor(ref store, const Input & originalInput, UseRegist fetched.emplace(CachedInput{.lockedInput = lockedInput, .accessor = accessor}); } else { if (useRegistries != UseRegistries::No) { - auto [res, extraAttrs] = lookupInRegistries(store, originalInput, useRegistries); + auto [res, extraAttrs_] = lookupInRegistries(store, originalInput, useRegistries); + extraAttrs = extraAttrs_; resolvedInput = std::move(res); fetched = lookup(resolvedInput); if (!fetched) { @@ -36,7 +38,7 @@ InputCache::getAccessor(ref store, const Input & originalInput, UseRegist debug("got tree '%s' from '%s'", fetched->accessor, fetched->lockedInput.to_string()); - return {fetched->accessor, resolvedInput, fetched->lockedInput}; + return {fetched->accessor, resolvedInput, fetched->lockedInput, extraAttrs}; } struct InputCacheImpl : InputCache diff --git a/src/libflake/flake.cc b/src/libflake/flake.cc index b31bef211..572df6cc3 100644 --- a/src/libflake/flake.cc +++ b/src/libflake/flake.cc @@ -340,8 +340,9 @@ static Flake getFlake( // Fetch a lazy tree first. auto cachedInput = state.inputCache->getAccessor(state.store, originalRef.input, useRegistries); - auto resolvedRef = FlakeRef(std::move(cachedInput.resolvedInput), originalRef.subdir); - auto lockedRef = FlakeRef(std::move(cachedInput.lockedInput), originalRef.subdir); + auto subdir = fetchers::maybeGetStrAttr(cachedInput.extraAttrs, "dir").value_or(originalRef.subdir); + auto resolvedRef = FlakeRef(std::move(cachedInput.resolvedInput), subdir); + auto lockedRef = FlakeRef(std::move(cachedInput.lockedInput), subdir); // Parse/eval flake.nix to get at the input.self attributes. auto flake = readFlake(state, originalRef, resolvedRef, lockedRef, {cachedInput.accessor}, lockRootAttrPath);