diff --git a/modules/nixos/services/home-assistant/default.nix b/modules/nixos/services/home-assistant/default.nix index 7215126..cde774f 100644 --- a/modules/nixos/services/home-assistant/default.nix +++ b/modules/nixos/services/home-assistant/default.nix @@ -35,45 +35,77 @@ in }; config = mkIf cfg.enable { - ### The actual Home Assistant service setup - services.home-assistant = { - enable = true; - - extraComponents = [ - # Components required to complete the onboarding - "analytics" - "google_translate" - "met" - "radio_browser" - "shopping_list" - - # Required for matter over thread with the ZBT-2 - "matter" - "otbr" - "thread" - - # Recommended for fast zlib compression - "isal" - ]; + services = { + ### The actual Home Assistant service setup + home-assistant = { + enable = true; + + extraComponents = [ + # Components required to complete the onboarding + "analytics" + "google_translate" + "met" + "radio_browser" + "shopping_list" + + # Required for matter over thread with the ZBT-2 + "matter" + "otbr" + "thread" + + # Recommended for fast zlib compression + "isal" + ]; + + config = { + # Includes dependencies for a basic setup + # https://www.home-assistant.io/integrations/default_config/ + default_config = { }; + + "automation ui" = "!include automations.yaml"; + "scene ui" = "!include scenes.yaml"; + "script ui" = "!include scripts.yaml"; + + http = { + server_host = "::1"; + trusted_proxies = [ "::1" ]; + use_x_forwarded_for = true; + }; + }; + }; + + ### The OpenThread Border Router required for the integration + services.openthread-border-router = { + enable = true; + + radio = { + device = cfg.radio.device; + baudRate = 460800; + flowControl = false; # ZBT-2 uses USB-C + }; - config = { - # Includes dependencies for a basic setup - # https://www.home-assistant.io/integrations/default_config/ - default_config = { }; + backboneInterfaces = [ cfg.otbr.backboneInterface ]; - "automation ui" = "!include automations.yaml"; - "scene ui" = "!include scenes.yaml"; - "script ui" = "!include scripts.yaml"; + rest = { + listenAddress = "::1"; + listenPort = 8081; + }; + }; + ### The Traefik proxy mappings + services.traefik.dynamicConfigOptions = { http = { - server_host = "::1"; - trusted_proxies = [ "::1" ]; - use_x_forwarded_for = true; + services.home-assistant.loadBalancer.servers = [ { url = "http://localhost:8123"; } ]; + routers.home-assistant = { + entryPoints = [ "websecure" ]; + service = "home-assistant"; + rule = "Host(`${cfg.subdomain}.${config.${namespace}.services.domain}`)"; + }; }; }; }; - # Ensure required files from the above config list are actually available + ### Ensure required files from the above config list are actually available systemd.tmpfiles.rules = [ "f ${config.services.home-assistant.configDir}/automations.yaml 0644 hass hass" "f ${config.services.home-assistant.configDir}/scenes.yaml 0644 hass hass" @@ -102,36 +134,6 @@ in ]; }; - ### The OpenThread Border Router required for the integration - services.openthread-border-router = { - enable = true; - - radio = { - device = cfg.radio.device; - baudRate = 460800; - flowControl = false; # ZBT-2 uses USB-C - }; - - backboneInterfaces = [ cfg.otbr.backboneInterface ]; - - rest = { - listenAddress = "::1"; - listenPort = 8081; - }; - }; - - ### The Traefik proxy mappings - services.traefik.dynamicConfigOptions = { - http = { - services.home-assistant.loadBalancer.servers = [ { url = "http://localhost:8123"; } ]; - routers.home-assistant = { - entryPoints = [ "websecure" ]; - service = "home-assistant"; - rule = "Host(`${cfg.subdomain}.${config.${namespace}.services.domain}`)"; - }; - }; - }; - ### Firewall configuration networking.firewall = { allowedUDPPorts = [