Skip to content

Improved backwards compatibility hack for git URLs using dir=...#14205

Merged
edolstra merged 2 commits intoNixOS:masterfrom
GrahamDennis:gdennis/improve-dir-url-backcompat
Oct 15, 2025
Merged

Improved backwards compatibility hack for git URLs using dir=...#14205
edolstra merged 2 commits intoNixOS:masterfrom
GrahamDennis:gdennis/improve-dir-url-backcompat

Conversation

@GrahamDennis
Copy link
Contributor

Motivation

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.

Some mitigations for this issue were added before:

  • 9f72d5b cleared all query attributes from file-scheme git URLs, but didn't touch other schemes (e.g. https or ssh). This PR removes the dir query parameter from all git URLs.
  • d00682b ensured that newer nix versions wouldn't consider flake.lock files out-of-date that had these unnecessary dir=... attributes

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions bot added the fetching Networking with the outside (non-Nix) world, input locking label Oct 10, 2025
@xokdvium
Copy link
Contributor

@GrahamDennis sounds good in principle. Could you add a test though? A unit test in libflake-tests would be good I think.

@GrahamDennis
Copy link
Contributor Author

@GrahamDennis sounds good in principle. Could you add a test though? A unit test in libflake-tests would be good I think.

This don't impact the Input you get by using inputFromAttrs or inputFromURL, it only impacts RepoInfo which is internal to git.cc and isn't (currently) exposed via git.hh to enable a test to be written in libfetchers-tests either.

The only way I can think to test this would be to write a functional test, but that would require using an ssh or http/s server for git and I believe all tests need to execute in a nix sandbox.

Happy to write a test, I'm just not sure how to do that in this case without refactoring to expose RepoInfo in git.hh.

@xokdvium
Copy link
Contributor

I see. In that case this could probably go to fetch-git nixos test. There we have an actual forge (gitea) that should be enough for a test.

@edolstra edolstra added the backport 2.32-maintenance Automatically creates a PR against the branch label Oct 15, 2025
@edolstra
Copy link
Member

Will merge this since it's simple enough, though a test would still be great.

@edolstra edolstra added this pull request to the merge queue Oct 15, 2025
Merged via the queue into NixOS:master with commit 5700112 Oct 15, 2025
19 checks passed
@internal-nix-ci
Copy link

Successfully created backport PR for 2.32-maintenance:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.32-maintenance Automatically creates a PR against the branch fetching Networking with the outside (non-Nix) world, input locking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants