Personal Nix flake for macOS (nix-darwin) and NixOS.
-
Set hostname (must match a
darwinConfigurationsentry inflake.nix):my_hostname="my-macbook-pro" sudo scutil --set HostName $my_hostname sudo scutil --set LocalHostName $my_hostname sudo scutil --set ComputerName $my_hostname dscacheutil -flushcache
-
Install Lix (docs):
curl -sSf -L https://install.lix.systems/lix | sh -s -- install nix run nixpkgs#hello # verify it works
-
Clone this repo to
~/system -
Add machine config if needed:
- Create
machines/<hostname>/default.nix - Add
darwinConfigurationsentry inflake.nix
- Create
-
Optional: Create
.envto override hostname (see.env.example) -
First build:
nix run nix-darwin -- switch --flake .
After initial setup:
mise nix-switch # from ~/system directory
nix-switch # from anywhere (shell alias)Update flake inputs and rebuild:
mise nix-upgrade # from ~/system directory
nix-upgrade # from anywhere (shell alias)Managed via modules/darwin/brew.nix. See docs/homebrew-vs-nixpkgs.md for when to use Homebrew vs nixpkgs.
brew bundle check -v # list missing dependencies
brew bundle cleanup # list unexpected dependencies (--force to remove)-
Move generated config:
sudo mv /etc/nixos ~/system && sudo chown -R $USER ~/system cd ~/system
-
Clone this repo, preserving hardware config:
mv hardware-configuration.nix .. git init && git remote add origin https://github.com/aviraccoon/system && git fetch origin git reset --hard origin/main mv ../hardware-configuration.nix ./machines/$(hostname)/hardware.nix
-
Add
nixosConfigurationsentry inflake.nixfor your hostname -
Build:
sudo nixos-rebuild switch --flake .