NixOS / nix

Nix, the purely functional package manager

Home Page:https://nixos.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nix flakes: git CRLF line endings are not handled

tmplt opened this issue · comments

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 👍 to issues you find important.

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

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