File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -425,7 +425,16 @@ struct GitInputScheme : InputScheme
425
425
auto url = parseURL (getStrAttr (input.attrs , " url" ));
426
426
bool isBareRepository = url.scheme == " file" && !pathExists (url.path + " /.git" );
427
427
repoInfo.isLocal = url.scheme == " file" && !forceHttp && !isBareRepository;
428
- repoInfo.url = repoInfo.isLocal ? url.path : url.to_string ();
428
+ //
429
+ // FIXME: here we turn a possibly relative path into an absolute path.
430
+ // This allows relative git flake inputs to be resolved against the
431
+ // **current working directory** (as in POSIX), which tends to work out
432
+ // ok in the context of flakes, but is the wrong behavior,
433
+ // as it should resolve against the flake.nix base directory instead.
434
+ //
435
+ // See: https://discourse.nixos.org/t/57783 and #9708
436
+ //
437
+ repoInfo.url = repoInfo.isLocal ? std::filesystem::absolute (url.path ).string () : url.to_string ();
429
438
430
439
// If this is a local directory and no ref or revision is
431
440
// given, then allow the use of an unclean working tree.
Original file line number Diff line number Diff line change @@ -76,3 +76,21 @@ git -C "$rootRepo" commit -m "Add flake.nix"
76
76
77
77
storePath=$( nix flake metadata --json " $rootRepo ?submodules=1" | jq -r .path)
78
78
[[ -e " $storePath /submodule" ]]
79
+
80
+ # The root repo may use the submodule repo as an input
81
+ # through the relative path. This may change in the future;
82
+ # see: https://discourse.nixos.org/t/57783 and #9708.
83
+ cat > " $rootRepo " /flake.nix << EOF
84
+ {
85
+ inputs.subRepo.url = "git+file:./submodule";
86
+ outputs = { ... }: { };
87
+ }
88
+ EOF
89
+ git -C " $rootRepo " add flake.nix
90
+ git -C " $rootRepo " commit -m " Add subRepo input"
91
+ (
92
+ cd " $rootRepo "
93
+ # The submodule must be locked to the relative path,
94
+ # _not_ the absolute path:
95
+ [[ $( nix flake metadata --json | jq -r .locks.nodes.subRepo.locked.url) = " file:./submodule" ]]
96
+ )
Original file line number Diff line number Diff line change @@ -231,6 +231,15 @@ nix build -o "$TEST_ROOT/result" "git+file://$flake1Dir#default"
231
231
nix build -o " $TEST_ROOT /result" " $flake1Dir ?ref=HEAD#default"
232
232
nix build -o " $TEST_ROOT /result" " git+file://$flake1Dir ?ref=HEAD#default"
233
233
234
+ # Check that relative paths are allowed for git flakes.
235
+ # This may change in the future once git submodule support is refined.
236
+ # See: https://discourse.nixos.org/t/57783 and #9708.
237
+ (
238
+ # This `cd` should not be required and is indicative of aforementioned bug.
239
+ cd " $flake1Dir /.."
240
+ nix build -o " $TEST_ROOT /result" " git+file:./$( basename " $flake1Dir " ) "
241
+ )
242
+
234
243
# Check that store symlinks inside a flake are not interpreted as flakes.
235
244
nix build -o " $flake1Dir /result" " git+file://$flake1Dir "
236
245
nix path-info " $flake1Dir /result"
You can’t perform that action at this time.
0 commit comments