From 674375b021ce9e229e575204395357f8d317bef5 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 14 Apr 2025 14:09:30 +0200 Subject: [PATCH 1/3] call-flake.nix: refactor: Bring mapAttrs into scope --- src/libflake/call-flake.nix | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libflake/call-flake.nix b/src/libflake/call-flake.nix index 1e9e21048..03a52c87c 100644 --- a/src/libflake/call-flake.nix +++ b/src/libflake/call-flake.nix @@ -14,6 +14,7 @@ overrides: fetchTreeFinal: let + inherit (builtins) mapAttrs; lockFile = builtins.fromJSON lockFileStr; @@ -35,7 +36,7 @@ let (resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path}) (builtins.tail path); - allNodes = builtins.mapAttrs ( + allNodes = mapAttrs ( key: node: let @@ -60,9 +61,7 @@ let flake = import (outPath + "/flake.nix"); - inputs = builtins.mapAttrs (inputName: inputSpec: allNodes.${resolveInput inputSpec}) ( - node.inputs or { } - ); + inputs = mapAttrs (inputName: inputSpec: allNodes.${resolveInput inputSpec}) (node.inputs or { }); outputs = flake.outputs (inputs // { self = result; }); From 9de9410f295a3daf5c97ea9fcbdcb0d3c5aafd5d Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 15 Apr 2025 09:10:18 +0200 Subject: [PATCH 2/3] call-flake.nix: allNodes.${key} -> allNodes.${key}.result --- src/libflake/call-flake.nix | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/libflake/call-flake.nix b/src/libflake/call-flake.nix index 03a52c87c..430dfabdd 100644 --- a/src/libflake/call-flake.nix +++ b/src/libflake/call-flake.nix @@ -48,7 +48,7 @@ let else if node.locked.type == "path" && builtins.substring 0 1 node.locked.path != "/" then parentNode.sourceInfo // { - outPath = parentNode.outPath + ("/" + node.locked.path); + outPath = parentNode.result.outPath + ("/" + node.locked.path); } else # FIXME: remove obsolete node.info. @@ -61,7 +61,9 @@ let flake = import (outPath + "/flake.nix"); - inputs = mapAttrs (inputName: inputSpec: allNodes.${resolveInput inputSpec}) (node.inputs or { }); + inputs = mapAttrs (inputName: inputSpec: allNodes.${resolveInput inputSpec}.result) ( + node.inputs or { } + ); outputs = flake.outputs (inputs // { self = result; }); @@ -84,12 +86,15 @@ let }; in - if node.flake or true then - assert builtins.isFunction flake.outputs; - result - else - sourceInfo + { + result = + if node.flake or true then + assert builtins.isFunction flake.outputs; + result + else + sourceInfo; + } ) lockFile.nodes; in -allNodes.${lockFile.root} +allNodes.${lockFile.root}.result From 2109a5a2066d0d49a1bcc5b44b2a4d84b5d313bd Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 15 Apr 2025 09:28:23 +0200 Subject: [PATCH 3/3] 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`. --- src/libflake/call-flake.nix | 11 ++++++++++- tests/functional/flakes/relative-paths.sh | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/libflake/call-flake.nix b/src/libflake/call-flake.nix index 430dfabdd..fe326291f 100644 --- a/src/libflake/call-flake.nix +++ b/src/libflake/call-flake.nix @@ -42,13 +42,20 @@ let parentNode = allNodes.${getInputByPath lockFile.root node.parent}; + flakeDir = + let + dir = overrides.${key}.dir or node.locked.path or ""; + parentDir = parentNode.flakeDir; + in + if node ? parent then parentDir + ("/" + dir) else dir; + sourceInfo = if overrides ? ${key} then overrides.${key}.sourceInfo else if node.locked.type == "path" && builtins.substring 0 1 node.locked.path != "/" then parentNode.sourceInfo // { - outPath = parentNode.result.outPath + ("/" + node.locked.path); + outPath = parentNode.sourceInfo.outPath + ("/" + flakeDir); } else # FIXME: remove obsolete node.info. @@ -93,6 +100,8 @@ let result else sourceInfo; + + inherit flakeDir sourceInfo; } ) lockFile.nodes; diff --git a/tests/functional/flakes/relative-paths.sh b/tests/functional/flakes/relative-paths.sh index 3f7ca3f46..4648ba98c 100644 --- a/tests/functional/flakes/relative-paths.sh +++ b/tests/functional/flakes/relative-paths.sh @@ -108,3 +108,24 @@ EOF [[ $(nix eval "$rootFlake#z") = 90 ]] fi + +# https://github.com/NixOS/nix/pull/10089#discussion_r2041984987 +# https://github.com/NixOS/nix/issues/13018 +mkdir -p "$TEST_ROOT/issue-13018/example" +( + cd "$TEST_ROOT/issue-13018" + git init + echo '{ outputs = _: { }; }' >flake.nix + cat >example/flake.nix <