-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
1630 lines (1451 loc) · 68.6 KB
/
Copy pathMakefile
File metadata and controls
1630 lines (1451 loc) · 68.6 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
##@ Variables
SHELL := bash
# Include dotagents from submodule but keep the local targets authoritative.
DOTAGENTS_SKIP_HELP := 1
DOTAGENTS_SKIP_SYNC := 1
-include dotagents/Makefile
# Detect architecture and OS
ARCH := $(shell uname -m)
OS := $(shell uname -s)
# Git variables
GIT_REMOTE_ORIGIN_URL := $(shell git config --get remote.origin.url)
GITHUB_REPO_PATH := $(shell echo $(GIT_REMOTE_ORIGIN_URL) | sed -n 's/.*github.com[:/]\(.*\)\.git/\1/p')
GITHUB_REPO_OWNER := $(shell echo $(GITHUB_REPO_PATH) | cut -d'/' -f1)
GITHUB_REPO_NAME := $(shell echo $(GITHUB_REPO_PATH) | cut -d'/' -f2)
GIT_COMMIT_SHA := $(shell git rev-parse --short HEAD)
# Env ironment variables
NIX_ALLOW_UNFREE := NIXPKGS_ALLOW_UNFREE=1
# Docker image names
DOCKER_IMAGE_NAME_BASE := ghcr.io/$(GITHUB_REPO_OWNER)/$(GITHUB_REPO_NAME)
DOCKER_IMAGE_LATEST := $(DOCKER_IMAGE_NAME_BASE):latest
DOCKER_IMAGE_TAGGED := $(DOCKER_IMAGE_NAME_BASE):$(GIT_COMMIT_SHA)
# Nix executable path
NIX_EXEC := $(shell which nix)
# Common cache settings (only applied when user is trusted to avoid warnings)
NIX_SUBSTITUTERS := https://cache.nixos.org https://devenv.cachix.org https://cachix.cachix.org https://hyprland.cachix.org
NIX_TRUSTED_KEYS := cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw= cachix.cachix.org-1:eWNHQldwUO7G2VkjpnjDbWwy4KQ/HNxht7H4SSoMckM= hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=
NIX_CACHIX_CONF := /etc/nix/cachix.conf
# Check if user is trusted (to avoid "ignoring untrusted substituter" warnings)
NIX_USER_TRUSTED := $(shell grep -qE "trusted-users.*=.*(\\*|$(shell whoami))" /etc/nix/nix.conf 2>/dev/null && echo "yes" || echo "no")
NAMED_HOSTS := andor galactica kyber matic pod viper
NIXOS_NAMED_HOSTS := $(filter matic viper,$(NAMED_HOSTS))
ISO_NAMED_HOSTS := $(filter matic viper,$(NAMED_HOSTS))
DMI_SYS_VENDOR ?= $(shell cat /sys/class/dmi/id/sys_vendor 2>/dev/null || true)
DMI_PRODUCT_NAME ?= $(shell cat /sys/class/dmi/id/product_name 2>/dev/null || true)
MACHINE_HOSTNAME ?= $(shell hostname 2>/dev/null || true)
TAILSCALE_DNS_NAME ?= $(shell \
if command -v tailscale >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then \
tailscale status --json 2>/dev/null | jq -r '.Self.DNSName // "" | rtrimstr(".")' 2>/dev/null; \
fi)
# Nix configuration system
NIX_SYSTEM := $(shell if [ "$(OS)" = "Darwin" ] && [ "$(ARCH)" = "arm64" ]; then \
echo "aarch64-darwin"; \
elif [ "$(OS)" = "Darwin" ] && [ "$(ARCH)" = "x86_64" ]; then \
echo "x86_64-darwin"; \
elif [ "$(OS)" = "Linux" ] && [ "$(ARCH)" = "x86_64" ]; then \
echo "x86_64-linux"; \
elif [ "$(OS)" = "Linux" ] && [ "$(ARCH)" = "aarch64" ]; then \
echo "aarch64-linux"; \
else \
echo "unsupported"; \
fi)
NIX_CONFIG_TYPE := $(shell \
if [ "$(OS)" = "Darwin" ]; then \
echo "darwinConfigurations"; \
elif [ "$(OS)" = "Linux" ]; then \
if [ "$$CI" = "true" ] && [ -n "$(NIX_CONFIG_TARGET)" ]; then \
if [ "$(NIX_CONFIG_TARGET)" = "nixos" ]; then \
echo "nixosConfigurations"; \
else \
echo "homeConfigurations"; \
fi; \
elif [ -f /etc/NIXOS ]; then \
echo "nixosConfigurations"; \
else \
echo "homeConfigurations"; \
fi; \
else \
echo "homeConfigurations"; \
fi)
NIX_USERNAME := $(shell \
if [ -n "$$RUNPOD_POD_ID" ]; then \
echo "root"; \
elif [ "$$CI" = "true" ] || [ "$$IN_DOCKER" = "true" ]; then \
echo "runner"; \
else \
echo "$(shell whoami)"; \
fi)
NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh 2>/dev/null || command -v nix >/dev/null 2>&1 || echo "not_found")
NIX_FLAGS := --extra-experimental-features 'flakes nix-command' --no-pure-eval --impure --fallback
# Only add cache options when user is trusted or on Darwin/CI (avoids "ignoring untrusted substituter" warnings)
ifeq ($(OS),Darwin)
NIX_FLAGS += --option substituters "$(NIX_SUBSTITUTERS)" --option trusted-public-keys "$(NIX_TRUSTED_KEYS)"
else ifeq ($(NIX_USER_TRUSTED),yes)
NIX_FLAGS += --option substituters "$(NIX_SUBSTITUTERS)" --option trusted-public-keys "$(NIX_TRUSTED_KEYS)"
else ifdef CI
NIX_FLAGS += --option substituters "$(NIX_SUBSTITUTERS)" --option trusted-public-keys "$(NIX_TRUSTED_KEYS)"
endif
# Machine detection for automatic host mapping
DETECTED_HOST := $(shell \
if [ "$(OS)" = "Darwin" ] && [ "$(shell whoami)" = "shunkakinoki" ] && [ "$(ARCH)" = "arm64" ]; then \
computer_name=$$(scutil --get ComputerName 2>/dev/null || echo ""); \
if echo "$$computer_name" | grep -q "Shun's MacBook M4"; then \
echo "galactica"; \
else \
echo ""; \
fi; \
elif [ "$(OS)" = "Linux" ]; then \
if [ -n "$$RUNPOD_POD_ID" ]; then \
echo "pod"; \
else \
hostname="$(MACHINE_HOSTNAME)"; \
tailscale_dns="$(TAILSCALE_DNS_NAME)"; \
if [ "$$hostname" = "andor" ]; then \
echo "andor"; \
elif [ "$$hostname" = "kyber" ] \
|| [ "$$hostname" = "c2-small-x86-chi-1" ] \
|| [ "$$tailscale_dns" = "kyber.tail950b36.ts.net" ]; then \
echo "kyber"; \
elif [ "$$hostname" = "matic" ] \
|| [ "$$tailscale_dns" = "matic.tail950b36.ts.net" ]; then \
echo "matic"; \
elif [ "$(DMI_SYS_VENDOR)" = "Framework" ] \
&& echo "$(DMI_PRODUCT_NAME)" | grep -q "Laptop 13.*AMD Ryzen AI 300"; then \
echo "matic"; \
else \
echo ""; \
fi; \
fi; \
else \
echo ""; \
fi)
# User's home directory
HOME_DIR := $(shell echo $$HOME)
CONFIG_DIR := $(HOME_DIR)/.config
# Darwin-rebuild path
DARWIN_REBUILD := $(shell command -v darwin-rebuild 2>/dev/null || echo "./result/sw/bin/darwin-rebuild")
# Sudo path (NixOS uses /run/wrappers/bin/sudo)
SUDO := $(shell \
if [ -x /run/wrappers/bin/sudo ]; then \
echo "/run/wrappers/bin/sudo"; \
elif command -v sudo >/dev/null 2>&1; then \
echo "sudo"; \
elif [ -x /usr/bin/sudo ]; then \
echo "/usr/bin/sudo"; \
else \
echo "sudo"; \
fi)
##@ Help
# Default target
.PHONY: default
default: help ## Default target (shows help).
# ====================================================================================
# HELP
# ====================================================================================
.PHONY: help
help: ## Show this help message.
@echo "Usage: make <target>"
@echo
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_%-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
##@ General
.PHONY: install
install: setup git-submodule-sync nix-build nix-switch shell-install ## Set up full environment (setup, flake-update, build, switch, shell-install).
.PHONY: build
build: nix-build ## Build Nix configuration.
.PHONY: check
check: ## Run all validation checks (nix, format, lua).
@echo "🔍 Running all validation checks..."
@$(MAKE) nix-flake-check
@$(MAKE) nix-format-check
@$(MAKE) nix-lint
@$(MAKE) lua-check
@echo "✅ All checks passed"
.PHONY: flake-check
flake-check: nix-flake-check ## Check Nix flake configuration (alias for nix-flake-check).
.PHONY: format
format: nix-format ## Format Nix files (alias for nix-format).
.PHONY: setup
setup: nix-setup ## Basic Nix setup (alias for nix-setup).
.PHONY: setup-dev
setup-dev: nix-setup git-submodule-sync shell-install ## Set up local development environment (Nix + submodules + shell).
.PHONY: nvim-plugins-install
nvim-plugins-install: ## Download/build missing Neovim native plugin binaries (fff.nvim, telescope-fzf-native, vscode-diff).
@PACK_DIR="$$HOME/.local/share/nvim/site/pack"; \
\
FFF_DIR=""; \
for d in "$$PACK_DIR"/*/opt/fff.nvim "$$PACK_DIR"/*/start/fff.nvim; do \
if [ -d "$$d" ]; then FFF_DIR="$$d"; break; fi; \
done; \
if [ -n "$$FFF_DIR" ]; then \
_ARCH=$$(uname -m); \
case "$$_ARCH" in arm64) _ARCH="aarch64" ;; amd64) _ARCH="x86_64" ;; esac; \
case "$$(uname -s)" in \
Darwin) _LIB_EXT="dylib"; _TRIPLE="$${_ARCH}-apple-darwin" ;; \
Linux) \
_LDD=$$(ldd --version 2>&1 || echo ""); \
if echo "$$_LDD" | grep -q musl; then _TRIPLE="$${_ARCH}-unknown-linux-musl"; else _TRIPLE="$${_ARCH}-unknown-linux-gnu"; fi; \
_LIB_EXT="so" ;; \
*) _LIB_EXT=""; _TRIPLE=""; echo "fff.nvim: unsupported platform, skipping download" ;; \
esac; \
if [ -n "$$_LIB_EXT" ]; then \
FFF_BINARY="$$FFF_DIR/target/libfff_nvim.$$_LIB_EXT"; \
if [ ! -f "$$FFF_BINARY" ]; then \
echo "Downloading fff.nvim native binary..."; \
FFF_VERSION=$$(git -C "$$FFF_DIR" rev-parse --short HEAD 2>/dev/null || echo ""); \
if [ -n "$$FFF_VERSION" ]; then \
mkdir -p "$$FFF_DIR/target"; \
echo "Fetching https://github.com/dmtrKovalenko/fff.nvim/releases/download/$$FFF_VERSION/$${_TRIPLE}.$${_LIB_EXT}"; \
curl --fail --location --silent --show-error \
-o "$$FFF_BINARY" \
"https://github.com/dmtrKovalenko/fff.nvim/releases/download/$$FFF_VERSION/$${_TRIPLE}.$${_LIB_EXT}" \
&& echo "fff.nvim binary downloaded successfully" \
|| echo "fff.nvim binary download failed"; \
else \
echo "fff.nvim: could not determine version, skipping"; \
fi; \
else \
echo "fff.nvim binary already present"; \
fi; \
fi; \
else \
echo "fff.nvim plugin directory not found, skipping"; \
fi
.PHONY: switch
switch: nix-switch services nvim-plugins-install dotagents-switch-sync ## Apply Nix config, refresh services/plugins, and refresh agent daemons.
@$(MAKE) refresh
.PHONY: refresh
refresh: refresh-codex-daemon refresh-claude-daemon ## Refresh the Codex and Claude daemons.
.PHONY: refresh-codex-daemon
refresh-codex-daemon: ## Restart the managed Codex app-server daemon on Kyber.
@set -euo pipefail; \
if [ "$(DETECTED_HOST)" != "kyber" ]; then \
echo "⏭️ Codex daemon refresh skipped (Kyber only)"; \
exit 0; \
fi; \
CODEX_BIN="$$(command -v codex || true)"; \
if [ -z "$$CODEX_BIN" ]; then \
echo "❌ Codex is not installed"; \
exit 1; \
fi; \
echo "🔄 Refreshing the Kyber Codex app-server daemon..."; \
"$$CODEX_BIN" app-server daemon restart; \
"$$CODEX_BIN" app-server daemon version; \
echo "✅ Kyber Codex app-server daemon refreshed"
.PHONY: refresh-claude-daemon
refresh-claude-daemon: ## Respawn Claude background sessions on the current binary on Kyber.
@set -euo pipefail; \
if [ "$(DETECTED_HOST)" != "kyber" ]; then \
echo "⏭️ Claude daemon refresh skipped (Kyber only)"; \
exit 0; \
fi; \
CLAUDE_BIN="$$(command -v claude || true)"; \
if [ -z "$$CLAUDE_BIN" ]; then \
echo "❌ Claude is not installed"; \
exit 1; \
fi; \
echo "🔄 Refreshing Kyber Claude background sessions..."; \
"$$CLAUDE_BIN" respawn --all; \
"$$CLAUDE_BIN" --version; \
echo "✅ Kyber Claude background sessions refreshed"
.PHONY: clean
clean: ## Clean up Nix generations older than 30 days and garbage collect.
@echo "🧹 Cleaning up old generations and garbage collecting..."
@$(SUDO) nix-collect-garbage --delete-older-than 30d
@nix store optimise
@echo "✅ Cleanup complete"
.PHONY: clean-all
clean-all: ## Delete ALL old Nix generations and garbage collect (nuclear).
@echo "🧹 Removing all old generations..."
@$(SUDO) nix-collect-garbage -d
@nix store optimise
@echo "✅ Full cleanup complete"
.PHONY: reset
reset: ## Reset git status to clean (restore all changes and reinitialize submodules).
@echo "🔄 Resetting git status to clean..."
@git reset --hard HEAD
@git submodule foreach --recursive 'git reset --hard HEAD && git clean -fd'
@git submodule sync --recursive
@git submodule update --init --recursive --force
@echo "✅ Git status reset to clean"
.PHONY: services
services: ## Restart platform-specific services (launchd on macOS, systemd on Linux).
@if [ "$(OS)" = "Darwin" ]; then \
$(MAKE) launchctl; \
elif [ "$(OS)" = "Linux" ]; then \
$(MAKE) systemctl; \
fi
.PHONY: test
test: neovim-test nix-test shell-test python-test shell-inline-check ## Run all tests (neovim + nix + shell + python + shell-inline-check).
##@ Dev
.PHONY: dev
dev: nix-develop ## Enter the Nix dev shell (alias for nix-develop).
.PHONY: nix-develop
nix-develop: ## Enter the Nix development shell.
DEVENV_ROOT=$(CURDIR) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) develop $(NIX_FLAGS)
.PHONY: devenv-cli
devenv-cli: ## Build the packaged devenv CLI binary.
@echo "📦 Building packaged devenv CLI..."
@$(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#devenv-cli $(NIX_FLAGS) --show-trace
@echo "✅ devenv CLI available in ./result/bin/devenv"
##@ Upgrade
.PHONY: upgrade
upgrade: sync update
.PHONY: upgrade-dev
upgrade-dev: ## Upgrade inside the Nix dev shell (mirrors CI).
@echo "🔄 Running upgrade inside the Nix dev shell..."
@DEVENV_ROOT=$(CURDIR) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) develop $(NIX_FLAGS) .# --command $(MAKE) upgrade
##@ Sync
.PHONY: sync
sync: dotagents-sync codex-security-sync rtk-rewrite-sync ## Sync all components (dotagents, Codex security patterns, rtk-rewrite.sh).
.PHONY: dotagents-sync
dotagents-sync: dotagents-prepare ## Sync dotagents (commands, skills, MCP configuration).
@if [ "$$CI" = "true" ]; then \
echo "⏭️ Skipping external dotagents skill installation in CI"; \
$(MAKE) -C dotagents DOTAGENTS_SKIP_SYNC=1 ruler-prepare commands-sync skills-sync mcp-sync ruler-dotdirs-sync; \
else \
$(MAKE) -C dotagents DOTAGENTS_SKIP_SYNC= sync; \
fi
.PHONY: dotagents-prepare
dotagents-prepare: ## Initialize the dotagents submodule when needed.
@if [ ! -f dotagents/Makefile ]; then \
echo "🔁 Initializing dotagents submodule..."; \
git submodule update --init dotagents; \
fi
@if [ ! -f dotagents/Makefile ]; then \
echo "❌ dotagents submodule is unavailable"; \
exit 1; \
fi
.PHONY: dotagents-switch-sync
dotagents-switch-sync: dotagents-prepare ## Sync checked-in dotagents content during switch.
@echo "🔄 Syncing checked-in dotagents content..."
@$(MAKE) -C dotagents DOTAGENTS_SKIP_SYNC=1 ruler-prepare commands-sync skills-sync mcp-sync ruler-dotdirs-sync
.PHONY: codex-security-sync
codex-security-sync: ## Sync Codex security deny patterns from Claude settings.
@echo "🔒 Syncing Codex security deny patterns..."
@./scripts/sync-codex-security.sh
@echo "✅ Codex security patterns synced"
.PHONY: rtk-rewrite-sync
rtk-rewrite-sync: ## Sync rtk-rewrite.sh from upstream rtk repo.
@echo "🔄 Syncing rtk-rewrite.sh from upstream..."
@./scripts/sync-rtk-rewrite.sh
@echo "✅ rtk-rewrite.sh synced"
##@ Update
.PHONY: update
update: neovim-update gitalias-update llm-update moshi-update overlays-update ## Update Nix flake, overlays, Neovim plugins, LLM configs, gitalias, moshi hooks, and bun deps
.PHONY: update-lock
update-lock: nix-flake-update bun-update cargo-update uv-update ## Update lock files for Nix flake, bun, and Cargo.
.PHONY: bun-update
bun-update: ## Update bun dependencies to latest and regenerate lock file.
@echo "📦 Updating bun dependencies..."
@bun update --latest --recursive
@git checkout bun.lock
@bun install
@echo "✅ bun dependencies updated"
.PHONY: cargo-update
cargo-update: ## Update Rust dependencies to latest and regenerate lock file.
@echo "🦀 Updating Cargo dependencies..."
@cargo +nightly update --breaking -Z unstable-options
@echo "✅ Cargo dependencies updated"
.PHONY: gitalias-update
gitalias-update: ## Download latest gitalias.txt from upstream.
@echo "📥 Updating gitalias.txt..."
@./scripts/update-gitalias.sh
@echo "✅ gitalias.txt updated"
.PHONY: moshi-update
moshi-update: ## Sync moshi-hook generated configs from live to dotfiles.
@if command -v moshi-hook >/dev/null 2>&1; then \
echo "📥 Updating moshi-hook configs..."; \
./scripts/update-moshi-hooks.sh; \
echo "✅ moshi-hook configs updated"; \
else \
echo "⏭️ moshi-hook not found, skipping"; \
fi
.PHONY: llm-update
llm-update: ## Regenerate tool configs from models.json.
@echo "🤖 Updating LLM tool configs..."
@./scripts/llm-update.sh
@echo "✅ LLM configs updated"
.PHONY: overlays-update
overlays-update: ## Upgrade all custom overlays to latest versions (CI only).
@if [ "$$CI" != "true" ]; then \
echo "⏭️ Skipping overlay upgrade outside CI"; \
elif [ "$$IN_DOCKER" = "true" ]; then \
echo "⏭️ Skipping overlay upgrade in Docker"; \
else \
echo "🔄 Upgrading custom overlays..."; \
./scripts/upgrade-overlays.sh all; \
fi
.PHONY: uv-update
uv-update: ## Update uv tool versions in pyproject.toml to latest.
@echo "🐍 Updating uv dependencies..."
@tomlq -r '.["dependency-groups"].tools[]' pyproject.toml | while read -r pkg; do \
name=$${pkg%%[><=!]*}; \
latest=$$(uv pip compile --no-deps - <<< "$$name" 2>/dev/null | grep "^$$name==" | sed "s/$$name==//"); \
if [ -n "$$latest" ]; then \
sed -i '' "s|\"$$name>=.*\"|\"$$name>=$$latest\"|" pyproject.toml; \
echo " $$name -> $$latest"; \
fi; \
done
@echo "✅ uv dependencies updated"
##@ Nix Setup
.PHONY: nix-setup
nix-setup: nix-install nix-check nix-connect nix-trust ## Set up Nix environment (install, check, connect, trust caches).
.PHONY: nix-connect
nix-connect: ## Ensure Nix daemon is running.
@echo "🔌 Ensuring Nix daemon is running for $(NIX_CONFIG_TYPE) on $(OS) $(ARCH) for USER=$(NIX_USERNAME)"
@if [ "$(OS)" = "Darwin" ]; then \
if nix store info >/dev/null 2>&1; then \
echo "✅ Nix daemon is already reachable. Skipping restart."; \
elif [ -f /Library/LaunchDaemons/systems.determinate.nix-daemon.plist ]; then \
$(SUDO) launchctl bootout system/systems.determinate.nix-daemon 2>/dev/null || true; \
$(SUDO) launchctl bootstrap system /Library/LaunchDaemons/systems.determinate.nix-daemon.plist; \
elif [ -f /Library/LaunchDaemons/org.nixos.nix-daemon.plist ]; then \
$(SUDO) launchctl bootout system/org.nixos.nix-daemon 2>/dev/null || true; \
$(SUDO) launchctl bootstrap system /Library/LaunchDaemons/org.nixos.nix-daemon.plist; \
else \
echo "❌ No Nix daemon plist found"; exit 1; \
fi; \
elif [ "$(OS)" = "Linux" ]; then \
if [ "$$CI" = "true" ] || [ "$$IN_DOCKER" = "true" ] || [ "$$AUTOMATED_UPDATE" = "true" ]; then \
echo "🏃♂️ Nix daemon management (e.g., systemctl) is skipped in CI/Docker/automated environments."; \
if [ "$$IN_DOCKER" = "true" ]; then \
echo "ℹ️ Docker environment is using a single-user Nix installation (no separate daemon)."; \
fi; \
if [ "$$AUTOMATED_UPDATE" = "true" ]; then \
echo "ℹ️ Running in automated update mode - assuming nix-daemon is already running."; \
fi; \
else \
if [ -d /run/systemd/system ] && [ -S /run/systemd/private ]; then \
if systemctl is-active --quiet nix-daemon.service; then \
echo "🐧 nix-daemon.service is already running. Skipping restart."; \
else \
echo "🐧 nix-daemon.service not running. Attempting to start..."; \
$(SUDO) systemctl start nix-daemon.service; \
fi; \
else \
echo "🏃♂️ systemd not detected as PID 1 or not fully operational. Nix daemon management via systemctl is skipped."; \
echo "ℹ️ This environment might be using a single-user Nix installation, require manual daemon setup, or be inside a container without full systemd."; \
fi; \
fi; \
else \
echo "❌ Unsupported OS: $(OS)"; \
exit 1; \
fi
@echo "⏳ Waiting for daemon to initialize..."
@sleep 3
@echo "✅ Nix daemon should now be active!"
.PHONY: nix-trust
nix-trust: ## Ensure current user is trusted by the Nix daemon.
@if [ "$(OS)" = "Linux" ] && [ "$(NIX_USER_TRUSTED)" = "no" ] && [ "$$CI" != "true" ] && [ "$$IN_DOCKER" != "true" ]; then \
echo "🔐 Adding $(NIX_USERNAME) to trusted-users in /etc/nix/nix.conf"; \
if grep -q '^trusted-users' /etc/nix/nix.conf 2>/dev/null; then \
$(SUDO) sed -i 's/^trusted-users.*/trusted-users = root $(NIX_USERNAME)/' /etc/nix/nix.conf; \
else \
echo "trusted-users = root $(NIX_USERNAME)" | $(SUDO) tee -a /etc/nix/nix.conf > /dev/null; \
fi; \
$(SUDO) systemctl restart nix-daemon.service; \
echo "✅ $(NIX_USERNAME) is now a trusted Nix user"; \
fi
.PHONY: nix-check
nix-check: ## Verify Nix environment setup.
@echo "🔍 Verifying Nix environment setup for $(NIX_CONFIG_TYPE) on $(OS) $(ARCH) for USER=$(NIX_USERNAME)"
@if [ "$(NIX_ENV)" = "not_found" ]; then \
echo "❌ Nix environment not found. Please ensure Nix is installed and run:"; \
exit 1; \
fi
@echo "✅ Nix environment found!"
.PHONY: nix-install
nix-install: ## Install Nix if not already installed.
@if [ "$(NIX_ENV)" = "not_found" ]; then \
echo "🚀 Installing Determinate Nix environment for $(NIX_CONFIG_TYPE) on $(OS) $(ARCH) for USER=$(NIX_USERNAME)"; \
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --no-confirm; \
fi
@echo "✅ Nix environment installed!"
.PHONY: nix-relocate-store
nix-relocate-store: ## Relocate the Nix store to /mnt (CI-only, Linux runners).
@if [ "$(OS)" != "Linux" ]; then \
echo "🏃♂️ Nix store relocation is Linux-only. Skipping on $(OS)."; \
elif [ "$$CI" != "true" ]; then \
echo "🏃♂️ Nix store relocation only runs in CI. Skipping."; \
elif ! mountpoint -q /mnt; then \
echo "ℹ️ /mnt is not a separate mount. Leaving the Nix store on /."; \
elif mountpoint -q /nix; then \
echo "✅ /nix is already a separate mount. Skipping."; \
elif [ -d /nix ] && [ -n "$$(ls -A /nix 2>/dev/null)" ]; then \
echo "ℹ️ /nix already exists and is not empty. Leaving it alone."; \
else \
echo "💾 Relocating the Nix store to /mnt/nix..."; \
$(SUDO) mkdir -p /mnt/nix /nix; \
$(SUDO) mount --bind /mnt/nix /nix; \
df -h /nix; \
echo "✅ Nix store relocated to /mnt/nix"; \
fi
##@ Nix
.PHONY: nix-update
nix-update: nix-connect nix-daemon-update nix-flake-update ## Upgrade Nix flake, build, and switch.
.PHONY: nix-backup
nix-backup: ## Backup configuration files.
@echo "🗄️ Backing up configuration files for $(NIX_CONFIG_TYPE) on $(OS) $(ARCH) for USER=$(NIX_USERNAME)"
@backup_dir="$$HOME/.config/backups/$(shell date +%Y%m%d_%H%M%S)"; \
mkdir -p "$$backup_dir"; \
if [ -d "$$HOME/.config" ]; then \
cp -R "$$HOME/.config" "$$backup_dir/" 2>/dev/null || true; \
echo "✅ Backup created at $$backup_dir"; \
fi
.PHONY: nix-build
nix-build: nix-connect nix-trust ## Build Nix configuration.
@echo "🏗️ Building Nix configuration for $(NIX_CONFIG_TYPE) on $(OS) $(ARCH) for USER=$(NIX_USERNAME)"
@if [ "$$CI" = "true" ] || [ "$$IN_DOCKER" = "true" ]; then \
echo "🤖 Running in CI/Docker environment"; \
if [ "$(OS)" = "Darwin" ]; then \
if [ -n "$(HOST)" ]; then \
case " $(NIXOS_NAMED_HOSTS) " in \
*" $(HOST) "*) \
echo "Building named NixOS host: $(HOST)"; \
HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#nixosConfigurations.$(HOST).config.system.build.toplevel $(NIX_FLAGS) --impure --no-update-lock-file --show-trace; \
;; \
*) \
echo "Building named Darwin host: $(HOST)"; \
HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#darwinConfigurations.$(HOST).system $(NIX_FLAGS) --impure --no-update-lock-file --show-trace; \
;; \
esac; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#darwinConfigurations.$(DETECTED_HOST).system $(NIX_FLAGS) --impure --no-update-lock-file --show-trace; \
else \
HOST=runner HOSTNAME=runner $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#$(NIX_CONFIG_TYPE).runner.system $(NIX_FLAGS) --impure --no-update-lock-file --show-trace; \
fi; \
elif [ "$(NIX_CONFIG_TYPE)" = "nixosConfigurations" ]; then \
if [ -n "$(HOST)" ]; then \
echo "Building named NixOS host: $(HOST)"; \
$(SUDO) env HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(HOST) --impure; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
$(SUDO) env HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(DETECTED_HOST) --impure; \
else \
HOST=runner HOSTNAME=runner $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#nixosConfigurations.runner.config.system.build.toplevel $(NIX_FLAGS) --impure --no-update-lock-file --show-trace; \
fi; \
elif [ "$(NIX_CONFIG_TYPE)" = "homeConfigurations" ]; then \
if [ -n "$(HOST)" ]; then \
echo "Building named home config: $(HOST)"; \
HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#homeConfigurations.$(HOST).activationPackage $(NIX_FLAGS) --impure --no-update-lock-file --show-trace; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#homeConfigurations.$(DETECTED_HOST).activationPackage $(NIX_FLAGS) --impure --no-update-lock-file --show-trace; \
else \
HOST=$(NIX_SYSTEM) HOSTNAME=$(NIX_SYSTEM) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#$(NIX_CONFIG_TYPE)."$(NIX_USERNAME)@$(NIX_SYSTEM)".activationPackage $(NIX_FLAGS) --impure --no-update-lock-file --show-trace; \
fi; \
else \
echo "Unsupported OS $(OS) for non-CI build"; \
exit 1; \
fi; \
else \
if [ "$(NIX_SYSTEM)" = "unsupported" ]; then \
echo "❌ Unsupported system architecture: $(OS) $(ARCH)"; \
exit 1; \
elif [ "$(OS)" = "Darwin" ]; then \
if [ -n "$(HOST)" ]; then \
case " $(NIXOS_NAMED_HOSTS) " in \
*" $(HOST) "*) \
echo "Building named NixOS host: $(HOST)"; \
HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#nixosConfigurations.$(HOST).config.system.build.toplevel $(NIX_FLAGS) --impure --show-trace; \
;; \
*) \
echo "Building named Darwin host: $(HOST)"; \
HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#darwinConfigurations.$(HOST).system $(NIX_FLAGS) --impure --show-trace; \
;; \
esac; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#darwinConfigurations.$(DETECTED_HOST).system $(NIX_FLAGS) --impure --show-trace; \
else \
HOST=$(NIX_SYSTEM) HOSTNAME=$(NIX_SYSTEM) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#$(NIX_CONFIG_TYPE).$(NIX_SYSTEM).system $(NIX_FLAGS) --impure --show-trace; \
fi; \
elif [ "$(NIX_CONFIG_TYPE)" = "nixosConfigurations" ]; then \
if [ -n "$(HOST)" ]; then \
echo "Building named host: $(HOST)"; \
$(SUDO) env HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(HOST) --impure; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
$(SUDO) env HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(DETECTED_HOST) --impure; \
else \
$(SUDO) env HOST=$(NIX_SYSTEM) HOSTNAME=$(NIX_SYSTEM) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(NIX_SYSTEM) --impure; \
fi; \
elif [ "$(NIX_CONFIG_TYPE)" = "homeConfigurations" ]; then \
if [ -n "$(HOST)" ]; then \
echo "Building named home config: $(HOST)"; \
HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#homeConfigurations.$(HOST).activationPackage $(NIX_FLAGS) --impure --show-trace; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#homeConfigurations.$(DETECTED_HOST).activationPackage $(NIX_FLAGS) --impure --show-trace; \
else \
HOST=$(NIX_SYSTEM) HOSTNAME=$(NIX_SYSTEM) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#$(NIX_CONFIG_TYPE)."$(NIX_USERNAME)@$(NIX_SYSTEM)".activationPackage $(NIX_FLAGS) --impure --show-trace; \
fi; \
else \
echo "Unsupported OS $(OS) for non-CI build"; \
exit 1; \
fi; \
fi
@echo "✅ Nix configuration built successfully!"
.PHONY: nix-daemon-update
nix-daemon-update: ## Upgrade Determinate Nix daemon to latest version.
@if [ "$$CI" = "true" ] || [ "$$IN_DOCKER" = "true" ]; then \
echo "⏭️ Skipping determinate-nixd upgrade in CI"; \
else \
echo "⬆️ Upgrading Determinate Nix daemon..."; \
$(SUDO) determinate-nixd upgrade || true; \
fi
.PHONY: nix-flake-check
nix-flake-check: ## Check Nix flake configuration.
@echo "🔍 Checking Nix flake configuration..."
@if [ "$(OS)" = "Darwin" ]; then \
$(NIX_ALLOW_UNFREE) $(NIX_EXEC) flake check --all-systems --impure $(NIX_FLAGS); \
else \
$(NIX_ALLOW_UNFREE) $(NIX_EXEC) flake check --system $(NIX_SYSTEM) --impure $(NIX_FLAGS); \
fi
@echo "✅ Nix flake check completed successfully"
.PHONY: nix-flake-update
nix-flake-update: nix-connect ## Update flake.lock file.
@echo "♻️ Refreshing flake.lock file..."
@if [ "$$CI" = "true" ] || [ "$$IN_DOCKER" = "true" ] || [ "$$AUTOMATED_UPDATE" = "true" ]; then \
echo "Bypassing flake update in CI/Docker/automated update"; \
else \
$(NIX_EXEC) flake update $(NIX_FLAGS); \
fi
@echo "✅ flake.lock updated!"
.PHONY: nix-format
nix-format: nix-format-clear-cache ## Format Nix files.
@echo "🧹 Formatting Nix files..."
@if $(NIX_EXEC) fmt -- --clear-cache; then \
:; \
else \
nixfmt_bin=$$(command -v nixfmt 2>/dev/null || true); \
if [ -z "$$nixfmt_bin" ]; then \
set -- /nix/store/*-nixfmt-*/bin/nixfmt; \
if [ -x "$$1" ]; then \
nixfmt_bin=$$1; \
fi; \
fi; \
if [ -z "$$nixfmt_bin" ]; then \
echo "❌ nix fmt failed and no local nixfmt fallback is available"; \
exit 1; \
fi; \
echo "⚠️ nix fmt unavailable; falling back to $$nixfmt_bin"; \
git ls-files -z '*.nix' | xargs -0 -r "$$nixfmt_bin"; \
fi
@echo "✅ Formatting complete"
.PHONY: nix-format-clear-cache
nix-format-clear-cache: ## Clear Nix format cache.
@echo "🧹 Clearing Nix cache..."
@if $(NIX_EXEC) fmt -- --clear-cache >/dev/null 2>&1; then \
echo "✅ Cache cleared"; \
else \
echo "⚠️ nix fmt cache clear unavailable; continuing without it"; \
fi
.PHONY: nix-format-check
nix-format-check: ## Check Nix file formatting.
@echo "🔍 Checking Nix file formatting..."
@$(NIX_EXEC) fmt -- --clear-cache --fail-on-change
@echo "✅ All Nix files are properly formatted"
.PHONY: nix-lint
nix-lint: ## Lint Nix files with statix from the flake/dev shell.
@echo "🔍 Linting Nix files with statix..."
@DEVENV_ROOT=$(CURDIR) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) develop $(NIX_FLAGS) .# --command statix check .
@echo "🔍 Checking for dead Nix code with deadnix..."
@DEVENV_ROOT=$(CURDIR) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) develop $(NIX_FLAGS) .# --command deadnix .
@echo "✅ All Nix files pass lint checks"
.PHONY: nix-switch
nix-switch: ## Activate Nix configuration.
@echo "🔧 Activating Nix configuration for $(NIX_CONFIG_TYPE) on $(OS) $(ARCH) for USER=$(NIX_USERNAME)"
@if [ "$$CI" = "true" ] || [ "$$IN_DOCKER" = "true" ]; then \
if [ "$(OS)" = "Darwin" ]; then \
$(SUDO) env CI="$$CI" IN_DOCKER="$$IN_DOCKER" HOST=runner HOSTNAME=runner $(NIX_ALLOW_UNFREE) $(DARWIN_REBUILD) switch --flake .#runner --impure --no-update-lock-file; \
elif [ "$(NIX_CONFIG_TYPE)" = "nixosConfigurations" ]; then \
if [ -n "$(HOST)" ]; then \
echo "Switching named host: $(HOST)"; \
$(SUDO) env HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(HOST) --no-update-lock-file || exit 0; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
$(SUDO) env HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(DETECTED_HOST) --no-update-lock-file || exit 0; \
else \
echo "⏭️ NixOS switch skipped in CI as the runner is not a NixOS system"; \
$(SUDO) env HOST=runner HOSTNAME=runner $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#runner --no-update-lock-file || exit 0; \
fi; \
elif [ "$(NIX_CONFIG_TYPE)" = "homeConfigurations" ]; then \
if [ "$$SKIP_HOME_MANAGER_SWITCH" = "true" ]; then \
echo "⏭️ Home-manager switch skipped (SKIP_HOME_MANAGER_SWITCH=true)"; \
elif [ -n "$(HOST)" ]; then \
echo "Switching named home config: $(HOST)"; \
HOST=$(HOST) HOSTNAME=$(HOST) USER=$(NIX_USERNAME) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure .#homeConfigurations.$(HOST).activationPackage; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) USER=$(NIX_USERNAME) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure .#homeConfigurations.$(DETECTED_HOST).activationPackage; \
else \
HOST=$(NIX_SYSTEM) HOSTNAME=$(NIX_SYSTEM) USER=$(NIX_USERNAME) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure .#$(NIX_CONFIG_TYPE)."$(NIX_USERNAME)@$(NIX_SYSTEM)".activationPackage; \
fi; \
else \
echo "Unsupported OS $(OS) for non-CI switch"; \
exit 1; \
fi; \
else \
if [ "$(NIX_SYSTEM)" = "unsupported" ]; then \
echo "❌ Unsupported system architecture: $(OS) $(ARCH)"; \
exit 1; \
elif [ "$(OS)" = "Darwin" ]; then \
if [ -n "$(HOST)" ]; then \
echo "Switching named host: $(HOST)"; \
$(SUDO) env HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(DARWIN_REBUILD) switch --flake .#$(HOST) --impure; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
$(SUDO) env HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) $(NIX_ALLOW_UNFREE) $(DARWIN_REBUILD) switch --flake .#$(DETECTED_HOST) --impure; \
else \
$(SUDO) env HOST=$(NIX_SYSTEM) HOSTNAME=$(NIX_SYSTEM) $(NIX_ALLOW_UNFREE) $(DARWIN_REBUILD) switch --flake .#$(NIX_SYSTEM) --impure; \
fi; \
elif [ "$(NIX_CONFIG_TYPE)" = "nixosConfigurations" ]; then \
if [ -n "$(HOST)" ]; then \
echo "Switching named host: $(HOST)"; \
$(SUDO) env HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- switch --flake .#$(HOST) --impure; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
$(SUDO) env HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- switch --flake .#$(DETECTED_HOST) --impure; \
else \
$(SUDO) env HOST=$(NIX_SYSTEM) HOSTNAME=$(NIX_SYSTEM) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- switch --flake .#$(NIX_SYSTEM) --impure; \
fi; \
elif [ "$(NIX_CONFIG_TYPE)" = "homeConfigurations" ]; then \
if [ -n "$(HOST)" ]; then \
echo "Switching named home config: $(HOST)"; \
HOST=$(HOST) HOSTNAME=$(HOST) USER=$(NIX_USERNAME) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure .#homeConfigurations.$(HOST).activationPackage; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) USER=$(NIX_USERNAME) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure .#homeConfigurations.$(DETECTED_HOST).activationPackage; \
else \
HOST=$(NIX_SYSTEM) HOSTNAME=$(NIX_SYSTEM) USER=$(NIX_USERNAME) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure .#$(NIX_CONFIG_TYPE)."$(NIX_USERNAME)@$(NIX_SYSTEM)".activationPackage; \
fi; \
else \
echo "Unsupported OS $(OS) for non-CI switch"; \
exit 1; \
fi; \
fi
@echo "✅ Nix configuration activated successfully!"
.PHONY: nix-switch-vm
nix-switch-vm: ## Switch NixOS configuration in VM.
@if [ ! -f "./result/bin/run-nixos-vm" ]; then \
echo "❌ VM binary not found at ./result/bin/run-nixos-vm"; \
exit 0; \
fi; \
export QEMU_OPTS="-m 4096 -smp 2"; \
printf "sleep 5\nmkdir -p /tmp/test && cd /tmp/test\ncp -r /mnt/shared/* .\n$(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- switch --flake .#runner --no-update-lock-file\npoweroff\n" > vm_commands.txt; \
timeout 600 ./result/bin/run-nixos-vm -nographic < vm_commands.txt || exit 1; \
rm -f vm_commands.txt
##@ Nix Offline Mode
.PHONY: nix-build-offline
nix-build-offline: ## Build Nix configuration in offline mode.
@echo "🏗️ Building Nix configuration in offline mode"
@if [ "$(OS)" = "Darwin" ]; then \
NIX_OFFLINE=1 $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#darwinConfigurations.galactica.system $(NIX_FLAGS) --impure --no-update-lock-file --offline --show-trace; \
elif [ "$(NIX_CONFIG_TYPE)" = "nixosConfigurations" ]; then \
NIX_OFFLINE=1 $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#nixosConfigurations.runner.config.system.build.toplevel $(NIX_FLAGS) --impure --no-update-lock-file --offline --show-trace; \
elif [ "$(NIX_CONFIG_TYPE)" = "homeConfigurations" ]; then \
NIX_OFFLINE=1 $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#$(NIX_CONFIG_TYPE)."$(NIX_USERNAME)@$(NIX_SYSTEM)".activationPackage $(NIX_FLAGS) --impure --no-update-lock-file --offline --show-trace; \
else \
echo "Unsupported OS $(OS) for offline build"; \
exit 1; \
fi
@echo "✅ Nix configuration built successfully in offline mode!"
.PHONY: nix-switch-offline
nix-switch-offline: ## Activate Nix configuration in offline mode.
@echo "🔧 Activating Nix configuration in offline mode"
@if [ "$(OS)" = "Darwin" ]; then \
NIX_OFFLINE=1 $(SUDO) $(NIX_ALLOW_UNFREE) $(DARWIN_REBUILD) switch --flake .#galactica --impure --offline; \
elif [ "$(NIX_CONFIG_TYPE)" = "nixosConfigurations" ]; then \
NIX_OFFLINE=1 $(SUDO) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#runner --no-update-lock-file --offline || exit 0; \
elif [ "$(NIX_CONFIG_TYPE)" = "homeConfigurations" ]; then \
NIX_OFFLINE=1 USER=$(NIX_USERNAME) $(SUDO) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure .#$(NIX_CONFIG_TYPE)."$(NIX_USERNAME)@$(NIX_SYSTEM)".activationPackage --offline; \
else \
echo "Unsupported OS $(OS) for offline switch"; \
exit 1; \
fi
@echo "✅ Nix configuration activated successfully in offline mode!"
.PHONY: nix-setup-offline
nix-setup-offline: ## Set up offline environment.
@echo "🔧 Setting up offline environment"
@mkdir -p ~/.cache/nix
@echo "✅ Offline environment setup complete"
##@ Offline Mode
##@ Named Hosts Specific Targets
define MAKE_NIXOS_HOST_BUILD_TARGET
.PHONY: build-$(1)
build-$(1): ## Build the $(1) named host configuration.
@$(MAKE) build HOST=$(1)
endef
define MAKE_NIXOS_HOST_ISO_TARGET
.PHONY: build-$(1)-iso
build-$(1)-iso: ## Build the $(1) named host live/install ISO.
@$(MAKE) build-iso HOST=$(1)
endef
$(foreach host,$(NIXOS_NAMED_HOSTS),$(eval $(call MAKE_NIXOS_HOST_BUILD_TARGET,$(host))))
$(foreach host,$(ISO_NAMED_HOSTS),$(eval $(call MAKE_NIXOS_HOST_ISO_TARGET,$(host))))
.PHONY: build-vm
build-vm: ## Build a named host VM launcher (set HOST=<name>, e.g. make build-vm HOST=viper).
@host="$(HOST)"; \
if [ -z "$$host" ]; then \
host="$(DETECTED_HOST)"; \
fi; \
if [ -z "$$host" ]; then \
echo "❌ No HOST specified and no named host auto-detected"; \
exit 1; \
fi; \
echo "🏗️ Building VM for $$host"; \
$(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#nixosConfigurations.$$host.config.system.build.vm $(NIX_FLAGS) --impure --show-trace
.PHONY: run-vm
run-vm: ## Run a named host VM launcher (set HOST=<name>, e.g. make run-vm HOST=viper).
@host="$(HOST)"; \
if [ -z "$$host" ]; then \
host="$(DETECTED_HOST)"; \
fi; \
if [ -z "$$host" ]; then \
echo "❌ No HOST specified and no named host auto-detected"; \
exit 1; \
fi; \
$(MAKE) build-vm HOST="$$host"; \
script=$$(find ./result/bin -maxdepth 1 -type f \( -name 'run-*-vm' -o -name 'run-nixos-vm' \) | head -n 1); \
if [ -z "$$script" ]; then \
echo "❌ Could not find a VM launcher under ./result/bin"; \
exit 1; \
fi; \
"$$script"
.PHONY: build-iso
build-iso: ## Build a named host live/install ISO and copy it to ./<host>.iso (set HOST=<name>, e.g. make build-iso HOST=viper).
@set -e; \
host="$(HOST)"; \
if [ -z "$$host" ]; then \
host="$(DETECTED_HOST)"; \
fi; \
if [ -z "$$host" ]; then \
echo "❌ No HOST specified and no named host auto-detected"; \
exit 1; \
fi; \
echo "💿 Building ISO for $$host"; \
$(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#nixosConfigurations.$$host"Iso".config.system.build.isoImage $(NIX_FLAGS) --impure --show-trace; \
iso_path=$$(bash ./scripts/find-built-iso.sh ./result); \
if [ -z "$$iso_path" ]; then \
echo "❌ Could not find a built ISO under ./result"; \
exit 1; \
fi; \
cp -f "$$iso_path" "./$$host.iso"; \
echo "✅ Copied $$iso_path to ./$$host.iso"
.PHONY: switch-%
switch-%: ## Switch to a named host configuration (e.g., make switch-galactica).
@$(MAKE) nix-switch HOST=$*
.PHONY: encrypt-key-%
encrypt-key-%: ## Encrypt a key for a named host (e.g., make encrypt-key-galactica KEY_FILE=~/.ssh/id_ed25519).
@$(MAKE) encrypt-key HOST=$* KEY_FILE=$(KEY_FILE)
.PHONY: decrypt-key-%
decrypt-key-%: ## Decrypt a key for a named host (e.g., make decrypt-key-galactica KEY_FILE=id_ed25519).
@$(MAKE) decrypt-key HOST=$* KEY_FILE=$(KEY_FILE)
.PHONY: rekey-%
rekey-%: ## Rekey all secrets for a named host (e.g., make rekey-galactica).
@$(MAKE) rekey HOST=$*
##@ Agenix Secrets Management
.PHONY: encrypt-key
encrypt-key: ## Encrypt a key file for a host (requires HOST and KEY_FILE variables).
@if [ -z "$(HOST)" ]; then \
echo "❌ HOST variable is not set. Usage: make encrypt-key HOST=<hostname> KEY_FILE=<path_to_key>"; \
exit 1; \
fi
@if [ -z "$(KEY_FILE)" ]; then \
echo "❌ KEY_FILE variable is not set. Usage: make encrypt-key HOST=<hostname> KEY_FILE=<path_to_key>"; \
exit 1; \
fi
@echo "🔐 Encrypting $(KEY_FILE) for host $(HOST)..."
@cd named-hosts/$(HOST) && mkdir -p keys && cat $(KEY_FILE) | agenix -e keys/$(shell basename $(KEY_FILE)).age
@echo "✅ Key encrypted to named-hosts/$(HOST)/keys/$(shell basename $(KEY_FILE)).age"
.PHONY: decrypt-key
decrypt-key: ## Decrypt a key file for a host (requires HOST variable, optional KEY_FILE).
@if [ -z "$(HOST)" ]; then \
echo "❌ HOST variable is not set. Usage: make decrypt-key HOST=<hostname> KEY_FILE=<path_to_key>"; \
exit 1; \
fi
@if [ -z "$(KEY_FILE)" ]; then \
KEY_FILE="id_ed25519"; \
fi
@echo "🔓 Decrypting keys/$(KEY_FILE).age for host $(HOST)..."
@cd named-hosts/$(HOST) && agenix -d keys/$(KEY_FILE).age
.PHONY: rekey
rekey: ## Rekey all secrets for a host (requires HOST variable).
@if [ -z "$(HOST)" ]; then \
echo "❌ HOST variable is not set. Usage: make rekey HOST=<hostname>"; \
exit 1; \
fi
@echo "🔑 Rekeying all secrets for host $(HOST)..."
@cd named-hosts/$(HOST) && agenix --rekey
@echo "✅ Rekeying complete for $(HOST)."
##@ Shell Installation
.PHONY: shell-install
shell-install: ## Set up Fish shell as default shell.
@echo "🐠 Setting up Fish shell..."
@if command -v fish > /dev/null; then \
fish_path=$$(command -v fish); \
if ! grep -q "$$fish_path" /etc/shells; then \
echo "Adding $$fish_path to /etc/shells..."; \
echo $$fish_path | $(SUDO) tee -a /etc/shells; \
fi; \
if [ "$$(basename "$$SHELL")" != "fish" ]; then \
echo "Changing default shell to Fish shell..."; \
chsh -s $$fish_path; \
echo "✅ Default shell changed to Fish. Please log out and back in for changes to take effect."; \
else \
echo "✅ Fish is already the default shell."; \
fi; \