-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (111 loc) · 4.66 KB
/
Copy pathMakefile
File metadata and controls
130 lines (111 loc) · 4.66 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
# Variables (override these as needed)
HOST ?= $(shell hostname -s)
FLAKE ?= .#$(HOST)
HOME_TARGET ?= .#$(USER)@$(HOST)
SOPS_USER_KEY ?=
SOPS_USER_PUBKEY ?= $(if $(SOPS_USER_KEY),$(SOPS_USER_KEY).pub,)
SOPS_AGE_KEY_CMD ?= nix run nixpkgs#ssh-to-age -- -private-key -i "$(SOPS_USER_KEY)"
EXPERIMENTAL ?= --extra-experimental-features "nix-command flakes"
.PHONY: help install-nix install-nix-darwin darwin-rebuild nixos-rebuild \
home-manager-switch nix-gc flake-update flake-update-homebrew flake-check \
sops-check-key sops-host-recipient sops-user-recipient sops-verify \
sops-edit-system sops-edit-home bootstrap-mac
help:
@echo "Available targets:"
@echo " install-nix - Install the Nix package manager"
@echo " install-nix-darwin - Install nix-darwin using flake $(FLAKE)"
@echo " darwin-rebuild - Rebuild the nix-darwin configuration"
@echo " nixos-rebuild - Rebuild the NixOS configuration"
@echo " home-manager-switch - Switch the Home Manager configuration using flake $(HOME_TARGET)"
@echo " nix-gc - Run Nix garbage collection"
@echo " flake-update - Update flake inputs"
@echo " flake-update-homebrew - Update brew and Homebrew taps together"
@echo " flake-check - Check the flake for issues"
@echo " sops-check-key - Check that SOPS_USER_KEY/SOPS_USER_PUBKEY are readable"
@echo " sops-host-recipient - Print age recipient for this host SSH key"
@echo " sops-user-recipient - Print age recipient for SOPS_USER_PUBKEY"
@echo " sops-verify - Verify all encrypted secrets decrypt with SOPS_USER_KEY"
@echo " sops-edit-system - Edit secrets/$(HOST).yaml"
@echo " sops-edit-home - Edit secrets/$(HOST)/$(USER).yaml"
@echo " bootstrap-mac - Install Nix and nix-darwin sequentially"
install-nix:
@echo "Installing Nix..."
@sudo curl -L https://nixos.org/nix/install | sh -s -- --daemon --yes
@echo "Nix installation complete."
install-nix-darwin:
@echo "Installing nix-darwin..."
@nix run nix-darwin $(EXPERIMENTAL) -- switch --flake $(FLAKE)
@echo "nix-darwin installation complete."
darwin-rebuild:
@echo "Rebuilding darwin configuration..."
@sudo darwin-rebuild switch --flake $(FLAKE)
@echo "Darwin rebuild complete."
nixos-rebuild:
@echo "Rebuilding NixOS configuration..."
@sudo nixos-rebuild switch --flake $(FLAKE)
@echo "NixOS rebuild complete."
home-manager-switch:
@echo "Switching Home Manager configuration..."
@home-manager switch --flake $(HOME_TARGET)
@echo "Home Manager switch complete."
nix-gc:
@echo "Collecting Nix garbage..."
@nix-collect-garbage -d
@echo "Garbage collection complete."
flake-update:
@echo "Updating flake inputs..."
@token=$$(gh auth token 2>/dev/null || true); \
if [ -n "$$token" ]; then \
NIX_CONFIG="access-tokens = github.com=$$token" nix flake update; \
else \
nix flake update; \
fi
@echo "Flake update complete."
flake-update-homebrew:
@echo "Updating Homebrew inputs in lockstep..."
@token=$$(gh auth token 2>/dev/null || true); \
if [ -n "$$token" ]; then \
NIX_CONFIG="access-tokens = github.com=$$token" nix flake update \
brew-src \
nix-homebrew \
homebrew-bundle \
homebrew-core \
homebrew-cask; \
else \
nix flake update \
brew-src \
nix-homebrew \
homebrew-bundle \
homebrew-core \
homebrew-cask; \
fi
@echo "Homebrew flake inputs updated together."
flake-check:
@echo "Checking flake..."
@nix flake check
@echo "Flake check complete."
sops-check-key:
@test -n "$(SOPS_USER_KEY)" || (echo "Set SOPS_USER_KEY to your local SOPS private SSH key path." >&2; exit 1)
@test -n "$(SOPS_USER_PUBKEY)" || (echo "Set SOPS_USER_PUBKEY or use a public key at SOPS_USER_KEY.pub." >&2; exit 1)
@test -r "$(SOPS_USER_KEY)" || (echo "Missing SOPS user key: $(SOPS_USER_KEY)" >&2; exit 1)
@test -r "$(SOPS_USER_PUBKEY)" || (echo "Missing SOPS user public key: $(SOPS_USER_PUBKEY)" >&2; exit 1)
sops-host-recipient:
@nix run nixpkgs#ssh-to-age -- -i /etc/ssh/ssh_host_ed25519_key.pub
sops-user-recipient: sops-check-key
@nix run nixpkgs#ssh-to-age -- -i "$(SOPS_USER_PUBKEY)"
sops-verify: sops-check-key
@set -e; \
found=0; \
for file in secrets/*.yaml secrets/*/*.yaml; do \
[ -e "$$file" ] || continue; \
found=1; \
echo "Checking $$file"; \
SOPS_AGE_KEY_CMD='$(SOPS_AGE_KEY_CMD)' sops -d "$$file" >/dev/null; \
done; \
[ "$$found" -eq 1 ] || echo "No encrypted secrets files found yet."
sops-edit-system: sops-check-key
@SOPS_AGE_KEY_CMD='$(SOPS_AGE_KEY_CMD)' sops secrets/$(HOST).yaml
sops-edit-home: sops-check-key
@mkdir -p secrets/$(HOST)
@SOPS_AGE_KEY_CMD='$(SOPS_AGE_KEY_CMD)' sops secrets/$(HOST)/$(USER).yaml
bootstrap-mac: install-nix install-nix-darwin