This repository setup a new macOS using nix-darwin and flakes.
-
Install Nix
Ref: https://github.com/DeterminateSystems/nix-installer
curl -fsSL https://install.determinate.systems/nix | sh -s -- installIf the first run fails, try running it again.
-
Install xcode-select
Required by Homebrew later. Still requires a manual agreement to License.
xcode-select --install softwareupdate -i -a --agree-to-license -
Copy config files
Copy is used here instead of clone. Init a repo to backup the final settings.
mkdir -p ~/.config/nix-config && cd ~/.config/nix-config curl -L https://github.com/lcenchew/macnix/archive/main.tar.gz | tar -xz --strip-components=1 -
Setup Nix config
Refresh the env to take in changes from Nix install. Then run the setup logic.
exec zsh chmod +x setup ./setup
For Mac Mini with 256G drive, attempt to install Nix to an external SSD Prepare the drive as follows before running above setup.
-
List available drives to identify the external storage device identifier (e.g., disk3, disk4)
diskutil list -
Add an external APFS Volume named
Nix StoreReplace diskX with the actual identifier identified above.
diskutil apfs addVolume diskX APFSX "Nix Store"
macOS protects the root directory using Signed System Volumes (SSV). Use /etc/synthetic.conf to instruct the operating system kernel to spawn an empty root-level mount point on the next launch. (see man synthetic.conf)
-
Update /etc/synthetic.conf
echo "nix" | sudo tee -a /etc/synthetic.conf -
Reboot. Check.
ls /
-
Get the
Volume UUIDdiskutil info "Nix Store" | grep "Volume UUID" -
Add volume to fstab
Replace with the value found above.
echo "UUID=<VOLUME UUID> /nix apfs rw,noatime,nobrowse,nosuid,owners,failok,late" | sudo tee -a /etc/fstab -
Reboot. Check.
df -h /nix
~/.config/nix-config
.
├── flake.nix # Standardized to look for current-host.nix
├── common.nix # Shared settings across all hardware type
├── macbook.nix # Settings for macbook
├── macmini.nix # Settings for macmini
├── current-host.nix # Created based on setup parameters (not committed, .gitignore)
└── setup # The setup logic
- Nix: Use for shell, terminal tools (Git, Neovim, Python, Node), and system settings (Dock, Trackpad).
- Homebrew (via Nix): Use for GUI "Apps" normally found /Applications folder.
- Experimental Features: This config enables
nix-commandandflakesby default. - system.stateVersion: Do not update this value even when updating Nixpkgs. It represents the compatibility state of the system when first installed. Changing it may result in data migration issues.
Some basics to maintain and manage the system after installing.
-
Determinate Nix See https://github.com/DeterminateSystems/nix-installer#upgrading-determinate-nix
sudo determinate-nixd upgrade -
flake
cd .config/nix-config sudo -H nix flake update sudo -H darwin-rebuild switch --flake .#current-host