Commit 32f8bd2e4896

Vincent Demeester <vincent@sbr.pm>
2026-11-24 12:31:28
perf: deferred host discovery until needed
Avoided unnecessary flake evaluation when displaying help or running other targets, while preserving host builds and exposing discovery failures. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent e0b425e
Changed files (1)
Makefile
@@ -1,7 +1,4 @@
 # Makefile for home
-HOSTS          = $(shell nix flake show --json --all-systems 2>/dev/null | yq '.nixosConfigurations.[] | key')
-HOSTS_BUILD    = $(addprefix host/, $(addsuffix /build,$(HOSTS)))
-
 .PHONY: all
 all: help
 
@@ -17,8 +14,13 @@ help: ## Show this help message
 ##@ Host Operations (Remote)
 
 .PHONY: hosts
-hosts: ${HOSTS_BUILD} ## List and build all hosts
-	echo ${HOSTS_BUILD} ${HOSTS}
+hosts: ## List and build all hosts
+	@json="$$(nix eval --json .#nixosConfigurations --apply builtins.attrNames)" || exit $$?; \
+	  hosts="$$(printf '%s\n' "$$json" | yq -r '.[]')" || exit $$?; \
+	  [ -n "$$hosts" ] || { echo 'No NixOS hosts found' >&2; exit 1; }; \
+	  set --; for host in $$hosts; do set -- "$$@" "host/$$host/build"; done; \
+	  echo "$$@"; \
+	  $(MAKE) "$$@"
 
 host/%/build: FORCE ## Build a specific remote host (e.g., make host/demeter/build)
 	nix build .#nixosConfigurations.$*.config.system.build.toplevel --no-link