Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/nix-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
contents: read
id-token: write
env:
CI_HOSTNAME: ci-${{ matrix.os.name }}
CI_FLAKE_TARGET: ci
runs-on: ${{ matrix.os.name }}
strategy:
fail-fast: false
Expand All @@ -47,7 +47,6 @@ jobs:
use-gha-cache: enabled
- name: Setup
run: |
sed -i '' "s/defaultHostname/${CI_HOSTNAME}/g" flake.nix
sed -i '' "s/defaultSystem/${{matrix.os.arch}}/g" flake.nix
sed -i '' "s/defaultVersion/$(sw_vers --productVersion | cut -d. -f1)/g" flake.nix

Expand All @@ -71,15 +70,15 @@ jobs:
env:
NIX_CONFIG: "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}"
run: |
sudo -E nix run nix-darwin/master#darwin-rebuild --extra-experimental-features "nix-command flakes" -- switch --flake .#${CI_HOSTNAME}
sudo -E nix run nix-darwin/master#darwin-rebuild --extra-experimental-features "nix-command flakes" -- switch --flake .#${CI_FLAKE_TARGET}

- name: Test - Switch
# See https://github.com/actions/runner-images/issues/264
shell: zsh {0}
env:
NIX_CONFIG: "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}"
run: |
sudo -E darwin-rebuild switch --flake .#${CI_HOSTNAME}
sudo -E darwin-rebuild switch --flake .#${CI_FLAKE_TARGET}

# - name: Test - bashrc
# run: bash -c "source ~/.bashrc"
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ssh/known_hosts
ssh/google*
ssh/*Github
secrets
darwin/local-flake-target
rbenv/*/
.DS_Store

Expand All @@ -13,4 +14,4 @@ gitconfig-user

.direnv
.pre-commit-config.yaml
.prettierignore
.prettierignore
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,30 @@ Opinionated `nix-darwin` and Home Manager configuration for bringing a clean mac
cd ~/.dotfiles
```

3. Perform the first system activation with the same command CI runs:
3. Perform the first system activation with the public flake target that matches your machine:

```bash
nix run nix-darwin/master#darwin-rebuild --extra-experimental-features "nix-command flakes" -- switch --flake .
nix run nix-darwin/master#darwin-rebuild --extra-experimental-features "nix-command flakes" -- switch --flake .#darwin-arm64
```

4. For day-to-day updates after the initial activation:
Use `darwin-arm64` for Apple Silicon machines and `darwin-x86_64` for Intel machines.

4. Optionally set a private default target on each machine so the `switch` shell helper can stay host-agnostic:

```bash
cp darwin/local-flake-target.example darwin/local-flake-target
$EDITOR darwin/local-flake-target
```

5. For day-to-day updates after the initial activation:

```bash
darwin-rebuild switch --flake .
switch
```

5. Drop into the development shell whenever you need project tooling (`nixfmt`, `prettier`, git hooks, etc.):
You can also continue to use `darwin-rebuild switch --flake .#darwin-arm64` explicitly.

6. Drop into the development shell whenever you need project tooling (`nixfmt`, `prettier`, git hooks, etc.):

```bash
nix develop
Expand Down Expand Up @@ -60,14 +71,16 @@ bootstrap.sh # Convenience script for bootstrapping fresh machines

## Everyday Commands

- `darwin-rebuild switch --flake .` — Apply configuration changes to the current machine.
- `switch [target]` — Apply configuration changes using a private local default or an explicit public target.
- `darwin-rebuild switch --flake .#darwin-arm64` — Apply the Apple Silicon configuration explicitly.
- `darwin-rebuild switch --flake .#darwin-x86_64` — Apply the Intel configuration explicitly.
- `nix develop` — Enter the dev shell with formatters and pre-commit hooks configured.
- `pre-commit run --all-files` — Lint and format Nix and text assets to match CI.
- `nix flake update` — Refresh inputs and rewrite `flake.lock` when bumping dependencies.

## Validation & Testing

