How to download/build static/portable nix binaries for MacOS (without /nix volume)

For Linux there seem to be pre-built static/portable binaries Where can I get a statically built nix? - #15 by shamrocklee

allowing Nix to work with alternative store paths, e.g.:

nix build --store 'local?store=/tmp/my-nix/store&state=/tmp/my-nix/state&log=/tmp/my-nix/log' nixpkgs#hello

But for MacOS how would that work without first having to do first install nix to /nix. Are there pre-built static/portable binaries for MacOS at all?

Wouldn’t it be extra interesting to do this for MacOS because the regular way to install Nix on MacOS is so cumbersome and error prone (creating a new encrypted volume, etc)?

1 Like

Just a bit of clarification:

What a store URL (given to the Nix command flag --store or the Nix config option store) specify is not an alternative store directory (builtins.storeDir or /nix/store), but more like an alternative chroot root where /nix/store resides.

Ah okay, thanks, but I guess there is a way of actually setting an alternative store path in Nix, right? In my question just substitute that for the wrong command I gave.

PS: MacOS actually does seem to support chroot as well, why isn’t that used for Nix on Mac rather than the awkward volume creation/mounting procedure for /nix ?

I think --store would be what you’re looking for instead of builtins.storeDir changing. (The latter causes world rebuild and was only relevant before we have the former.)

I’m not familiar with Mac, but have heard that Nix people experienced quite a few trouble before fixing the Nix installation and multi-user mode support on MacOS.

No, I was actually looking for a truly different store path. I want to world rebuild (i.e. compile from source instead of downloading packages from the Nix cloud cache). But before even getting to try that, I’m failing to even run Nix on MacOS without first setting up the /nix volume stuff bc as far as I know the prebuilt MacOS binaries assume to be installed in /nix

Lack of bind mounts iirc.

No one wants the “awkward” procedure.

chroot Environments on macOS (draft) · GitHub looks like a decent introduction to how elegant/simple a chroot approach would be.

1 Like

That same post also mentions that it’s become impossible to use chroot when System Integrity Protection is enabled. Disabling SIP is a no-go at least for work provided Macs.

1 Like

A notable darwin alternative to chroot by @Thesola10 is fakedir, but it also clashes with SIP in some cases:

2 Likes

In the context of this thread, the project fakedir was made for might be of particular interest:

Running the nix script at the root of your repository will automatically determine if you have Nix installed or not. If Nix is installed, it will just redirect the call to your system-wide Nix. It’s when it is not installed that the magic happens.

Nixie will automatically download a prebuilt static nix binary from this repository’s CI jobs into your user’s cache directory

2 Likes

Ah, indeed, that looks useful, thanks!

Do I understand this correctly that this: nixie/static-bins/default.nix at 67a9c1248deea80e55a84b9421cc83c73e0d0dc2 · nixie-dev/nixie · GitHub is the derivation able to build a static version of nix for MacOS that doesn’t require /nix ? Assuming fakedir caused problems on Mac would this also work without fakedir and simply a non /nix store path or is the fakedir approach hardcoded into this?

You mentioned fakedir also clashes with SIP. Do you know in which ways?