Skip to content

Commit ff8e2fe

Browse files
committed
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.
1 parent 8aafc05 commit ff8e2fe

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/libflake/flake/flakeref.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
102102

103103
if (baseDir) {
104104
/* Check if 'url' is a path (either absolute or relative
105-
to 'baseDir'). If so, search upward to the root of the
106-
repo (i.e. the directory containing .git). */
105+
to 'baseDir'). If so, search upward to the root of the
106+
repo (i.e. the directory containing .git). */
107107

108108
path = absPath(path, baseDir);
109109

@@ -232,7 +232,12 @@ std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
232232
)
233233
{
234234
try {
235-
return fromParsedURL(fetchSettings, parseURL(url), isFlake);
235+
auto parsed = parseURL(url);
236+
if (baseDir
237+
&& (parsed.scheme == "path" || parsed.scheme == "git+file")
238+
&& !hasPrefix(parsed.path, "/"))
239+
parsed.path = absPath(parsed.path, *baseDir);
240+
return fromParsedURL(fetchSettings, std::move(parsed), isFlake);
236241
} catch (BadURL &) {
237242
return std::nullopt;
238243
}

tests/functional/flakes/flakes.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ nix build -o "$TEST_ROOT/result" flake1
9797

9898
nix build -o "$TEST_ROOT/result" "$flake1Dir"
9999
nix build -o "$TEST_ROOT/result" "git+file://$flake1Dir"
100+
(cd "$flake1Dir" && nix build -o "$TEST_ROOT/result" ".")
101+
(cd "$flake1Dir" && nix build -o "$TEST_ROOT/result" "path:.")
102+
(cd "$flake1Dir" && nix build -o "$TEST_ROOT/result" "git+file:.")
100103

101104
# Test explicit packages.default.
102105
nix build -o "$TEST_ROOT/result" "$flake1Dir#default"

0 commit comments

Comments
 (0)