-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
211 lines (165 loc) · 6.86 KB
/
Copy pathMakefile
File metadata and controls
211 lines (165 loc) · 6.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# ABOUTME: Common targets for managing nix flake configurations (home-manager and NixOS)
# ABOUTME: Auto-detects hostname for switch/build targets
# Valid hostnames with configurations
VALID_HOSTS := bluestreak ubuntu generic
# NixOS hosts (hostname -> config name mapping via -wsl suffix removal)
VALID_NIXOS_HOSTS := galvatron-wsl
HOSTNAME := $(shell hostname -s)
USER := sme
# Allow override: make switch HOST=generic
HOST ?= $(HOSTNAME)
FLAKE_TARGET := $(USER)@$(HOST)
# NixOS config name (strips -wsl suffix: galvatron-wsl -> galvatron)
NIXOS_CONFIG := $(subst -wsl,,$(HOST))
# Converge target for this host: nixos-switch for NixOS hosts, switch otherwise
ifeq ($(filter $(HOST),$(VALID_NIXOS_HOSTS)),)
SWITCH_TARGET := switch
else
SWITCH_TARGET := nixos-switch
endif
# Check if host has a home-manager configuration
define check_host
@if ! echo "$(VALID_HOSTS)" | grep -qw "$(HOST)"; then \
echo "Error: No configuration for host '$(HOST)'"; \
echo "Valid hosts: $(VALID_HOSTS)"; \
echo ""; \
echo "To use a specific config: make $(1) HOST=<hostname>"; \
exit 1; \
fi
endef
# Check if host has a NixOS configuration
define check_nixos_host
@if ! echo "$(VALID_NIXOS_HOSTS)" | grep -qw "$(HOST)"; then \
echo "Error: No NixOS configuration for host '$(HOST)'"; \
echo "Valid NixOS hosts: $(VALID_NIXOS_HOSTS)"; \
echo ""; \
echo "To use a specific config: make $(1) HOST=<hostname>"; \
exit 1; \
fi
endef
# Age for generation cleanup (override: make clean-generations AGE=14d)
AGE ?= 30d
# Current system for package builds
SYSTEM := $(shell nix eval --impure --raw --expr 'builtins.currentSystem')
# Dynamic package discovery from pkgs/
# Note: Adds ~0.5s startup overhead due to nix eval at parse time.
# This is a fixed cost (evaluates attribute names only, not package contents).
PACKAGES := $(shell nix eval .#packages.$(SYSTEM) --apply 'builtins.attrNames' --json 2>/dev/null | jq -r '.[]')
.PHONY: switch build check fmt update clean clean-generations news diff zsh-bench help
.PHONY: nixos-switch nixos-build nixos-diff
.PHONY: pkg-list pkg-build-all pkg-bump bump coder-update kiro-update swamp-update $(PACKAGES)
.PHONY: alacritty-sync wezterm-sync claude-sync
## Primary targets
switch: ## Apply home-manager configuration
$(call check_host,$@)
home-manager switch --flake .#$(FLAKE_TARGET)
build: ## Dry-run build to verify changes
$(call check_host,$@)
nix build .#homeConfigurations.$(FLAKE_TARGET).activationPackage --dry-run
diff: ## Show what will change before switching
$(call check_host,$@)
home-manager build --flake .#$(FLAKE_TARGET)
nix store diff-closures ~/.local/state/nix/profiles/home-manager ./result
## NixOS targets
nixos-switch: ## Apply NixOS configuration
$(call check_nixos_host,$@)
sudo nixos-rebuild switch --flake .#$(NIXOS_CONFIG)
nixos-build: ## Dry-run NixOS build to verify changes
$(call check_nixos_host,$@)
nix build .#nixosConfigurations.$(NIXOS_CONFIG).config.system.build.toplevel --dry-run
nixos-diff: ## Show what will change before NixOS switch
$(call check_nixos_host,$@)
nix build .#nixosConfigurations.$(NIXOS_CONFIG).config.system.build.toplevel
nix store diff-closures /run/current-system ./result
## Maintenance
update: ## Update flake inputs
nix flake update
fmt: ## Format nix files with alejandra
alejandra .
check: ## Validate flake
nix flake check
clean: ## Garbage collect old generations
nix-collect-garbage -d
clean-generations: ## Remove old home-manager generations (default: 30d, override: AGE=14d)
nix profile wipe-history --profile ~/.local/state/nix/profiles/home-manager --older-than $(AGE)
news: ## Show home-manager news
$(call check_host,$@)
home-manager news --flake .#$(FLAKE_TARGET)
## Windows/WSL
ALACRITTY_SRC := home/sme/shared/includes/alacritty.toml
ALACRITTY_DST := /mnt/c/Users/sme/AppData/Roaming/alacritty/alacritty.toml
WEZTERM_SRC := home/sme/shared/includes/wezterm.lua
WEZTERM_DST := /mnt/c/Users/sme/.wezterm.lua
alacritty-sync: ## Sync alacritty.toml to Windows AppData
@cp $(ALACRITTY_SRC) $(ALACRITTY_DST)
@echo "Synced alacritty config (auto-reloads)"
wezterm-sync: ## Sync wezterm.lua to Windows home
@cp $(WEZTERM_SRC) $(WEZTERM_DST)
@echo "Synced wezterm config (auto-reloads)"
CLAUDE_SRC := $(HOME)/.claude
CLAUDE_DST := /mnt/c/Users/sme/.claude
claude-sync: ## Sync Claude Code config (CLAUDE.md, settings.json, commands, skills, hooks) to Windows
@cp $(CLAUDE_SRC)/CLAUDE.md $(CLAUDE_DST)/CLAUDE.md
@cp $(CLAUDE_SRC)/settings.json $(CLAUDE_DST)/settings.json
@cp -r $(CLAUDE_SRC)/commands $(CLAUDE_DST)/
@cp -r $(CLAUDE_SRC)/skills $(CLAUDE_DST)/
@cp -r $(CLAUDE_SRC)/hooks $(CLAUDE_DST)/
@echo "Synced Claude Code config to Windows (settings.local.json intentionally excluded)"
## Diagnostics
zsh-bench: ## Measure zsh startup time
hyperfine --warmup 2 'zsh -i -c exit'
## Custom packages (pkgs/)
## Individual package targets are generated dynamically (e.g., make aws-doctor)
pkg-list: ## List available custom packages
@echo "Available packages (build with 'make <name>'):"
@for pkg in $(PACKAGES); do echo " $$pkg"; done
pkg-build-all: ## Build all custom packages
@for pkg in $(PACKAGES); do \
echo "Building $$pkg..."; \
nix build .#$$pkg || exit 1; \
done
@echo "All packages built successfully"
pkg-bump: ## Bump package to latest GitHub release (PKG=name)
ifndef PKG
@echo "Usage: make pkg-bump PKG=<package-name>"
@echo "Run 'make pkg-list' to see available packages"
@exit 1
endif
@./scripts/bump-pkg.sh $(PKG)
coder-update: ## Update coder to latest or specific version (VERSION=x.y.z)
@./scripts/update-coder.sh $(VERSION)
kiro-update: ## Update kiro-cli to latest or specific version (VERSION=x.y.z)
@./scripts/update-kiro.sh $(VERSION)
swamp-update: ## Update swamp to latest or specific version (VERSION=x.y.z)
@./scripts/update-swamp.sh $(VERSION)
bump: ## Bump PKG to latest & converge host (make bump PKG=swamp [VERSION=x.y.z] [CLEAN=<age>])
ifndef PKG
@echo "Usage: make bump PKG=<name> [VERSION=x.y.z] [CLEAN=<age>]"
@echo "Bumps pkgs/<name> via scripts/update-<name>.sh, then runs '$(SWITCH_TARGET)' if it changed."
@exit 1
endif
@test -f scripts/update-$(PKG).sh || { \
echo "Error: no update script for '$(PKG)' (expected scripts/update-$(PKG).sh)"; \
exit 1; \
}
@./scripts/update-$(PKG).sh $(VERSION)
@if git diff HEAD --quiet -- pkgs/$(PKG); then \
echo ">> $(PKG) already current -- skipping $(SWITCH_TARGET)"; \
else \
git add pkgs/$(PKG); \
$(MAKE) $(SWITCH_TARGET); \
fi
ifdef CLEAN
@$(MAKE) clean-generations AGE=$(CLEAN)
@$(MAKE) clean
endif
# Generate a target for each package (e.g., make aws-doctor, make iamlive)
define pkg_target
$(1): ## Build $(1) package
nix build .#$(1)
endef
$(foreach pkg,$(PACKAGES),$(eval $(call pkg_target,$(pkg))))
## Help
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help