From 43b01b6790af2070e6162472bbfa5bbe3bb3ff61 Mon Sep 17 00:00:00 2001 From: Graham Dennis Date: Fri, 10 Oct 2025 14:54:03 +1100 Subject: [PATCH 1/2] Improved backwards compatibility hack for git URLs using dir=... attribute --- src/libfetchers/git.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 7c1630167..a8a52ef30 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -496,6 +496,36 @@ struct GitInputScheme : InputScheme Git interprets them as part of the file name. So get rid of them. */ url.query.clear(); + /* Backward compatibility hack: In old versions of Nix, if you had + a flake input like + + inputs.foo.url = "git+https://foo/bar?dir=subdir"; + + it would result in a lock file entry like + + "original": { + "dir": "subdir", + "type": "git", + "url": "https://foo/bar?dir=subdir" + } + + New versions of Nix remove `?dir=subdir` from the `url` field, + since the subdirectory is intended for `FlakeRef`, not the + fetcher (and specifically the remote server), that is, the + flakeref is parsed into + + "original": { + "dir": "subdir", + "type": "git", + "url": "https://foo/bar" + } + + However, new versions of nix parsing old flake.lock files would pass the dir= + query parameter in the "url" attribute to git, which will then complain. + + For this reason, we filtering the `dir` query parameter from the URL + before passing it to git. */ + url.query.erase("dir"); repoInfo.location = url; } From 8d9e9bc400433faeb9a6edc49327f7700b93b1c2 Mon Sep 17 00:00:00 2001 From: Graham Dennis Date: Fri, 10 Oct 2025 15:00:10 +1100 Subject: [PATCH 2/2] Improve comment --- src/libfetchers/git.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index a8a52ef30..9334dc1cb 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -523,7 +523,7 @@ struct GitInputScheme : InputScheme However, new versions of nix parsing old flake.lock files would pass the dir= query parameter in the "url" attribute to git, which will then complain. - For this reason, we filtering the `dir` query parameter from the URL + For this reason, we are filtering the `dir` query parameter from the URL before passing it to git. */ url.query.erase("dir"); repoInfo.location = url;