Skip to content

Commit 99a16c5

Browse files
authored
Merge pull request #13026 from roberth/issue-13018
Fix issue #13018, `sourceInfo` strict in `outputs`
2 parents 22c928f + 2109a5a commit 99a16c5

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

src/libflake/call-flake.nix

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ overrides:
1414
fetchTreeFinal:
1515

1616
let
17+
inherit (builtins) mapAttrs;
1718

1819
lockFile = builtins.fromJSON lockFileStr;
1920

@@ -35,19 +36,26 @@ let
3536
(resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path})
3637
(builtins.tail path);
3738

38-
allNodes = builtins.mapAttrs (
39+
allNodes = mapAttrs (
3940
key: node:
4041
let
4142

4243
parentNode = allNodes.${getInputByPath lockFile.root node.parent};
4344

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+
4452
sourceInfo =
4553
if overrides ? ${key} then
4654
overrides.${key}.sourceInfo
4755
else if node.locked.type == "path" && builtins.substring 0 1 node.locked.path != "/" then
4856
parentNode.sourceInfo
4957
// {
50-
outPath = parentNode.outPath + ("/" + node.locked.path);
58+
outPath = parentNode.sourceInfo.outPath + ("/" + flakeDir);
5159
}
5260
else
5361
# FIXME: remove obsolete node.info.
@@ -60,7 +68,7 @@ let
6068

6169
flake = import (outPath + "/flake.nix");
6270

63-
inputs = builtins.mapAttrs (inputName: inputSpec: allNodes.${resolveInput inputSpec}) (
71+
inputs = mapAttrs (inputName: inputSpec: allNodes.${resolveInput inputSpec}.result) (
6472
node.inputs or { }
6573
);
6674

@@ -85,12 +93,17 @@ let
8593
};
8694

8795
in
88-
if node.flake or true then
89-
assert builtins.isFunction flake.outputs;
90-
result
91-
else
92-
sourceInfo
96+
{
97+
result =
98+
if node.flake or true then
99+
assert builtins.isFunction flake.outputs;
100+
result
101+
else
102+
sourceInfo;
103+
104+
inherit flakeDir sourceInfo;
105+
}
93106
) lockFile.nodes;
94107

95108
in
96-
allNodes.${lockFile.root}
109+
allNodes.${lockFile.root}.result

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)