NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.63k stars 1.51k forks source link

nix flakes: git CRLF line endings are not handled #10640

Open tmplt opened 6 months ago

tmplt commented 6 months ago

Describe the bug

On WSL2, CRLF line endings break flake build unless git attributes are overridden, usually resulting in a confusing $'\r': command not found error.

Steps To Reproduce

In a NixOS-WSL instance, run

$ git clone https://github.com/cachix/devenv.git && cd devenv
$ nix build .#devenv
error: builder for '/nix/store/hnjx2v3nw9al8pjcp4g22b2s9xhyq9r7-devenv-1.0.5.drv' failed with exit code 127;                                                                                       
last 10 log lines:                                                                                                                                                                         
>                                                                                                                                                                                           
> running 0 tests                                                                                                                                                                           
>                                                                                                                                                                                           
> test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s                                                                                             
>                                                                                                                                                                                           
> Finished cargoCheckHook                                                                                                                                                                   
> Running phase: installPhase                                                                                                                                                               
> Executing cargoInstallHook                                                                                                                                                                
> /nix/store/v5lsd029lz5lfhamivbgqyp3zdv94ah2-stdenv-linux/setup: line 114: $'\r': command not found                                                                                        
> /nix/store/v5lsd029lz5lfhamivbgqyp3zdv94ah2-stdenv-linux/setup: line 131: pop_var_context: head of shell_variables not a function context                                                 
For full logs, run 'nix log /nix/store/hnjx2v3nw9al8pjcp4g22b2s9xhyq9r7-devenv-1.0.5.drv'. 
$ echo "*.nix text eol=lf" > .gitattributes && git add .gitattributes
$ nix build .#devenv && echo $?
0

Expected behavior

devenv should be built without having to override git EOL attributes.

nix-env --version output

nix-env (Nix) 2.18.1

Additional context

Previously reported at https://discourse.nixos.org/t/nix-flakes-and-line-endings/22065, but not strictly WSL2-related.

Priorities

Add :+1: to issues you find important.

nixos-discourse commented 6 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-flakes-and-line-endings/22065/10

tmplt commented 6 months ago

MWE can very likely be reduced: git init; trivially build a file containing CRLF; observe different hash depending on git attributes?