News for hackers. Stuff that matters.
Re:macOS Nix setup: an alternative to Homebrew (2020) by callahad on Tuesday July 13, 2021 @05:34PM (#27826592)
A better future is on the horizon (or here, today, if you're willing to install a 2.4 pre-release): Flakes make it trivial to fall back to x86_64 when aarch64 fails, and the CLI experience is dramatically improved.

Alas, that path is probably not yet suitable for folks without prior Nix experience, given how new everything is.

Re:macOS Nix setup: an alternative to Homebrew (2020) by ianthehenry on Tuesday July 13, 2021 @05:53PM (#27826745)
Are flakes necessary for that? I would think you could install x86_64 binaries manually by setting `system`, even on the 2.3 branch. It seems I can do the reverse thing:

    $ nix-env -iA nixpkgs.hello --argstr system aarch64-darwin
    $ file $(which hello)
    /Users/ian/.nix-profile/bin/hello: Mach-O 64-bit executable arm64
But maybe you just mean that it does this automatically? That's neat, if so. And I would expect this to be a lot more annoying within a default.nix file, having to keep track of two different nixpkgs imports.
Re:macOS Nix setup: an alternative to Homebrew (2020) by callahad on Tuesday July 13, 2021 @06:05PM (#27826855)
Not automatic, but as a replacement for nix-env and nix-shell, it's great. When I need an x86_64 package, I find `nix shell nixpkgs#legacyPackages.x86_64-darwin.neovim` easier to recall and reason about.

(Or `nix profile install nixpkgs#...` for a persistent version of the same)

Re:macOS Nix setup: an alternative to Homebrew (2020) by Filligree on Wednesday July 14, 2021 @08:35AM (#27832342)
Where would I look to get started with that?

I do have preexisting Nix experience, as well as with flakes, but I don't know how it applies to my M1.

Re:macOS Nix setup: an alternative to Homebrew (2020) by callahad on Wednesday July 14, 2021 @05:07PM (#27838456)
What I did on my M1 was:

1. Grab a pre-release of Nix 2.4 from the `binaryTarball.aarch64-darwin` job on Hydra: https://hydra.nixos.org/jobset/nix/master#tabs-jobs

2. Run the installer with: ./install --daemon --no-channel-add

3. Edit `/etc/nix/nix.conf` to include the line: experimental-features = nix-command flakes ca-references

4. Restart the daemon with: sudo launchctl kickstart -k system/org.nixos.nix-daemon

5. Done!

At this point you have a Nix installation, without any legacy channels, which uses aarch64-darwin by default. If you have Rosetta2 installed, Nix will automatically detect it and set `extra-platforms = x86_64-darwin` so you can seamlessly use / build software for other architectures. If you want to specifically get an Intel version of something in nixpkgs, you have to explicitly state it like: `nixpkgs#legacyPackages.x86_64-darwin.foo`

I found Alexander Bantyev's blog post, "Practical Nix Flakes" (https://serokell.io/blog/practical-nix-flakes) especially helpful in figuring out how things are intended to work, followed by the unstable branch of the Nix documentation at https://nixos.org/manual/nix/unstable/command-ref/new-cli/ni..., which covers the new CLI commands.