How to install nix on MacOS with m1?

I am struggling to install nix on a mac with m1. I have checked out all the related issues, but I am not sure what to do to install properly as an end-user

These are the issues:

How can I install nix on a M1 mac?

I’ve been looking for information on the same topic.

The conclusion so far is that it’s not supported. See supported platforms in the manual:

Maybe possible to use it as x86_64 with Rosetta though? But that seems hugely inefficient since it presumably forces all installed software to also run as x86_64. Happy to hear counter-arguments though :wink:

There’s nixpkgs support for aarch64-darwin now. The issues is how to get a version of nix which is compatible with aarch64-darwin.

Luckily, the 2.3.13 release of nix also updated the installer script to include a proper fix to the install script. https://releases.nixos.org/nix/nix-2.3.13/install

You should be able to curl -L https://nixos.org/nix/install | sh yourself into nix on M1 now. (not sure if the /nix mount is still an issue, don’t own an M1)

1 Like

The mount issue was ~fixed in master via nix#4289, but the changes haven’t been backported to 2.3.x.

At the time, I didn’t really anticipate how far off the next release from master would be–and other/overlapping unreleased work in master adds some friction to backporting it. (If someone wants to try, I outlined likely steps in darwin: encrypt nix volume if filevault is enabled by abathur · Pull Request #4289 · NixOS/nix · GitHub)

1 Like

you can build nix from sources, create a mountpoint /nix by self.

./configure --prefix=/nix --with-boost=$HOME/.me
✿ file /nix/bin/nix                                                                                      ─╯
/nix/bin/nix: Mach-O 64-bit executable arm64

if package support aarch64-darwin, install successful:

✿ file /nix/store/blcjz4b5fjkxlwx5rpzsgq398gf9lgf1-rustc-1.52.1/bin/rustc                                ─╯
/nix/store/blcjz4b5fjkxlwx5rpzsgq398gf9lgf1-rustc-1.52.1/bin/rustc: Mach-O 64-bit executable arm64

if not support aarch64-darwin:

error: Package ‘ghc-8.10.4’ in /nix/store/m62zfwzwss5bap5ly32w5rmnncypfjd5-nixpkgs/nixpkgs/pkgs/development/compilers/ghc/8.10.4.nix:267 is not supported on ‘aarch64-darwin’, refusing to evaluate.

use export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 still not work

error: cannot bootstrap GHC on this platform
(use '--show-trace' to show detailed location information)

i hope nix will can install only support x86_64 package with Rosetta

2 Likes

I can confirm Nix 2.3.15 can be properly installed on aarch64-darwin simply following the manual’s instructions: Introduction - Nix Reference Manual

1 Like

You guys should probably be testing Nix 2.4 release candidate - #2 by domenkozar :slight_smile:

1 Like

What if you already have nix installed but are on macOS? It doesn’t seem to be explicitly covered by the instructions there.

The release candidate is available in nixpkgs-unstable as nix_2_4. As long as you have access to nixpkgs-unstable somehow (channels, flake, etc), you can install it into your environment with nix-env or set nix.packages to nix_2_4 if you’re using nix-darwin.

1 Like

System:
OS: macOS 12.3
CPU: (8) arm64 Apple M1
Memory: 1.45 GB / 8.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
Yarn: 1.22.15 - /opt/homebrew/bin/yarn
npm: 8.5.2 - /opt/homebrew/bin/npm

  • I installed nix via - $ sh <(curl -L https://nixos.org/nix/install)
  • The install seemed to be successful.
  • I closed my terminal and reopened to make sure I was in a new session and when I typed nix-env I received zsh: command not found: nix-env
  • I look in my home directory and i do not see any nix sym links
  • I see that nix is not in my $PATH
  • I do see that nix has been installed in my root and I can cd into cd /nix/var/nix/profiles/default/etc/profile.d

I thought after the install appeared to be successful I could just use nix but this does not seem to be the case. How can I add nix to my path so I can start using the nix-env command?

2 Likes

You probably want to add /Users/$USER/.nix-profile/bin:/nix/var/nix/profiles/default/bin to your PATH.

The installer presumably added nix to your /etc/bashrc and /etc/zshrc, but something already in your profile scripts either prevents it from running, or overwrites the PATH after it does.

1 Like

This was my experience as well. I had to manually include the appropriate directories in my PATH environment variable.