Last active
February 28, 2026 19:01
-
-
Save tsgautier/7ff22ab87c09ffde31bafba6be188623 to your computer and use it in GitHub Desktop.
Nix-Darwin Bootstrap Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| # --- 1. PRE-FLIGHT: Apple Developer Tools --- | |
| if ! xcode-select -p &>/dev/null; then | |
| echo "Apple Command Line Tools not found. Starting installation..." | |
| xcode-select --install | |
| echo "--------------------------------------------------------" | |
| echo "A macOS dialog has appeared. Please click 'Install'." | |
| echo "Wait for the installation to finish, THEN press ENTER here." | |
| echo "--------------------------------------------------------" | |
| read -r | |
| fi | |
| # --- 2. PRE-FLIGHT: Rosetta 2 (Apple Silicon only) --- | |
| if [[ "$(uname -m)" == "arm64" ]]; then | |
| # Check if Rosetta is already installed by looking for the oahd daemon | |
| if ! pgrep oahd >/dev/null 2>&1; then | |
| echo "Apple Silicon detected. Installing Rosetta 2..." | |
| # Using --agree-to-license for a non-interactive install | |
| sudo softwareupdate --install-rosetta --agree-to-license | |
| else | |
| echo "Rosetta 2 is already installed." | |
| fi | |
| fi | |
| # --- 3. Install Nix (Determinate Systems) --- | |
| if ! command -v nix &> /dev/null; then | |
| curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems | sh -s -- install --no-confirm | |
| if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then | |
| . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' | |
| fi | |
| fi | |
| # --- 4. Use a Nix Ephemeral Shell --- | |
| export NIXPKGS_ALLOW_UNFREE=1 | |
| export SSH_AUTH_SOCK=~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock | |
| # Using your _1password-cli with the -E flag for parser safety | |
| nix-shell -E 'with import <nixpkgs> {}; mkShell { buildInputs = [ git pkgs."_1password-cli" ]; }' --run bash <<EOF | |
| set -e | |
| echo "--- 1PASSWORD CHECK ---" | |
| if [ ! -d "/Applications/1Password.app" ]; then | |
| echo "1Password GUI not found. Opening download page..." | |
| open https://1password.com | |
| echo "Please install 1Password, sign in, and enable the SSH Agent." | |
| echo "Press ENTER when 1Password.app is running and Agent is enabled." | |
| read -r | |
| fi | |
| # --- 5. Clone Dotfiles --- | |
| echo "Cloning dotfiles..." | |
| mkdir -p ~/dotfiles | |
| if [ ! -d "$HOME/dotfiles/.git" ]; then | |
| git clone git@github.com:tsgautier/dotfiles.git ~/dotfiles | |
| else | |
| echo "Dotfiles already cloned, skipping..." | |
| fi | |
| # --- 6. Hand off to nix-darwin --- | |
| cd ~/dotfiles/nix-darwin | |
| echo "Applying nix-darwin configuration..." | |
| # Use HOST=default and point explicitly to the #default flake attribute | |
| sudo HOST=default nix run --extra-experimental-features "nix-command flakes" nix-darwin -- switch --flake .#default | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment