Setup on macbook with m1 chip

I am facing the following issue, while setting up holochain environment using nix-shell. Any help will be appreciated. Thanks

MacBook-Pro ~ % sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume
. ~/.nix-profile/etc/profile.d/nix.sh
nix-env -iA cachix -f https://cachix.org/api/v1/install
cachix use holochain-ci

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:ā€“:-- --:ā€“:-- --:ā€“:-- 0
100 2619 100 2619 0 0 6466 0 --:ā€“:-- --:ā€“:-- --:ā€“:-- 6466
downloading Nix 2.3.15 binary tarball for aarch64-darwin from ā€˜https://releases.nixos.org/nix/nix-2.3.15/nix-2.3.15-aarch64-darwin.tar.xzā€™ to ā€˜/var/folders/d3/l71kyj4n2tx_2gvf6khfd6fr0000gn/T/nix-binary-tarball-unpack.XXXXXXXXXX.ApErJqdQā€™ā€¦
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 19.9M 100 19.9M 0 0 8934k 0 0:00:02 0:00:02 --:ā€“:-- 8934k
Note: a multi-user installation is possible. See https://nixos.org/nix/manual/#sect-multi-user-installation
Creating volume and mountpoint /nix.

 ------------------------------------------------------------------ 
| This installer will create a volume for the nix store and        |
| configure it to mount at /nix.  Follow these steps to uninstall. |
 ------------------------------------------------------------------ 
  1. Remove the entry from fstab using ā€˜sudo vifsā€™
  2. Destroy the data volume using ā€˜diskutil apfs deleteVolumeā€™
  3. Remove the ā€˜nixā€™ line from /etc/synthetic.conf or the file

Using existing ā€˜Nix Storeā€™ volume
performing a single-user installation of Nixā€¦
copying Nix to /nix/storeā€¦
replacing old ā€˜nix-2.3.15ā€™
installing ā€˜nix-2.3.15ā€™
unpacking channelsā€¦

Installation finished! To ensure that the necessary environment
variables are set, either log in again, or type

. /Users/kamal/.nix-profile/etc/profile.d/nix.sh

in your shell.
replacing old ā€˜cachix-0.6.1ā€™
installing ā€˜cachix-0.6.1ā€™
Configured https://holochain-ci.cachix.org binary cache in /Users/kamal/.config/nix/nix.conf
MacBook-Pro ~ % cd developer-exercises

MacBook-Pro developer-exercises % nix-shell

error: Component resolution failed for rust-default-1.54.0

  • note: available extensions are cargo, clippy, clippy-preview, llvm-tools-preview, miri, miri-preview, reproducible-artifacts, rls, rls-preview, rust-analysis, rust-analyzer-preview, rust-docs, rust-mingw, rust-src, rust-std, rustc, rustc-dev, rustc-docs, rustfmt, rustfmt-preview
  • Host component rust-docs doesnā€™t support target aarch64-apple-darwin

@steveeJ any ideas? Iā€™ve found https://github.com/rust-lang/rustup/issues/2692 but no idea if it would work.

Apple M1s are uncharted territory for me. i donā€™t posses one and donā€™t plan on changing that anytime soon. however, i searched around the webs and found that you can enable x86_64 mode on it using this command arch -x86_64 zsh. if you run that before installing nix and running the nix-shell it hopefully works as well as on x86_86 macOS. iā€™m curious if this does work so please let us know!

i know that @lucksus had access to such a machine so maybe he can share his experience as well.

2 Likes

Thanks @steveeJ
Your suggestion works, I can install x86 nix and run tests of elemental-chat in nix-shell (3 of 49 tests failed though).

But using this way, itā€™s pretty slow and Iā€™m having network issues from time to time. Not sure if itā€™s my own case or a general issue.
Detail log:

  Downloaded proc-macro-nested v0.1.7
  Downloaded rcgen v0.8.13
  Downloaded nanoid v0.3.0
error: failed to sync

Caused by:
  failed to download packages

Caused by:
  failed to download from `https://crates.io/api/v1/crates/ahash/0.7.4/download`

Caused by:
  [55] Failed sending data to the peer (Connection died, tried 5 times before giving up)
Traceback (most recent call last):
  File "/nix/store/z3784a4xn039iz1gbfb4pzkjx0l08872-cargo-vendor-normalise/bin/.cargo-vendor-normalise-wrapped", line 42, in <module>
    main()
  File "/nix/store/z3784a4xn039iz1gbfb4pzkjx0l08872-cargo-vendor-normalise/bin/.cargo-vendor-normalise-wrapped", line 17, in main
    assert list(data.keys()) == ["source"]
