From 514409939d22b0495f9d7f50565fcea08056111b Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Tue, 17 Nov 2026 16:59:50 -0500 Subject: [PATCH] feat(nixos): add activation guard preventing example.test domain deployment - Add system.activationScripts.checkHomelabDomain that aborts activation if homelab.domain defaults to 'example.test' - Prevents silent deployment with placeholder domains when --impure flag is omitted from nixos-rebuild - Guard runs only during activation (not during nix eval), so workstation tests remain unaffected --- nixos/modules/homeserver.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nixos/modules/homeserver.nix b/nixos/modules/homeserver.nix index 9180412..0020787 100644 --- a/nixos/modules/homeserver.nix +++ b/nixos/modules/homeserver.nix @@ -32,6 +32,18 @@ domainParts = lib.splitString "." config.homelab.domain; ldapBaseDn = lib.concatStringsSep "," (map (part: "dc=${part}") domainParts); in { + # ── Host Activation Guard ──────────────────────────────────────────────────── + # Prevents activating on a live host if homelab.domain defaulted to example.test (e.g. forgot --impure) + system.activationScripts.checkHomelabDomain = { + text = '' + if [ "${config.homelab.domain}" = "example.test" ]; then + echo "❌ [homelab] FATAL: homelab.domain is defaulting to 'example.test'!" >&2 + echo "❌ [homelab] Did you run 'nixos-rebuild switch' without the '--impure' flag?" >&2 + echo "❌ [homelab] To activate properly: sudo nixos-rebuild switch --flake path:/home/operator/Core#server --impure" >&2 + exit 1 + fi + ''; + }; # Define the keys to decrypt from secrets.yaml sops.secrets = (lib.genAttrs [ "dynu/api_key"