Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/libflake/flake-primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<NixStringContextElem::Path>(&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);
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/flakes/get-flake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" <<EOF
{
outputs =
{ self }:
let
flakeOutputs = builtins.getFlake (
builtins.unsafeDiscardStringContext "path:\${self.sourceInfo}?narHash=\${self.narHash}"
);
in
{
foo = "bar";
inherit flakeOutputs;
};
}
EOF

[[ $(nix eval --raw "$flake1Dir#flakeOutputs.foo") = bar ]]
Loading