A declarative macOS system configuration using nix-darwin, home-manager, and homebrew.
/etc/nix-darwin/
├── flake.nix # Main configuration entry point
├── config/
│ ├── default.nix # Import all configurations
│ ├── home.nix # Home-manager configuration
│ ├── homebrew.nix # Homebrew packages and casks
│ ├── packages.nix # System packages configuration
│ └── system.nix # System preferences and defaults
├── apps/
│ ├── default.nix # Import all app configurations
│ ├── aerospace/
│ │ └── aerospace.flake # Aerospace window manager configuration
│ ├── git/
│ │ └── git.flake # Git configuration
│ └── zsh/
│ └── zsh.flake # ZSH shell configuration
├── scripts/
│ └── fetch-email.sh # Script for 1Password email fetching
└── README.md # This file
- Declarative System Configuration: Define your entire macOS setup in code
- Package Management: Manage packages with Nix and Homebrew
- Dotfile Management: Configure your shell and tools with home-manager
- Reproducible: Easily replicate your setup on a new machine
- 1Password Integration: Securely retrieve secrets from 1Password
- Modular Structure: Easily maintain and extend configurations
- External Scripts: Separation of logic from configuration
- Window Management: Tiling window management with Aerospace
- macOS 12+
- Administrative access
-
Install Nix package manager using Lix (recommended):
curl -sSf -L https://install.lix.systems/lix | sh -s -- install --nix-build-group-id 30000
- Answer
Y
when prompted to install Nix - Answer
Y
when prompted to set up the nix-daemon
- Answer
-
Source the Nix profile:
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
-
Create and set permissions for the nix-darwin directory:
sudo mkdir -p /etc/nix-darwin sudo chown $(id -nu):$(id -ng) /etc/nix-darwin
-
Clone this repository (or create a new one from the template):
# Option 1: Clone this repository git clone https://github.com/dededecline/nixos-config.git /etc/nix-darwin # Option 2: Create a new configuration from template cd /etc/nix-darwin nix flake init -t nix-darwin/nix-darwin-24.11
-
If using Option 2, customize the configuration files to match your needs.
-
Apply the configuration:
nix run nix-darwin/nix-darwin-24.11#darwin-rebuild -- switch
-
After the first install, you can use the simplified command:
darwin-rebuild switch
This configuration uses 1Password to store sensitive information such as your Git email. To set this up:
-
Install 1Password (already included in the configuration)
-
Create an item in 1Password with the title "git-email" and a field called "email"
-
Ensure you're signed in to 1Password CLI:
op signin
Update and rebuild your system with:
darwin-rebuild switch --flake /etc/nix-darwin
Or use the alias defined in the configuration:
update
- Edit
config/packages.nix
to add system-wide packages - Edit
config/homebrew.nix
to add Homebrew packages or casks - Edit
config/home.nix
to add user-specific packages
To add a new application configuration:
- Create a new directory in
apps/
for your application - Create a configuration file (e.g.,
myapp.flake
) - Add it to the imports in
apps/default.nix
Example for a new app configuration:
# apps/newapp/newapp.flake
{ pkgs, user, ... }: {
home-manager.users.${user.username} = { ... }: {
programs.newapp = {
enable = true;
# Configuration options here
};
};
}
User information is centralized in flake.nix
(or config/host.nix if extracted):
user = {
name = "Dani Klein";
username = "daniklein";
githubUsername = "dededecline";
homeDirectory = "/Users/daniklein";
};
System preferences are configured in config/system.nix
.
Shell aliases and configuration are defined in apps/zsh/zsh.flake
.
Git settings are configured in apps/git/git.flake
.
Aerospace window manager settings are configured in apps/aerospace/aerospace.flake
. This includes:
- Keyboard shortcuts for window manipulation
- Gap and padding settings
- Window layouts and workspace configuration
- Application-specific rules
- Integration with sketchybar and borders
If you encounter issues:
-
Check Nix store permissions:
sudo chown -R root:wheel /nix
-
Ensure proper permissions on configuration directory:
sudo chown -R $(id -nu):$(id -ng) /etc/nix-darwin
-
For more help, consult: