mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
Fix relative 'path:' flakerefs in the CLI
And handle relative 'git+file:' flakerefs while we're at it (these crashed with an assertion failure). Fixes #12248.
This commit is contained in:
parent
8aafc05885
commit
ff8e2fe84e
2 changed files with 11 additions and 3 deletions
|
@ -102,8 +102,8 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
|
||||||
|
|
||||||
if (baseDir) {
|
if (baseDir) {
|
||||||
/* Check if 'url' is a path (either absolute or relative
|
/* Check if 'url' is a path (either absolute or relative
|
||||||
to 'baseDir'). If so, search upward to the root of the
|
to 'baseDir'). If so, search upward to the root of the
|
||||||
repo (i.e. the directory containing .git). */
|
repo (i.e. the directory containing .git). */
|
||||||
|
|
||||||
path = absPath(path, baseDir);
|
path = absPath(path, baseDir);
|
||||||
|
|
||||||
|
@ -232,7 +232,12 @@ std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return fromParsedURL(fetchSettings, parseURL(url), isFlake);
|
auto parsed = parseURL(url);
|
||||||
|
if (baseDir
|
||||||
|
&& (parsed.scheme == "path" || parsed.scheme == "git+file")
|
||||||
|
&& !hasPrefix(parsed.path, "/"))
|
||||||
|
parsed.path = absPath(parsed.path, *baseDir);
|
||||||
|
return fromParsedURL(fetchSettings, std::move(parsed), isFlake);
|
||||||
} catch (BadURL &) {
|
} catch (BadURL &) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,9 @@ nix build -o "$TEST_ROOT/result" flake1
|
||||||
|
|
||||||
nix build -o "$TEST_ROOT/result" "$flake1Dir"
|
nix build -o "$TEST_ROOT/result" "$flake1Dir"
|
||||||
nix build -o "$TEST_ROOT/result" "git+file://$flake1Dir"
|
nix build -o "$TEST_ROOT/result" "git+file://$flake1Dir"
|
||||||
|
(cd "$flake1Dir" && nix build -o "$TEST_ROOT/result" ".")
|
||||||
|
(cd "$flake1Dir" && nix build -o "$TEST_ROOT/result" "path:.")
|
||||||
|
(cd "$flake1Dir" && nix build -o "$TEST_ROOT/result" "git+file:.")
|
||||||
|
|
||||||
# Test explicit packages.default.
|
# Test explicit packages.default.
|
||||||
nix build -o "$TEST_ROOT/result" "$flake1Dir#default"
|
nix build -o "$TEST_ROOT/result" "$flake1Dir#default"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue