Skip to content

Commit 2109a5a

Browse files
roberthMic92
authored andcommitted
fix: Evaluate flake parent source without evaluating its outputs
This requires that we refer to the `sourceInfo` instead of the `result`. However, `sourceInfo` does not create a chain of basedir resolution, so we add that back with `flakeDir`.
1 parent 9de9410 commit 2109a5a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/libflake/call-flake.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,20 @@ let
4242

4343
parentNode = allNodes.${getInputByPath lockFile.root node.parent};
4444

45+
flakeDir =
46+
let
47+
dir = overrides.${key}.dir or node.locked.path or "";
48+
parentDir = parentNode.flakeDir;
49+
in
50+
if node ? parent then parentDir + ("/" + dir) else dir;
51+
4552
sourceInfo =
4653
if overrides ? ${key} then
4754
overrides.${key}.sourceInfo
4855
else if node.locked.type == "path" && builtins.substring 0 1 node.locked.path != "/" then
4956
parentNode.sourceInfo
5057
// {
51-
outPath = parentNode.result.outPath + ("/" + node.locked.path);
58+
outPath = parentNode.sourceInfo.outPath + ("/" + flakeDir);
5259
}
5360
else
5461
# FIXME: remove obsolete node.info.
@@ -93,6 +100,8 @@ let
93100
result
94101
else
95102
sourceInfo;
103+
104+
inherit flakeDir sourceInfo;
96105
}
97106
) lockFile.nodes;
98107

tests/functional/flakes/relative-paths.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,24 @@ EOF
108108
[[ $(nix eval "$rootFlake#z") = 90 ]]
109109

110110
fi
111+
112+
# https://github.com/NixOS/nix/pull/10089#discussion_r2041984987
113+
# https://github.com/NixOS/nix/issues/13018
114+
mkdir -p "$TEST_ROOT/issue-13018/example"
115+
(
116+
cd "$TEST_ROOT/issue-13018"
117+
git init
118+
echo '{ outputs = _: { }; }' >flake.nix
119+
cat >example/flake.nix <<EOF
120+
{
121+
inputs.parent.url = ../.;
122+
outputs = { parent, ... }: builtins.seq parent { ok = null; };
123+
}
124+
EOF
125+
git add -N .
126+
cd example
127+
# Important: the error does not trigger for an in-memory lock!
128+
nix flake lock
129+
# would fail:
130+
nix eval .#ok
131+
)

0 commit comments

Comments
 (0)