Nixpkgs should do something to stop line endings being converted to CRLF
As absurd-looking the situation described in the title is, it is a real thing happening in some otherwise reasonable-seeming workflows. This was found trying to debug local build problems at #421200.
@sxmair did not provide the full logs but the symptoms are clear: Everything gets rebuilt, and promptly fails. Specifically bootstrap-tools gets a different hash than expected, and fails with this confusing message:
: not foundvfmsncamj00syrsyihr8hra70ic0jkj9-unpack-bootstrap-tools.sh: line 5:
error: Cannot build '/nix/store/pnn9q0q55xsxyqwgn0ilffamhkjfhid5-bootstrap-tools.drv'.
Reason: builder failed with exit code 127.
Output paths:
/nix/store/bx5zx1mxng79fmggmxldzw53vlbx7cb4-bootstrap-tools
What happened was that this copy of the Nixpkgs repo was cloned on Windows into WSL's file share with Git option core.autocrlf = true. This mangled every file with line endings CRLF instead of LF, and now bootstrap-tools is different. It also makes bash choke on an empty line that now has a sole CR in it.
This took infuriatingly long and some lucky inspiration to diagnose. The first line of output pointing to line ending problems only seems obvious in hindsight. What's more, it's hard to tell that Git has performed this on the files: running git status even on Linux in WSL shows an apparently clean worktree.
It would be great if Nixpkgs could check for this and bail early. I tried to add a check somewhere but I can't figure out where I should put it, so I'm reporting this as an issue in case anyone can take a look.
IMO: slowing down eval to check for this would be bad. Surely there's a way to enforce crlf behavior in git?
Just checking one file would be good enough
Edit: Just to spell it out, I'm thinking we do one builtins.readFile and check it against a string, and if it doesn't match error out. That's it.
Perhaps the fix for a new CVE in Git related to how it handles line endings would address this issue?
- https://dgl.cx/2025/07/git-clone-submodule-cve-2025-48384
- https://www.cvedetails.com/cve/CVE-2025-48384/
It's fixed in git v2.49.1 and v2.50.1.
I came here checking to see if work was underway to update Git in Nixpkgs.
Yeah, it's in progress:
- https://github.com/NixOS/nixpkgs/pull/423647
- https://github.com/NixOS/nixpkgs/pull/423553
nixpkgs doesn't have submodules, so that's unrelated. We can use .gitattributes to enforce LF endings, I believe.
.gitattributes may be a better idea. Thanks for the tip.
I'm currently playing around with using .gitattributes for this at https://github.com/me-and/nixpkgs/tree/crlf.
Confirmed I can reproduce the problem, and my naive attempt at using .gitattributes at https://github.com/me-and/nixpkgs/tree/crlf means the build works. I'm currently checking what I've broken instead...
For context, I used the workflow suggested in the gitattributes(5) man page under "End-of-line conversion". That resulted in a bunch of files that are in the nixpkgs repo being converted from CRLF to LF line endings, mostly patch files. I'm not entirely clear on whether patch will handle that change cleanly or not; if it doesn't then the solution here will need at least a little bit more intelligence to avoid unexpectedly changing the line endings of files that do need CRLF.