From 46beb9af76284d131b43f2657296303390f9a585 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Mon, 12 May 2025 12:16:40 +0100 Subject: [PATCH] Use correct parent `outPath` for relative path inputs Ensure relative path inputs are relative to the parent node's _actual_ `outPath`, instead of the subtly different `sourceInfo.outPath`. Additionally, non-flake inputs now also have a `sourceInfo` attribute. This fixes the relationship between `self.outPath` and `self.sourceInfo.outPath` in some edge cases. Fixes #13164 --- src/libflake/call-flake.nix | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/libflake/call-flake.nix b/src/libflake/call-flake.nix index fe326291f..ed7947e06 100644 --- a/src/libflake/call-flake.nix +++ b/src/libflake/call-flake.nix @@ -39,24 +39,16 @@ let allNodes = mapAttrs ( key: node: let + hasOverride = overrides ? ${key}; + isRelative = node.locked.type or null == "path" && builtins.substring 0 1 node.locked.path != "/"; 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 + if hasOverride then overrides.${key}.sourceInfo - else if node.locked.type == "path" && builtins.substring 0 1 node.locked.path != "/" then + else if isRelative then parentNode.sourceInfo - // { - outPath = parentNode.sourceInfo.outPath + ("/" + flakeDir); - } else # FIXME: remove obsolete node.info. # Note: lock file entries are always final. @@ -64,7 +56,11 @@ let subdir = overrides.${key}.dir or node.locked.dir or ""; - outPath = sourceInfo + ((if subdir == "" then "" else "/") + subdir); + outPath = + if !hasOverride && isRelative then + parentNode.outPath + (if node.locked.path == "" then "" else "/" + node.locked.path) + else + sourceInfo.outPath + (if subdir == "" then "" else "/" + subdir); flake = import (outPath + "/flake.nix"); @@ -99,9 +95,9 @@ let assert builtins.isFunction flake.outputs; result else - sourceInfo; + sourceInfo // { inherit sourceInfo outPath; }; - inherit flakeDir sourceInfo; + inherit outPath sourceInfo; } ) lockFile.nodes;