- Run `darwin-rebuild switch --flake .` (or the CI command from Quick Start) after edits to confirm the macOS build succeeds.
- Run `switch` or `darwin-rebuild switch --flake .#<public-target>` after edits to confirm the macOS build succeeds.
- Use `nix flake check` to evaluate Home Manager modules on both `aarch64-darwin` and `x86_64-darwin`.
- Source the interactive shell with `zsh -vc "source ~/.zshrc"` to ensure the login environment stays clean.

Expand Down
6 changes: 3 additions & 3 deletions darwin/homebrew.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
inputs,
lib,
user,
hostname,
osVersion,
platform,
...
Expand All @@ -24,7 +23,9 @@ in
homebrew = {
enable = true;
onActivation = {
autoUpdate = true;
# Avoid Homebrew self-updating on every rebuild while still allowing
# managed formula and cask upgrades during activation.
autoUpdate = false;
upgrade = true;
};
brews = [
Expand Down Expand Up @@ -71,7 +72,6 @@ in
"vagrant"
"virtualbox"
"visual-studio-code"
"zen"
];

# Mac App Store apps
Expand Down
8 changes: 8 additions & 0 deletions darwin/local-flake-target.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copy this file to darwin/local-flake-target on each machine and keep the
# selected target private.
#
# Valid public targets:
# - darwin-arm64
# - darwin-x86_64

darwin-arm64
20 changes: 8 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
mkDarwinSystem =
{
system,
hostname,
osVersion,
username,
}:
Expand Down Expand Up @@ -109,7 +108,6 @@
specialArgs = {
inherit
inputs
hostname
osVersion
platform
system
Expand All @@ -131,7 +129,6 @@
extraSpecialArgs = {
inherit
inputs
hostname
platform
;
user = user;
Expand All @@ -146,31 +143,30 @@
}
];
};
in
{
darwinConfigurations = {
"MSPLAIN-M-CH4Y" = mkDarwinSystem {

publicDarwinConfigurations = {
darwin-arm64 = mkDarwinSystem {
system = "aarch64-darwin";
hostname = "MSPLAIN-M-CH4Y";
osVersion = "26";
username = "msplain";
};

"Mikes-MBP-16" = mkDarwinSystem {
darwin-x86_64 = mkDarwinSystem {
system = "x86_64-darwin";
hostname = "Mikes-MBP-16";
osVersion = "26";
username = "mike";
};

# For CI and testing
"defaultHostname" = mkDarwinSystem {
ci = mkDarwinSystem {
system = "defaultSystem";
hostname = "defaultHostname";
osVersion = "defaultVersion";
username = "runner";
};
};
in
{
darwinConfigurations = publicDarwinConfigurations;

# Import devShells from devshell.nix
inherit (import ./devshell.nix { inherit inputs; }) devShells;
Expand Down
1 change: 0 additions & 1 deletion home/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
user,
system,
config,
hostname,
...
}:
let
Expand Down
1 change: 0 additions & 1 deletion home/git.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
inputs,
pkgs,
hostname,
...
}:
{
Expand Down
29 changes: 27 additions & 2 deletions home/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
High-level
help Show this list
dot, dotfiles cd $HOME/.dotfiles
switch darwin-rebuild switch --flake .
switch [target] darwin-rebuild switch --flake .#<target>
update_flake_from_pr Approve + merge latest successful flake update PR and pull
w windsurf .
c cursor .
Expand Down Expand Up @@ -137,9 +137,34 @@

eval "$(mise activate zsh)"

darwin_flake_target() {
local target="$1"
local repo_dir="''${2:-$HOME/.dotfiles}"
local target_file="$repo_dir/darwin/local-flake-target"

if [[ -n "$target" ]]; then
print -r -- "$target"
return 0
fi

if [[ -f "$target_file" ]]; then
target=$(grep -Ev '^[[:space:]]*(#|$)' "$target_file" | head -n 1)
if [[ -n "$target" ]]; then
print -r -- "$target"
return 0
fi
fi

echo "No default Darwin flake target configured." >&2
echo "Pass a target like 'switch darwin-arm64' or create $target_file." >&2
return 1
}

# Switch to the current flake
switch() {
sudo darwin-rebuild switch --flake .
local target
target=$(darwin_flake_target "$1") || return 1
sudo darwin-rebuild switch --flake ".#''${target}"
}

# Approve + merge latest successful flake update PR and pull locally.
Expand Down
Loading