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 @@ -426,7 +426,16 @@ struct GitInputScheme : InputScheme
426426 auto url = parseURL (getStrAttr (input.attrs , " url" ));
427427 bool isBareRepository = url.scheme == " file" && !pathExists (url.path + " /.git" );
428428 repoInfo.isLocal = url.scheme == " file" && !forceHttp && !isBareRepository;
429- repoInfo.url = repoInfo.isLocal ? url.path : url.to_string ();
429+ //
430+ // FIXME: here we turn a possibly relative path into an absolute path.
431+ // This allows relative git flake inputs to be resolved against the
432+ // **current working directory** (as in POSIX), which tends to work out
433+ // ok in the context of flakes, but is the wrong behavior,
434+ // as it should resolve against the flake.nix base directory instead.
435+ //
436+ // See: https://discourse.nixos.org/t/57783 and #9708
437+ //
438+ repoInfo.url = repoInfo.isLocal ? std::filesystem::absolute (url.path ).string () : url.to_string ();
430439
431440 // If this is a local directory and no ref or revision is
432441 // 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"
7676
7777storePath=$( nix flake metadata --json " $rootRepo ?submodules=1" | jq -r .path)
7878[[ -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 @@ -106,6 +106,15 @@ nix build -o "$TEST_ROOT/result" "git+file://$flake1Dir#default"
106106nix build -o " $TEST_ROOT /result" " $flake1Dir ?ref=HEAD#default"
107107nix build -o " $TEST_ROOT /result" " git+file://$flake1Dir ?ref=HEAD#default"
108108
109+ # Check that relative paths are allowed for git flakes.
110+ # This may change in the future once git submodule support is refined.
111+ # See: https://discourse.nixos.org/t/57783 and #9708.
112+ (
113+ # This `cd` should not be required and is indicative of aforementioned bug.
114+ cd " $flake1Dir /.."
115+ nix build -o " $TEST_ROOT /result" " git+file:./$( basename " $flake1Dir " ) "
116+ )
117+
109118# Check that store symlinks inside a flake are not interpreted as flakes.
110119nix build -o " $flake1Dir /result" " git+file://$flake1Dir "
111120nix path-info " $flake1Dir /result"
You can’t perform that action at this time.
0 commit comments