Skip to content

Instantly share code, notes, and snippets.

@djanatyn
Created May 5, 2020 18:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djanatyn/32fb653ade52a7410794adeeae8829a1 to your computer and use it in GitHub Desktop.
Save djanatyn/32fb653ade52a7410794adeeae8829a1 to your computer and use it in GitHub Desktop.
line 1: $'\r': command not found

context

I'm on MacOS High Sierra.

$ nix --version
nix (Nix) 2.3.4
$ nix-channel --list
darwin https://github.com/LnL7/nix-darwin/archive/master.tar.gz
nixos https://nixos.org/channels/nixos-20.03
nixpkgs https://nixos.org/channels/nixpkgs-unstable
$ echo $NIX_PATH
darwin=/Users/stricklanj/.nix-defexpr/darwin:darwin-config=/Users/stricklanj/.nixpkgs/darwin-configuration.nix:nixpkgs=/Users/stricklanj/.nix-defexpr/channels/nixpkgs:nixpkgs=/Users/stricklanj/.nix-defexpr/channels/nixpkgs

problem

I'm trying to setup nix-darwin, building darwin-rebuild:

$ nix-build '<darwin>' -A system --no-out-link --show-trace

I'm running into an error with a CRLF line ending:

$ nix-build '<darwin>' -A 'config.system.build.fonts' --no-out-link --show-trace
these derivations will be built:
  /nix/store/wngfa8nwzg5rv884vfal4dkf09jyzrzi-fonts.drv
building '/nix/store/wngfa8nwzg5rv884vfal4dkf09jyzrzi-fonts.drv'...
/private/var/folders/y_/l6_63w553g122p9w9c3z9d75s_cs8r/T/nix-build-fonts.drv-0/.attr-0: line 1: $'\r': command not found
builder for '/nix/store/wngfa8nwzg5rv884vfal4dkf09jyzrzi-fonts.drv' failed with exit code 127

Inspecting the derivation, I see that the literal \r character is in the file:

$ nix show-derivation /nix/store/wngfa8nwzg5rv884vfal4dkf09jyzrzi-fonts.drv | jq '."/nix/store/wngfa8nwzg5rv884vfal4dkf09jyzrzi-fonts.drv".env.buildCommand' -C
"\r\n        mkdir -p $out/Library/Fonts\r\n        for path in $paths; do\r\n            find -L $path/share/fonts -type f -print0 | while IFS= read -rd \"\" f; do\r\n                ln -s \"$f\" $out/Library/Fonts\r\n            done\r\n        done\r\n"

This is the script that config.system.build.fonts evaluates to:

$ ag -F 'system.build.fonts' -A 9 ~/.nix-defexpr/channels/darwin/modules/fonts/default.nix
31:    system.build.fonts = pkgs.runCommandNoCC "fonts"
32-      { paths = cfg.fonts; preferLocalBuild = true; }
33-      ''
34-        mkdir -p $out/Library/Fonts
35-        for path in $paths; do
36-            find -L $path/share/fonts -type f -print0 | while IFS= read -rd "" f; do
37-                ln -s "$f" $out/Library/Fonts
38-            done
39-        done
40-      '';

questions

  • Should the literal \r character be present in the derivation?
  • Is there a darwin-nix or nix setting for line-endings?
  • How can I address my issue and build system successfully?
@573
Copy link

573 commented Aug 9, 2022

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