From 46beb9af76284d131b43f2657296303390f9a585 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Mon, 12 May 2025 12:16:40 +0100 Subject: [PATCH 1/4] 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; From eaee0b4740dcc82e3fec8482d5f803a45741594d Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 14 May 2025 22:48:56 +0200 Subject: [PATCH 2/4] tests/function/flakes/relative-paths: Test #13164 --- tests/functional/flakes/relative-paths.sh | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/functional/flakes/relative-paths.sh b/tests/functional/flakes/relative-paths.sh index 4648ba98c..560cc6aaa 100644 --- a/tests/functional/flakes/relative-paths.sh +++ b/tests/functional/flakes/relative-paths.sh @@ -129,3 +129,46 @@ EOF # would fail: nix eval .#ok ) + +# https://github.com/NixOS/nix/issues/13164 +mkdir -p "$TEST_ROOT/issue-13164/nested-flake1/nested-flake2" +( + cd "$TEST_ROOT/issue-13164" + git init + git config --global user.email "you@example.com" + git config --global user.name "Your Name" + cat >flake.nix <nested-flake1/flake.nix <nested-flake1/nested-flake2/flake.nix < Date: Sun, 18 May 2025 00:18:46 +0100 Subject: [PATCH 3/4] tests/functional/flakes/non-flake-inputs: Test non-flake inputs having `sourceInfo` --- tests/functional/flakes/non-flake-inputs.sh | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/functional/flakes/non-flake-inputs.sh b/tests/functional/flakes/non-flake-inputs.sh index f5e12cd01..05e656042 100644 --- a/tests/functional/flakes/non-flake-inputs.sh +++ b/tests/functional/flakes/non-flake-inputs.sh @@ -37,11 +37,20 @@ cat > "$flake3Dir/flake.nix" < Date: Sun, 18 May 2025 00:37:23 +0100 Subject: [PATCH 4/4] Add release note for non-flake inputs having `sourceInfo` --- .../rl-next/outpath-and-sourceinfo-fixes.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 doc/manual/rl-next/outpath-and-sourceinfo-fixes.md diff --git a/doc/manual/rl-next/outpath-and-sourceinfo-fixes.md b/doc/manual/rl-next/outpath-and-sourceinfo-fixes.md new file mode 100644 index 000000000..479a2f5cb --- /dev/null +++ b/doc/manual/rl-next/outpath-and-sourceinfo-fixes.md @@ -0,0 +1,17 @@ +--- +synopsis: Non-flake inputs now contain a `sourceInfo` attribute +issues: 13164 +prs: 13170 +--- + +Flakes have always a `sourceInfo` attribute which describes the source of the flake. +The `sourceInfo.outPath` is often identical to the flake's `outPath`, however it can differ when the flake is located in a subdirectory of its source. + +Non-flake inputs (i.e. inputs with `flake = false`) can also be located at some path _within_ a wider source. +This usually happens when defining a relative path input within the same source as the parent flake, e.g. `inputs.foo.url = ./some-file.nix`. +Such relative inputs will now inherit their parent's `sourceInfo`. + +This also means it is now possible to use `?dir=subdir` on non-flake inputs. + +This iterates on the work done in 2.26 to improve relative path support ([#10089](https://github.com/NixOS/nix/pull/10089)), +and resolves a regression introduced in 2.28 relating to nested relative path inputs ([#13164](https://github.com/NixOS/nix/issues/13164)).