August 4, 2020•499 words
I've recently fallen down the rabbit whole of exploring Nix and it's ecosystem of projects. That includes NixOS; however, since my nomad machine is a Macbook Pro from 2016 (MBP 13,1), I've hit a wall with the hardware compatability of installing a Linux distro as the primary OS on my machine (actually, the support is improving everyday -- my biggest issues are with A2DP for bluetooth headphones and sleep/hibernate/resume on a dual boot of Fedora 32 running the latest kernel). I've known about the ability of installing Nix on a macOS machine, but that wasn't enough for me. I wanted the ability to declaratively describe as much of my machines configuration as possible. Recently, I stumbled across nix-darwin.
Here's the gist, BUT make sure you read below for an explanation of flags. With Nix being fairly new and still actively developed, things often change quickly -- especially as it relates to install nix on other *unix distros.
#!/usr/bin/env bash ##### INSTALL NIX ##### wget -qO - https://nixos.org/nix/install | sh -s -- --daemon --darwin-use-unencrypted-nix-store-volume ##### START NIX DAEMON ##### sudo -b nix-daemon # launchctl script for nix-daemon ##### INSTALL NIX-DARWIN ##### sudo -b su NIX_DARWIN_INSTALLER="$TMPDIR/nix-darwin-installer" mkdir -p "$NIX_DARWIN_INSTALLER" && cd "$NIX_DARWIN_INSTALLER" nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer ./result/bin/darwin-installer source /etc/static/bashrc darwin-rebuild switch
Install Nix on APFS Volume (
nix-darwin still needs Nix already installed. That's tricky on its own because Nix tools expects to write to and control
/nix while the root of the partition is made read only by Apple as a method to protect your computer from malicious software. Since High Sierra, Apple has defaulted to using APFS. This has allowed the Nix team to come up with a clever solution that creates an APFS volume that gets mounted to
/nix during installation. While I'm not an expert on filesystems, it helps for me to consider APFS volumes as something similar to Btrfs subvolumes in that they are space sharing volumes -- meaning you don't have to define the size of the volume during creation like you would in LVM with ext4. More information can be found on the Nix installation instructions.
Install Nix as Multi-User Installation (
I opted to install Nix as a multi-user installtion on my macOS for a few reasons:
- Allows for multiple users to use the packages installed by Nix
- It felt a little more like NixOS as NixOS is by default a multi-user install
- I didn't see any downsides More information can be found on the Nix installation instructions.
nix-darwin can be installed. Follow along with the prompts given while the installation script is running.
PS: This post is going to be actively updated, improved upon, and added to over the near future as I learn more and dig into Nix on Darwin. I'm also aiming to do a clean install soon of macOS Catalina to verify these install steps work as expected as system creep can affect things.