Changing Nix platform in place

I have the x86_64 version of Nix installed on my M1 Mac (it’s emulated using Rosetta).

  • macOS 11.6
  • nix (Nix) 2.3.16
  • home-manager 22.05

If practical, I would like to change Nix’s platform to aarch64 without a complete reinstall.

In a different thread, @ElvishJerricco mentioned that it can be done using:

sudo nix-env -p /nix/var/nix/profiles/default -f “” --argstr system aarch64-drawin -iA nix

I’m a little scared to run this command, so to be extra safe, I would like to hear some more people’s thoughts on this before I go through with it.
Is it practical to change the platform in place? And, if it is, how does reinstalling packages work?

1 Like

/nix/store doesn’t actually care what platform you’re on. You can install linux binaries in there if you like (you just can’t run them cuz, y’know, macos). Nix is just installed in the store like any other package, and you happen to have the x86_64-darwin one setup for use right now. You can install the aarch64-linux one in there without any sort of conflict. By doing it with nix-env -p /nix/var/nix/profiles/default -f "<nixpkgs>" --argstr system aarch64-darwin -iA nix, you’re telling it to make it the version that’s on your PATH. There’s no magic or trickery. It’s just installing a package like any other. From then on, Nix will default to the aarch64-darwin system for anything you install/update, simply because that’s the system it was built for.


Ah, I see! Thanks for the explanation.

By doing it with nix-env -p /nix/var/nix/profiles/default -f "<nixpkgs>" --argstr system aarch64-darwin -iA nix , you’re telling it to make it the version that’s on your PATH.

So, could I also do nix-env -p /nix/var/nix/profiles/default -f "<nixpkgs>" --argstr system x86_64-darwin -iA nix to revert back to the x86_64 version?

1 Like

Yea I would think that would work. Though that should never really be necessary, since if you ever need the x86_64 version of a package, you can always just install that using the aarch64 version of nix. e.g. nix-env -f "<nixpkgs>" --argstr system x86_64-darwin -iA emacs


I successfully changed Nix’s platform, thank you so much @ElvishJerricco !

For anyone in the future that finds this, make sure you run the command without sudo if you’re using a single user install.

That is, use the following:

nix-env -p /nix/var/nix/profiles/default -f “” --argstr system aarch64-drawin -iA nix

For me, this command didn’t override my existing Nix installation, so I first ran nix-env -e '.*' to remove everything first.
Then, I ran the following:

/nix/store/3aprinvdd7w5504cjzzd4c8q9jh8324v-nix-2.9.1/bin/nix-env -f "<nixpkgs>" --argstr system aarch64-darwin -iA nix
/nix/store/3aprinvdd7w5504cjzzd4c8q9jh8324v-nix-2.9.1/bin/nix-env -f "<nixpkgs>" --argstr system aarch64-darwin -iA cacert

Of course, replace 3aprinvdd7w5504cjzzd4c8q9jh8324v-nix-2.9.1 with your nix store path.