nix-darwin
Getting started
Section titled “Getting started”This guide walks you through setting up macOS with nix-darwin to configure native settings and preinstall essential apps and configurations.
References
Section titled “References”-
Make directory
Section titled “Make directory”Terminal window mkdir ~/.nix-config && cd ~/.nix-config -
Add nix files
Section titled “Add nix files”flake.nix {description = "nix-darwin system";inputs = {# Use `github:NixOS/nixpkgs/nixpkgs-24.11-darwin` to use Nixpkgs 24.11.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";# Use `github:LnL7/nix-darwin/nix-darwin-24.11` to use Nixpkgs 24.11.nix-darwin.url = "github:LnL7/nix-darwin/master";nix-darwin.inputs.nixpkgs.follows = "nixpkgs";};outputs = inputs@{ self, nix-darwin, nixpkgs }: {darwinConfigurations."{{HOSTNAME_VAR}}" = nix-darwin.lib.darwinSystem {modules = [ ./configuration.nix ];specialArgs = {inherit inputs;hostname = "{{HOSTNAME_VAR}}";user = "{{USERNAME_VAR}}";home = "/Users/{{USERNAME_VAR}}";};};};}configuration.nix { config, pkgs, specialArgs, ... }:lethome = specialArgs.home;in{imports = [./system.nix];# Nix configurationsystem.stateVersion = 6;nix.enable = false;nix.settings.experimental-features = [ "nix-command" "flakes" ];nixpkgs.hostPlatform = "x86_64-darwin";# System packages# environment.systemPackages = with pkgs; [# fd# ffmpeg# fzf# jq# bat# gh# pipx# ];# # zsh# programs.zsh = {# enable = true;# enableCompletion = true;# enableFastSyntaxHighlighting = true;# shellInit = ''# source ${home}/.nix-config/.dotfiles/.zshrc# '';# };}system.nix { config, pkgs, specialArgs, ... }:lethome = specialArgs.home;in{# Globalsystem.defaults.NSGlobalDomain.AppleInterfaceStyle = "Dark";system.defaults.NSGlobalDomain.AppleShowAllExtensions = true;system.defaults.trackpad.TrackpadRightClick = true;system.defaults.NSGlobalDomain."com.apple.trackpad.enableSecondaryClick" = true;system.defaults.NSGlobalDomain."com.apple.trackpad.trackpadCornerClickBehavior" = 1;# Findersystem.defaults.finder.AppleShowAllFiles = true;system.defaults.finder.AppleShowAllExtensions = true;system.defaults.finder._FXSortFoldersFirst = true;system.defaults.finder._FXSortFoldersFirstOnDesktop = true;system.defaults.finder.FXDefaultSearchScope = "SCcf";system.defaults.finder.FXEnableExtensionChangeWarning = false;system.defaults.finder.FXPreferredViewStyle = "Nlsv";system.defaults.finder.QuitMenuItem = true;system.defaults.finder.ShowRemovableMediaOnDesktop = false;system.defaults.finder.ShowExternalHardDrivesOnDesktop = true;system.defaults.finder.ShowHardDrivesOnDesktop = false;system.defaults.finder.ShowMountedServersOnDesktop = false;system.defaults.finder.ShowPathbar = true;system.defaults.finder.ShowStatusBar = true;system.defaults.finder.NewWindowTarget = "Other";system.defaults.finder.NewWindowTargetPath = "file:///${home}/Downloads";# Docksystem.defaults.dock.tilesize = 64;system.defaults.dock.largesize = 16;system.defaults.dock.orientation = "right";system.defaults.dock.mineffect = "genie";system.defaults.dock.minimize-to-application = true;system.defaults.dock.autohide = false;system.defaults.dock.launchanim = true;system.defaults.dock.show-process-indicators = true;system.defaults.dock.show-recents = false;system.defaults.dock.persistent-others = null;system.defaults.dock.persistent-apps = ["Applications/Google Chrome.app""/System/Applications/Utilities/Terminal.app""/Applications/Visual Studio Code.app""/System/Applications/System Settings.app"];# Desktop & Stage managersystem.defaults.WindowManager.StandardHideDesktopIcons = false;system.defaults.WindowManager.HideDesktop = true;system.defaults.WindowManager.EnableStandardClickToShowDesktop = false;system.defaults.WindowManager.GloballyEnabled = false;system.defaults.spaces.spans-displays = false;# Miscellaneous#security.pam.services.sudo_local.touchIdAuth = true; # Enable if TouchID existssystem.defaults.screencapture.location = "~/Documents/screenshots";system.defaults.controlcenter.Bluetooth = true;# macOS security updatessystem.defaults.CustomUserPreferences."com.apple.SoftwareUpdate".CriticalUpdateInstall = 1;# app store updatessystem.defaults.CustomUserPreferences."com.apple.commerce".AutoUpdate = true;system.activationScripts.postUserActivation.text = ''# Create dirsmkdir -p ~/Documents/screenshots ~/Documents/dev# Keep: Map bottom right corner to right-clickdefaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 2defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -int 0# "disable" Writing of .DS_Store files on network or USB volumesdefaults write com.apple.desktopservices DSDontWriteNetworkStores -bool truedefaults write com.apple.desktopservices DSDontWriteUSBStores -bool true# Set list view as default for all foldersdefaults write com.apple.finder "SearchRecentsSavedViewStyle" -string "Nlsv"defaults write com.apple.finder "FXPreferredViewStyle" -string "Nlsv"# "disable" Sidebar: Recent Tagsdefaults write com.apple.finder ShowRecentTags -bool false# Restart Finder to apply changeskillall Finder || true'';} -
Install nix
Section titled “Install nix”Terminal window curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install- Insert
Yto install Determinate Nix orNfor NixOS. - Insert
Yto continue.
- Insert
-
Install nix-darwin
Section titled “Install nix-darwin”Terminal window nix run nix-darwin/master#darwin-rebuild -- switch --flake .#{{HOSTNAME_VAR}} -
Terminal window darwin-rebuild switch --flake .#{{HOSTNAME_VAR}}
Uninstall
Section titled “Uninstall”-
Remove unused profiles
Section titled “Remove unused profiles”Terminal window nix-collect-garbage --delete-old -
Uninstall nix-darwin
Section titled “Uninstall nix-darwin”Terminal window nix --extra-experimental-features "nix-command flakes" run nix-darwin#darwin-uninstaller -
Uninstall nix
Section titled “Uninstall nix”Terminal window /nix/nix-installer uninstall -
Remove nix artifacts
Section titled “Remove nix artifacts”
-
Edit system shell configs
Section titled “Edit system shell configs”Edit /etc/zshrc, /etc/bashrc and /etc/bash.bashrc to remove the lines sourcing nix-daemon.sh.
-
Remove shell config backups
Section titled “Remove shell config backups”If these files haven’t been altered since installing Nix you can simply put the backups back in place.
Terminal window sudo mv /etc/zshrc.backup-before-nix /etc/zshrcsudo mv /etc/bashrc.backup-before-nix /etc/bashrcsudo mv /etc/bash.bashrc.backup-before-nix /etc/bash.bashrc -
Stop and remove the Nix daemon services
Section titled “Stop and remove the Nix daemon services”Terminal window sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plistsudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plistsudo launchctl unload /Library/LaunchDaemons/org.nixos.darwin-store.plistsudo rm /Library/LaunchDaemons/org.nixos.darwin-store.plist -
Remove the nixbld group and the _nixbuildN users
Section titled “Remove the nixbld group and the _nixbuildN users”Terminal window sudo dscl . -delete /Groups/nixbldfor u in $(sudo dscl . -list /Users | grep _nixbld); dosudo dscl . -delete /Users/$udone -
Edit fstab
Section titled “Edit fstab”Edit fstab using sudo vifs to remove the line mounting the Nix Store volume on /nix, which looks like UUID=<uuid> /nix apfs rw,noauto,nobrowse,suid,owners or LABEL=Nix\040Store /nix apfs rw,nobrowse. This will prevent automatic mounting of the Nix Store volume.
-
Edit synthetic.conf
Section titled “Edit synthetic.conf”Edit /etc/synthetic.conf to remove the nix line. If this is the only line in the file you can remove it entirely, sudo rm /etc/synthetic.conf. This will prevent the creation of the empty /nix directory to provide a mountpoint for the Nix Store volume.
-
Remove the files Nix added to your system
Section titled “Remove the files Nix added to your system”Terminal window sudo rm -rf /etc/nix ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.cache/nix ~/.local/state/nix /System/Volumes/Data/private/var/root/.nix-defexpr /System/Volumes/Data/private/var/root/.cache/nix /private/var/root/.nix-defexpr /private/var/root/.cache/nix -
Remove the Nix Store volume
Section titled “Remove the Nix Store volume”Terminal window sudo diskutil apfs deleteVolume /nix -
Verify
Section titled “Verify”Look for a “Nix Store” volume in the output of the following command.
Terminal window diskutil list
-
Manual configurations
Section titled “Manual configurations”Defaults that aren’t configurable with nix-darwin.
Notifications
Section titled “Notifications”- Allow notifications when the screen is locked >
false
Desktop & Dock
Section titled “Desktop & Dock”- Default web browser
Lock Screen
Section titled “Lock Screen”- When Switching User > Login window shows >
Name and password
Trackpad
Section titled “Trackpad”- Secondary click >
Click in Bottom Right Corner
Finder sidebar
Section titled “Finder sidebar”Favorites
- Recents
- AirDrop
- Applications
- Desktop
- Documents
- Downloads
- Movies
- Music
- Pictures
- $USER
iCloud
- iCloud Drive
- Shared
Locations
- Device
- Hard disks
- External disks
- CDs, DVDs, and iOS Devices
- Cloud Storage
- Bonjour computers
- Connected servers
Tags
- Recent Tags
View Options
Section titled “View Options”- Always open in list view
- Browse in list view
- Group By:
None - Sort By:
Date Modified
Show Columns:
- Date Modified
- Date Created
- Date Last Opened
- Date Added
- Size
- Kind
- Version
- Comments
- Tags
Misc
- Use relative dates
- Calculate all sizes
- Show icon preview
Troublshooting
Section titled “Troublshooting”Reset finder preferences
Section titled “Reset finder preferences”rm ~/Library/Preferences/com.apple.finder.plistdefaults delete com.apple.finderkillall Findersudo reboot