-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Ensure that git filters are applied when reading blobs #13428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
What decides whether CR/LF conversion gets done? For reproducibility, it should not depend on the user's configuration or on the system type. |
It is determined by the |
Team discussion:
|
I just want to highlight this piece of @joshuaspence's description:
This implies that the current behaviour of nix is impure / dependent on an order of operations, which suggests that this code needs to change in some way regardless to address this impurity. It should be acknowledged that this impurity occurs in a particular edge case, but it is an impurity. |
The order of evaluation matters because the fetcher-cache is being polluted and keyed by only the rev, but not by all the attributes describing how the repo is fetched.
Then, the two mechanisms do the fetch with different settings:
It is documented that:
which seems to imply that this uses the contents of the work directory, not the contents of the git objects, hence after filters are run. It's odd and surprising that the attribute format behaves differently than the plain file URL format, but at least a portion of the problem is due to the fact that the fetcher cache is seeing them as equivalent. This leads to the order-of-operations impurity. Edit: looks like it was attempted to include this information into the fetcher cache with the Edit2: The problem would be fixed if the workdir format correctly used the attribute that reflected that is post-export - setting exportIgnore to false. |
Just for context, Nix is currently inconsistent about smudge/clean filters as well. We'll need similar calls in the source access for git workdirs, but we could make that the scope of a future PR. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2025-07-09-nix-team-meeting-minutes-233/66474/1 |
Motivation
Nix 2.20 introduced a regression (a breaking change) in which git repositories do not properly have filters applied (specifically filters that are configured via
.gitattributes
). This manifests as "NAR hash mismatch" errors when users are upgrading from earlier versions and they have a dependency that uses.gitattributes
to manipulate line endings.curl
is the most notable example I am aware of which, for example, specifies in.gitattributes
that*.bat
files should have CRLF line endings.Note that although this change is technically a breaking change, it is undeniably fixing some very broken behaviour within Nix and, therefore, I believe that it is worthwhile. Additionally, I suspect that there are very few dependencies in the wild that are actually affected by this bug and so hopefully the blast radius is small.
Context
Fixes #11428.
The current nix behaviour seems completely broken when it comes to handling git filters.
The output of the above script on my machine is as follows:
This shows that the way Nix is handling git repositories is inconsistent with git, irrespective of the user and/or system git configuration.
Another manifestation of this bug is that the NAR hash for a git repository can change depending on the order of evaluations. This can be demonstrated by the following script:
The output of this script is as follows:
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.