diff --git a/src/libfetchers/include/nix/fetchers/input-cache.hh b/src/libfetchers/include/nix/fetchers/input-cache.hh index b2fc84245..402412071 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); @@ -19,6 +20,7 @@ struct InputCache { Input lockedInput; ref accessor; + Attrs extraAttrs; }; virtual std::optional lookup(const Input & originalInput) const = 0; diff --git a/src/libfetchers/input-cache.cc b/src/libfetchers/input-cache.cc index 1422c1d9a..c44f1a236 100644 --- a/src/libfetchers/input-cache.cc +++ b/src/libfetchers/input-cache.cc @@ -22,7 +22,8 @@ InputCache::getAccessor(ref store, const Input & originalInput, UseRegist fetched = lookup(resolvedInput); if (!fetched) { auto [accessor, lockedInput] = resolvedInput.getAccessor(store); - fetched.emplace(CachedInput{.lockedInput = lockedInput, .accessor = accessor}); + fetched.emplace( + CachedInput{.lockedInput = lockedInput, .accessor = accessor, .extraAttrs = extraAttrs}); } upsert(resolvedInput, *fetched); } else { @@ -36,7 +37,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, fetched->extraAttrs}; } struct InputCacheImpl : InputCache diff --git a/src/libflake/flake.cc b/src/libflake/flake.cc index 56e455cb6..3acf589a5 100644 --- a/src/libflake/flake.cc +++ b/src/libflake/flake.cc @@ -341,8 +341,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); diff --git a/tests/functional/flakes/flakes.sh b/tests/functional/flakes/flakes.sh index 7fd9dc9b5..8fb7ce8e2 100755 --- a/tests/functional/flakes/flakes.sh +++ b/tests/functional/flakes/flakes.sh @@ -470,3 +470,20 @@ cat > "$flake3Dir/flake.nix" < "$subdirFlakeDir"/flake.nix <