Describe the bug
In a flake folder, running nix flake metadata path: (or any command that takes a flake-url) fails with the following error :
error:
… while fetching the input 'path:'
error: cannot fetch input 'path:' because it uses a relative path
Steps To Reproduce
- Create a flake in an empty folder (
nix flake init)
- Run
nix flake metadata path:
- Observe the error.
Expected behavior
This used to work with version 2.24.11
Metadata
Works with: nix-env (Nix) 2.24.11
Doesn't work with: nix-env (Nix) 2.25.4 nor nix-env (Nix) 2.26.0
Additional context
Bisected the error to 8502819
I've been able to solve the issue with the following patch, but I don't know the codebase enough to do a proper fix
Quick hack to fix the issue
diff --git a/src/libflake/flake/flakeref.cc b/src/libflake/flake/flakeref.cc
index cdf0a40e8..9482749e8 100644
--- a/src/libflake/flake/flakeref.cc
+++ b/src/libflake/flake/flakeref.cc
@@ -71,7 +71,8 @@ std::optional<FlakeRef> maybeParseFlakeRef(
static std::pair<FlakeRef, std::string> fromParsedURL(
const fetchers::Settings & fetchSettings,
ParsedURL && parsedURL,
- bool isFlake)
+ bool isFlake,
+ const std::optional<Path> & baseDir = std::nullopt)
{
auto dir = getOr(parsedURL.query, "dir", "");
parsedURL.query.erase("dir");
@@ -79,7 +80,10 @@ static std::pair<FlakeRef, std::string> fromParsedURL(
std::string fragment;
std::swap(fragment, parsedURL.fragment);
- return {FlakeRef(fetchers::Input::fromURL(fetchSettings, parsedURL, isFlake), dir), fragment};
+ auto input = fetchers::Input::fromURL(fetchSettings, parsedURL, isFlake);
+ input.parent = baseDir;
+
+ return {FlakeRef(std::move(input), dir), fragment};
}
std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
@@ -232,7 +236,7 @@ std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
)
{
try {
- return fromParsedURL(fetchSettings, parseURL(url), isFlake);
+ return fromParsedURL(fetchSettings, parseURL(url), isFlake, baseDir);
} catch (BadURL &) {
return std::nullopt;
}
Checklist
Add 👍 to issues you find important.
Describe the bug
In a flake folder, running
nix flake metadata path:(or any command that takes a flake-url) fails with the following error :error: … while fetching the input 'path:' error: cannot fetch input 'path:' because it uses a relative pathSteps To Reproduce
nix flake init)nix flake metadata path:Expected behavior
This used to work with version 2.24.11
Metadata
Works with:
nix-env (Nix) 2.24.11Doesn't work with:
nix-env (Nix) 2.25.4nornix-env (Nix) 2.26.0Additional context
Bisected the error to 8502819
I've been able to solve the issue with the following patch, but I don't know the codebase enough to do a proper fix
Quick hack to fix the issue
Checklist
Add 👍 to issues you find important.