diff --git a/src/libflake/flake-primops.cc b/src/libflake/flake-primops.cc index 33c7b7d8789a..f5f4c9aefebf 100644 --- a/src/libflake/flake-primops.cc +++ b/src/libflake/flake-primops.cc @@ -30,6 +30,7 @@ #include "nix/util/source-path.hh" #include "nix/util/types.hh" #include "nix/util/util.hh" +#include "nix/util/mounted-source-accessor.hh" namespace nix::flake::primops { @@ -74,14 +75,11 @@ PrimOp getFlake(const Settings & settings) if (auto sourcePath = flakeRef.input.getSourcePath(); sourcePath && state.store->isInStore(sourcePath->string())) { auto [storePath, subPath] = state.store->toStorePath(sourcePath->string()); - for (auto & c : context) { - if (auto p = std::get_if(&c.raw); p && p->storePath == storePath) { - auto path = state.storePath(storePath) / CanonPath(subPath); - if (!flakeRef.subdir.empty()) - path = path / flakeRef.subdir; - callFlake(state, lockFlake(settings, state, path, lockFlags), v); - return; - } + if (auto mount = state.storeFS->getMount(CanonPath(state.store->printStorePath(storePath)))) { + auto path = state.storePath(storePath) / CanonPath(subPath); + if (!flakeRef.subdir.empty()) + path = path / flakeRef.subdir; + return callFlake(state, lockFlake(settings, state, path, lockFlags), v); } } } diff --git a/tests/functional/flakes/get-flake.sh b/tests/functional/flakes/get-flake.sh index 1e130317ec14..704f770e9a9c 100644 --- a/tests/functional/flakes/get-flake.sh +++ b/tests/functional/flakes/get-flake.sh @@ -25,3 +25,22 @@ expectStderr 0 nix eval "$flake1Dir/subflake#x" | grepQuiet "This may become a f [[ $(nix eval "$flake1Dir/subflake#x") = 123 ]] [[ $(nix eval "$flake1Dir/subflake#y") = 123 ]] + +# Check backward compatibility with getFlake applied to a store path with discarded string context. +cat > "$flake1Dir/flake.nix" <