AssertionError
error: builder for '/nix/store/4kak4d5bl2amzj50wiffx8zhpl5agdg3-holochain-vendor.tar.gz.drv' failed with exit code 1;
       last 10 log lines:
       >   failed to download from `https://crates.io/api/v1/crates/ahash/0.7.4/download`
       >
       > Caused by:
       >   [55] Failed sending data to the peer (Connection died, tried 5 times before giving up)
       > Traceback (most recent call last):
       >   File "/nix/store/z3784a4xn039iz1gbfb4pzkjx0l08872-cargo-vendor-normalise/bin/.cargo-vendor-normalise-wrapped", line 42, in <module>
       >     main()
       >   File "/nix/store/z3784a4xn039iz1gbfb4pzkjx0l08872-cargo-vendor-normalise/bin/.cargo-vendor-normalise-wrapped", line 17, in main
       >     assert list(data.keys()) == ["source"]
       > AssertionError
       For full logs, run 'nix log /nix/store/4kak4d5bl2amzj50wiffx8zhpl5agdg3-holochain-vendor.tar.gz.drv'.
error: 1 dependencies of derivation '/nix/store/wig4r551mzqy6dfi7cv3b4igw4l3irbn-holochain.drv' failed to build
error: build of '/nix/store/0v17nck5dkpmk89akz4w900msm40dnaz-holochain.drv', '/nix/store/lahk7ak3z9sb03b9f5vqp899ncxr4y8c-holochain.drv', '/nix/store/p3cfm6xyk5cfhnx0ihqzsjsvhg633jw3-holochain.drv', '/nix/store/wig4r551mzqy6dfi7cv3b4igw4l3irbn-holochain.drv' failed

I actually didnā€™t get my M1 macBook until today. I was waiting for the pro versions to come out and finally received mine now :slight_smile:

The problem I was fighting almost all day today and finally got the solution from @kaichao (thanks!) was the error too many open files when entering any nix-shell.

This is what @kaichao suggested and made it work for me:

sudo launchctl limit maxfiles 1024 unlimited
sudo launchctl stop org.nixos.nix-daemon

Tried only changing the file limits before. Stopping (=restarting, since nix-shell will start it again) the nix-daemon seems to be crucial since it is the process opening those files, not the shell in which you call nix-shell.

After solving that problem, I could even build Holochain for arm64 natively, that is without arch -x86_64 zsh as @steveeJ suggested. Instead I did export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 as nix-shell suggests, if you want to try building an unsupported package anyways.

So I got a Holochain arm64 binary :slight_smile:

[nix-shell:~/p/ad4m-executor]$ file /nix/store/p21x2967sdpwwzqznpa794y6wydj1x3w-github.com_holochain_holochain-9d9a556e8236234bcca64ee33620012c8a6ab095-holochain/bin/holochain
/nix/store/p21x2967sdpwwzqznpa794y6wydj1x3w-github.com_holochain_holochain-9d9a556e8236234bcca64ee33620012c8a6ab095-holochain/bin/holochain: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE|HAS_TLV_DESCRIPTORS>

Letā€™s see how that performsā€¦

3 Likes

I have a Mac Silicon M1.

Iā€™m watching DevCamp 8 ā€“ Session 3 - YouTube, specifically using @holochain/create - npm that need NodeJS. This npm package is a ā€œRAD tool to rapidly scaffold Holochain applicationsā€ in svelte, lit or Vue front-end.

I could install nix-shell and cachix following @lucksus advice:

You could set this variable permanently on your Shell configuration file. Iā€™m using ZSH, then I added to config file ~/.zshrch this:

# Holochain.love
alias nshl="nix-shell https://holochain.love" # This is for running `nshl` command instead of `nix-shell https://holochain.love`

# Allow holochain.love that is unsupported for this system (aarch64-darwin)
export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1

To me, I had one error in nix-shell ā€œnode.js - wasm code commit Allocation failed - process out of memory - Stack Overflowā€ before using the npm package, it was related to Node 12, it seems it doesnā€™t support arm64 architecture.

I see the that @holochain/create - npm v0.0.26 uses Nix with Node v16.x. Look at default.nix file:

# Located in <your_app_directory>/default.nix
let
  holonixRev = "d15633710a8d4349dc0ff03b7b47ad01eb9f2433";

  holonixPath = builtins.fetchTarball "https://github.com/holochain/holonix/archive/${holonixRev}.tar.gz";
  holonix = import (holonixPath) {};
  nixpkgs = holonix.pkgs;
in nixpkgs.mkShell {
  inputsFrom = [ holonix.main ];
  packages = with nixpkgs; [
    # Additional packages go here
    nodejs-16_x
  ];
}

Node 16.0.0 supports Apple Silicon (Node v16.0.0 (Current) | Node.js).

This Node version is working on my Mac, furthermore, Iā€™m using nvm.

1 Like