1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-04 03:01:47 +02:00

Merge pull request #12254 from DeterminateSystems/fix-relative-path-on-cli

Fix relative 'path:' flakerefs in the CLI
This commit is contained in:
John Ericson 2025-01-15 15:19:56 -05:00 committed by GitHub
commit e02026adae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 22 additions and 14 deletions

View file

@ -102,8 +102,8 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
if (baseDir) {
/* Check if 'url' is a path (either absolute or relative
to 'baseDir'). If so, search upward to the root of the
repo (i.e. the directory containing .git). */
to 'baseDir'). If so, search upward to the root of the
repo (i.e. the directory containing .git). */
path = absPath(path, baseDir);
@ -178,7 +178,7 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
}
} else {
if (!hasPrefix(path, "/"))
if (!isAbsolute(path))
throw BadURL("flake reference '%s' is not an absolute path", url);
path = canonPath(path + "/" + getOr(query, "dir", ""));
}
@ -232,7 +232,12 @@ std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
)
{
try {
return fromParsedURL(fetchSettings, parseURL(url), isFlake);
auto parsed = parseURL(url);
if (baseDir
&& (parsed.scheme == "path" || parsed.scheme == "git+file")
&& !isAbsolute(parsed.path))
parsed.path = absPath(parsed.path, *baseDir);
return fromParsedURL(fetchSettings, std::move(parsed), isFlake);
} catch (BadURL &) {
return std::nullopt;
}