This repository contains the full declarative configuration for my macOS setup, managed by Nix and nix-darwin. The goal is a reproducible and version-controlled system.
The configuration is structured into several key directories.
- hosts/: Contains the main entry point for each specific machine.
darwin/default.nix: The main file for this Mac, which assembles all the necessary modules.
- modules/: Contains reusable pieces of the configuration.
darwin/: Modules with settings that only apply to macOS.casks.nix: A list of graphical.appfiles to install via Homebrew.packages.nix: A list of command-line tools for macOS.system.nix: macOS-specific system settings (system.defaults).
shared/: Modules with settings that apply to all systems.home-manager.nix: The main configuration for user-level programs like Git, Zsh, and Neovim.
- overlays/: Used for advanced package customizations (optional).
To set up a new Mac from scratch:
-
Install Nix: Run the Determinate Systems Nix Installer script.
curl --proto '=https' --tlsv1.2 -sSf -L [https://install.determinate.systems/nix](https://install.determinate.systems/nix) | sh -s -- install
-
Get a temporary Git shell:
nix-shell -p git
-
Clone this repository:
git clone [https://github.com/your-username/nixos-config.git](https://github.com/your-username/nixos-config.git) ~/nixos-config cd ~/nixos-config
-
Perform the initial build and activation:
# First, build the configuration to create the './result' link nix build '.#darwinConfigurations.aarch64-darwin.system' # Second, run the activation script from the result with sudo sudo ./result/sw/bin/darwin-rebuild switch --flake .#aarch64-darwin
-
Perform Initial App Setup: These are one-time manual steps after the first
switchhas completed.-
Enable Kubernetes in OrbStack:
- Launch OrbStack from your Applications folder.
- Click the OrbStack icon in the menu bar -> Settings.
- Navigate to the Kubernetes section and check the "Enable Kubernetes" box.
-
Set
kubectlContext:- Open a new terminal tab.
- Run the following command to point
kubectlto your local OrbStack cluster:kubectl config use-context orbstack
-
Configure 1Password:
- Launch the 1Password app from your Applications folder and sign in.
- Open Settings (
⌘,) and navigate to the Developer tab. - Check the box for "Integrate with 1Password CLI".
- Verify the setup in a new terminal by running
op account list. It should prompt for your fingerprint (Touch ID) and then show your account details.
-
Any time I edit a .nix file to change a setting, add an application, or modify the configuration, I follow this process:
-
Commit the changes (Best Practice):
git add . git commit -m "feat: add new tool and tweak settings"
-
Activate the new configuration: (This alias is defined in
modules/shared/home-manager.nix)nix-switch
(Or, the full command:
sudo darwin-rebuild switch --flake .#aarch64-darwin)
To update all underlying software (Nixpkgs, Home Manager, etc.) to their latest versions:
-
Update the flake's lock file:
nix flake update
-
Apply the updates to the system:
# First, commit the new flake.lock git add flake.lock git commit -m "chore: update flakes" # Then, switch to the new configuration nix-switch
Nix stores every version of every package. Over time, this can use a lot of disk space. To clean up old, unused versions (generations) of your system:
1. List current system generations:
bash darwin-rebuild --list-generations
2. Delete all old (not currently booted) generations:
bash nix-collect-garbage -d