numtide / treefmt

one CLI to format your repo [maintainers=@zimbatm,@brianmcgee]
https://treefmt.com
MIT License
575 stars 35 forks source link

Dev shell environment fails to build on macOS #129

Closed brianmcgee closed 1 year ago

brianmcgee commented 2 years ago

Describe the bug

Unable to enter the the dev shell on an M1 MacBook Pro

To Reproduce

Steps to reproduce the behavior:

  1. Get yourself an M1 MacBook Pro, however I suspect macOS BigSur in general is all that's required
  2. Try to enter the dev shell by running nix-shell from the root of the repository.

Expected behavior

$ nix-shell --show-trace                                                                                                                                              1 ↵
error: while evaluating the attribute 'args' of the derivation 'treefmt' at /nix/store/qq9vbals3s6dyry604sji10jix15fk8h-source/nix/mkNakedShell.nix:31:10:
while evaluating the attribute 'buildInputs' of the derivation 'coreutils-8.32' at /nix/store/zz4q0z1jj8m72k9qbcp4vs4rj954w64q-source/pkgs/stdenv/generic/make-derivation.nix:192:11:
while evaluating the attribute 'depsBuildBuild' of the derivation 'gmp-6.2.1' at /nix/store/zz4q0z1jj8m72k9qbcp4vs4rj954w64q-source/pkgs/development/libraries/gmp/6.x.nix:15:3:
while evaluating 'getOutput' at /nix/store/zz4q0z1jj8m72k9qbcp4vs4rj954w64q-source/lib/attrsets.nix:482:23, called from undefined position:
while evaluating anonymous function at /nix/store/zz4q0z1jj8m72k9qbcp4vs4rj954w64q-source/pkgs/stdenv/generic/make-derivation.nix:133:17, called from undefined position:
while evaluating the attribute 'stdenv.cc' at /nix/store/zz4q0z1jj8m72k9qbcp4vs4rj954w64q-source/pkgs/stdenv/generic/default.nix:166:14:
while evaluating the attribute 'cc' at /nix/store/zz4q0z1jj8m72k9qbcp4vs4rj954w64q-source/pkgs/stdenv/generic/default.nix:166:14:
while evaluating the attribute 'cc' at /nix/store/zz4q0z1jj8m72k9qbcp4vs4rj954w64q-source/pkgs/stdenv/native/default.nix:122:5:
anonymous function at /nix/store/zz4q0z1jj8m72k9qbcp4vs4rj954w64q-source/pkgs/build-support/cc-wrapper/default.nix:8:1 called without required argument 'lib', at /nix/store

System information

Running this from latest master on macOS Big Sur 11.4, M1 Chip.

zimbatm commented 2 years ago

Can you try with #130 ? I have seen that issue before and I think it has been fixed in nixos-unstable.

brianmcgee commented 2 years ago

Different failure now:

strip is /nix/store/0zcf6wnk2zrpdz6q4rqk4y90yfcw7mvn-clang-wrapper-11.1.0/bin/strip
patching script interpreter paths in /nix/store/mgqgsdsjdvqrb67b7bm8b6mxf6jc9f4a-ormolu-0.1.4.1-data
strip is /nix/store/0zcf6wnk2zrpdz6q4rqk4y90yfcw7mvn-clang-wrapper-11.1.0/bin/strip
patching script interpreter paths in /nix/store/8ai2rsfpx9gc43d5jxawm53wqll13ql5-ormolu-0.1.4.1-doc
strip is /nix/store/0zcf6wnk2zrpdz6q4rqk4y90yfcw7mvn-clang-wrapper-11.1.0/bin/strip
stripping (with command strip and flags -S) in /nix/store/gl2832pyfc7l1pzji6hbckfkqyhqi1qz-ormolu-0.1.4.1-bin/bin
patching script interpreter paths in /nix/store/gl2832pyfc7l1pzji6hbckfkqyhqi1qz-ormolu-0.1.4.1-bin
cycle detected in the references of '/nix/store/gl2832pyfc7l1pzji6hbckfkqyhqi1qz-ormolu-0.1.4.1-bin' from '/nix/store/llpjv8kzb16r8hw19wd8wqx0srcvr5ll-ormolu-0.1.4.1'
cannot build derivation '/nix/store/lzsqfzy8zqgw974z00ap75qlw1sm5cki-devshell-dir.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/ddiwqrf2c3h9qg6f5dmwc8719ilv2lp0-treefmt-entrypoint.drv': 1 dependencies couldn't be built
error: build of '/nix/store/ddiwqrf2c3h9qg6f5dmwc8719ilv2lp0-treefmt-entrypoint.drv' failed

Earlier in the compilation I was seeing a lot of this from various packages:

'apple-a7' is not a recognized processor for this target (ignoring processor)`
zimbatm commented 2 years ago

That's because aarch64-darwin is not quite there yet. You can try nix-shell --system x86_64-darwin

brianmcgee commented 2 years ago

I literally just had a look at the flake and saw the architectures listed and realised it didn't have a aarch64-darwin.

Tried with x86_64-darwin but ran into this:

warning: ignoring the user-specified setting 'system', because it is a restricted setting and you are not a trusted user

I'm using Nix Darwin, so I'm trying to figure out how to make my user a trusted user.

brianmcgee commented 2 years ago

That's because aarch64-darwin is not quite there yet. You can try nix-shell --system x86_64-darwin

As an aside, where can I track the effort to add ARM support?

brianmcgee commented 2 years ago

I was able to activate flake support and successfully built 😄

Is there a way to set x86_64-darwin as the default system system wide? An env variable or something?

zimbatm commented 2 years ago

You want to set system = "x86_64-darwin" in /etc/nix/nix.conf. In nix-darwin, this can be achieved by adding it to the nix.extraOptions attribute. See https://github.com/LnL7/nix-darwin/blob/e1a3f7292f085fd588d11f94ed0f47968c16df0c/modules/nix/default.nix#L126-L134

I'm not sure if there is a meta ticket for M1. There is https://github.com/NixOS/nixpkgs/issues/116341 or search for M1 or aarch64-darwin on the issue tracker. I think https://github.com/NixOS/nixpkgs/pull/136049 might be related to the error you were seeing, ormolu is the code formatter for Haskell.

saifelokour commented 2 years ago

Thanks for this! Just wanted to add that you want to set system = x86_64-darwin in /etc/nix/nix.conf without the quotes around x86_64-darwin 😃

montchr commented 1 year ago

I cloned this repo for the first time on aarch64-darwin, ran direnv allow upon entering the repo, and the devshell built without issues. nix develop also works.

Edit:

System info: latest master, M2 MacBook Air, macOS@12.6.1

FWIW, I already had extra-platforms = x86_64-darwin aarch64-darwin in my /etc/nix/nix.conf, managed by a nix-darwin flake.

brianmcgee commented 1 year ago

Yeah this can be closed, I forgot about it 😅