From 5fd2649cac8ed9adce3b1111ef3a678adcc8d176 Mon Sep 17 00:00:00 2001 From: Jordan Holt Date: Sun, 5 Jan 2025 19:14:34 +0000 Subject: [PATCH] Split out home-assistant config --- hosts/pi/default.nix | 342 +------------------ modules/default.nix | 1 + modules/services/home-assistant/default.nix | 353 ++++++++++++++++++++ 3 files changed, 355 insertions(+), 341 deletions(-) create mode 100644 modules/services/home-assistant/default.nix diff --git a/hosts/pi/default.nix b/hosts/pi/default.nix index e8a3529..eb3c631 100644 --- a/hosts/pi/default.nix +++ b/hosts/pi/default.nix @@ -113,343 +113,6 @@ pulse.enable = true; }; - age.secrets."files/services/home-assistant/secrets.yaml" = { - file = "${self.inputs.secrets}/files/services/home-assistant/secrets.yaml.age"; - path = "${config.services.home-assistant.configDir}/secrets.yaml"; - owner = "hass"; - group = "hass"; - }; - - services.home-assistant = { - enable = true; - - config = { - automation = "!include automations.yaml"; - backup = { }; - binary_sensor = [ ]; - default_config = { }; - http = { - server_host = "::1"; - trusted_proxies = [ "::1" ]; - use_x_forwarded_for = true; - }; - ffmpeg = { }; - homeassistant = { - name = "Home"; - latitude = "!secret latitude"; - longitude = "!secret longitude"; - country = "GB"; - temperature_unit = "C"; - time_zone = config.time.timeZone; - unit_system = "metric"; - auth_providers = [ - { - type = "trusted_networks"; - trusted_networks = [ - "100.64.0.0/10" - "127.0.0.1" - ]; - allow_bypass_login = true; - } - { - type = "homeassistant"; - } - ]; - }; - logger = { - default = "info"; - logs = { }; - }; - lovelace = { - resources = [ - { - url = "/local/nixos-lovelace-modules/floorplan.js"; - type = "module"; - } - { - url = "/local/nixos-lovelace-modulels/mushroom.js"; - type = "module"; - } - ]; - }; - media_player = [ ]; - mobile_app = { }; - mqtt = { }; - onkyo = { }; - open_meteo = { }; - recorder = { - purge_keep_days = 365; - }; - scene = "!include scenes.yaml"; - sensor = [ ]; - system_health = { }; - zeroconf = { }; - }; - - extraComponents = [ - "air_quality" - "airly" - "alert" - "api" - "application_credentials" - "asuswrt" - "auth" - "automation" - "bayesian" - "binary_sensor" - # "blackbird" - "blueprint" - "bluetooth_adapters" - "bluetooth_le_tracker" - "button" - "calendar" - "camera" - "cast" - "cert_expiry" - "climate" - "co2signal" - "color_extractor" - "command_line" - "compensation" - "configurator" - "counter" - "cover" - "cpuspeed" - "default_config" - "demo" - "derivative" - "device_automation" - "device_sun_light_trigger" - "device_tracker" - "dlna_dmr" - "dlna_dms" - "dnsip" - "esphome" - "fail2ban" - "fan" - "feedreader" - "ffmpeg" - "file" - "file_upload" - "filesize" - "folder" - "folder_watcher" - "forecast_solar" - "frontend" - "gdacs" - "generic" - "generic_hygrostat" - "generic_thermostat" - "geo_json_events" - "geo_location" - "geo_rss_events" - "github" - "group" - "hardware" - "hdmi_cec" - "history_stats" - "homeassistant" - "homekit" - "homekit_controller" - "html5" - "http" - "humidifier" - "icloud" - "image_processing" - "input_boolean" - "input_button" - "input_datetime" - "input_number" - "input_select" - "input_text" - "integration" - "ios" - "jellyfin" - "light" - "local_calendar" - "local_file" - "local_ip" - "local_todo" - "lock" - "logentries" - "logger" - "lovelace" - "manual" - "manual_mqtt" - "matter" - "media_player" - "min_max" - "mjpeg" - "modern_forms" - "mold_indicator" - "moon" - "mqtt" - "mqtt_eventstream" - "mqtt_json" - "mqtt_room" - "mqtt_statestream" - "mysensors" - "network" - "nmap_tracker" - "notify" - "number" - "onboarding" - "onkyo" - "panel_custom" - "persistent_notification" - "person" - "ping" - "plant" - "prometheus" - "proximity" - "push" - "proximity" - "python_script" - "radio_browser" - "random" - "recorder" - "remote" - "repairs" - "rest" - "rest_command" - "rss_feed_template" - "scene" - "schedule" - "scrape" - "script" - "search" - "season" - "select" - "sense" - "sensor" - "sensorpush" - "shell_command" - "shopping_list" - "siren" - "smtp" - "snmp" - "sql" - "statistics" - "sun" - "switch" - "switch_as_x" - "system_health" - "system_log" - "systemmonitor" - "tag" - "tailscale" - "tcp" - "template" - "text" - "thread" - "threshold" - "time_date" - "timer" - "tod" - "todo" - "tomorrowio" - "trend" - "universal" - "upb" - "update" - "upnp" - "uptime" - "utility_meter" - "vacuum" - "vlc" - "vlc_telnet" - "wake_on_lan" - "water_heater" - "weather" - "websocket_api" - "wled" - "workday" - "worldclock" - "zone" - ]; - - extraPackages = python3Packages: with python3Packages; [ - onkyo-eiscp - zeroconf - ]; - - customLovelaceModules = with pkgs.home-assistant-custom-lovelace-modules; [ - bubble-card - button-card - ha-floorplan - mushroom - sankey-chart - universal-remote-card - # zigbee2mqtt-networkmap - ]; - }; - - services.nginx = { - enable = true; - virtualHosts."home.mesh.vimium.net" = { - forceSSL = false; - extraConfig = '' - proxy_buffering off; - ''; - locations."/" = { - proxyPass = "http://[::1]:8123"; - proxyWebsockets = true; - }; - }; - }; - - services.mosquitto = { - enable = true; - listeners = [{ - acl = [ "pattern readwrite #" ]; - omitPasswordAuth = true; - port = 1883; - settings = { - allow_anonymous = true; - }; - }]; - }; - - age.secrets."files/services/zigbee2mqtt/secret.yaml" = { - file = "${self.inputs.secrets}/files/services/zigbee2mqtt/secret.yaml.age"; - path = "${config.services.zigbee2mqtt.dataDir}/secret.yaml"; - owner = "zigbee2mqtt"; - group = "zigbee2mqtt"; - }; - - services.zigbee2mqtt = { - package = pkgs.unstable.zigbee2mqtt; - enable = true; - dataDir = "/var/lib/zigbee2mqtt"; - settings = { - homeassistant = lib.optionalAttrs config.services.home-assistant.enable { - discovery_topic = "homeassistant"; - status_topic = "hass/status"; - legacy_entity_attributes = true; - legacy_triggers = true; - }; - availability = true; - frontend = true; - device_options = { - retain = true; - }; - serial = { - port = "/dev/serial/by-id/usb-Silicon_Labs_Sonoff_Zigbee_3.0_USB_Dongle_Plus_0001-if00-port0"; - }; - advanced = { - channel = 20; - network_key = "!secret.yaml network_key"; - pan_id = 13001; - ext_pan_id = [ 79 1 73 47 250 136 124 222 ]; - transmit_power = 20; - }; - mqtt = { - version = 5; - server = "mqtt://localhost:1883"; - }; - }; - }; - modules = { networking = { wireless = { @@ -460,12 +123,9 @@ services = { borgmatic = { enable = true; - directories = [ - "/var/lib/mosquitto" - "/var/lib/zigbee2mqtt" - ]; repoPath = "ssh://qcw86s11@qcw86s11.repo.borgbase.com/./repo"; }; + home-assistant.enable = true; }; }; diff --git a/modules/default.nix b/modules/default.nix index a5ff39d..5867ffd 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -43,6 +43,7 @@ ./services/gitea ./services/gitea-runner ./services/headscale + ./services/home-assistant ./services/mail ./services/matrix ./services/nginx diff --git a/modules/services/home-assistant/default.nix b/modules/services/home-assistant/default.nix new file mode 100644 index 0000000..60e6e98 --- /dev/null +++ b/modules/services/home-assistant/default.nix @@ -0,0 +1,353 @@ +{ config, lib, self, ... }: + +let + cfg = config.modules.services.home-assistant; +in { + options.modules.services.home-assistant = lib.mkEnableOption "home-assistant"; + + config = lib.mkIf cfg.enable { + age.secrets."files/services/home-assistant/secrets.yaml" = { + file = "${self.inputs.secrets}/files/services/home-assistant/secrets.yaml.age"; + path = "${config.services.home-assistant.configDir}/secrets.yaml"; + owner = "hass"; + group = "hass"; + }; + + modules.services.borgmatic.directories = [ + "/var/lib/mosquitto" + "/var/lib/zigbee2mqtt" + ]; + + + services.home-assistant = { + enable = true; + + config = { + automation = "!include automations.yaml"; + backup = { }; + binary_sensor = [ ]; + default_config = { }; + http = { + server_host = "::1"; + trusted_proxies = [ "::1" ]; + use_x_forwarded_for = true; + }; + ffmpeg = { }; + homeassistant = { + name = "Home"; + latitude = "!secret latitude"; + longitude = "!secret longitude"; + country = "GB"; + temperature_unit = "C"; + time_zone = config.time.timeZone; + unit_system = "metric"; + auth_providers = [ + { + type = "trusted_networks"; + trusted_networks = [ + "100.64.0.0/10" + "127.0.0.1" + ]; + allow_bypass_login = true; + } + { + type = "homeassistant"; + } + ]; + }; + logger = { + default = "info"; + logs = { }; + }; + lovelace = { + resources = [ + { + url = "/local/nixos-lovelace-modules/floorplan.js"; + type = "module"; + } + { + url = "/local/nixos-lovelace-modulels/mushroom.js"; + type = "module"; + } + ]; + }; + media_player = [ ]; + mobile_app = { }; + mqtt = { }; + onkyo = { }; + open_meteo = { }; + recorder = { + purge_keep_days = 365; + }; + scene = "!include scenes.yaml"; + script = "!include scripts.yaml"; + sensor = [ ]; + system_health = { }; + zeroconf = { }; + }; + + extraComponents = [ + "air_quality" + "airly" + "alert" + "api" + "application_credentials" + "asuswrt" + "auth" + "automation" + "bayesian" + "binary_sensor" + # "blackbird" + "blueprint" + "bluetooth_adapters" + "bluetooth_le_tracker" + "button" + "calendar" + "camera" + "cast" + "cert_expiry" + "climate" + "co2signal" + "color_extractor" + "command_line" + "compensation" + "configurator" + "counter" + "cover" + "cpuspeed" + "default_config" + "demo" + "derivative" + "device_automation" + "device_sun_light_trigger" + "device_tracker" + "dlna_dmr" + "dlna_dms" + "dnsip" + "esphome" + "fail2ban" + "fan" + "feedreader" + "ffmpeg" + "file" + "file_upload" + "filesize" + "folder" + "folder_watcher" + "forecast_solar" + "frontend" + "gdacs" + "generic" + "generic_hygrostat" + "generic_thermostat" + "geo_json_events" + "geo_location" + "geo_rss_events" + "github" + "group" + "hardware" + "hdmi_cec" + "history_stats" + "homeassistant" + "homekit" + "homekit_controller" + "html5" + "http" + "humidifier" + "icloud" + "image_processing" + "input_boolean" + "input_button" + "input_datetime" + "input_number" + "input_select" + "input_text" + "integration" + "ios" + "jellyfin" + "light" + "local_calendar" + "local_file" + "local_ip" + "local_todo" + "lock" + "logentries" + "logger" + "lovelace" + "manual" + "manual_mqtt" + "matter" + "media_player" + "min_max" + "mjpeg" + "modern_forms" + "mold_indicator" + "moon" + "mqtt" + "mqtt_eventstream" + "mqtt_json" + "mqtt_room" + "mqtt_statestream" + "mysensors" + "network" + "nmap_tracker" + "notify" + "number" + "onboarding" + "onkyo" + "panel_custom" + "persistent_notification" + "person" + "ping" + "plant" + "prometheus" + "proximity" + "push" + "proximity" + "python_script" + "radio_browser" + "random" + "recorder" + "remote" + "repairs" + "rest" + "rest_command" + "rss_feed_template" + "scene" + "schedule" + "scrape" + "script" + "search" + "season" + "select" + "sense" + "sensor" + "sensorpush" + "shell_command" + "shopping_list" + "siren" + "smtp" + "snmp" + "sql" + "statistics" + "sun" + "switch" + "switch_as_x" + "system_health" + "system_log" + "systemmonitor" + "tag" + "tailscale" + "tcp" + "template" + "text" + "thread" + "threshold" + "time_date" + "timer" + "tod" + "todo" + "tomorrowio" + "trend" + "universal" + "upb" + "update" + "upnp" + "uptime" + "utility_meter" + "vacuum" + "vlc" + "vlc_telnet" + "wake_on_lan" + "water_heater" + "weather" + "websocket_api" + "wled" + "workday" + "worldclock" + "zone" + ]; + + extraPackages = python3Packages: with python3Packages; [ + onkyo-eiscp + zeroconf + ]; + + customLovelaceModules = with pkgs.home-assistant-custom-lovelace-modules; [ + bubble-card + button-card + ha-floorplan + mushroom + sankey-chart + universal-remote-card + # zigbee2mqtt-networkmap + ]; + }; + + services.nginx = { + enable = true; + virtualHosts."home.mesh.vimium.net" = { + forceSSL = false; + extraConfig = '' + proxy_buffering off; + ''; + locations."/" = { + proxyPass = "http://[::1]:8123"; + proxyWebsockets = true; + }; + }; + }; + + services.mosquitto = { + enable = true; + listeners = [{ + acl = [ "pattern readwrite #" ]; + omitPasswordAuth = true; + port = 1883; + settings = { + allow_anonymous = true; + }; + }]; + }; + + age.secrets."files/services/zigbee2mqtt/secret.yaml" = { + file = "${self.inputs.secrets}/files/services/zigbee2mqtt/secret.yaml.age"; + path = "${config.services.zigbee2mqtt.dataDir}/secret.yaml"; + owner = "zigbee2mqtt"; + group = "zigbee2mqtt"; + }; + + services.zigbee2mqtt = { + package = pkgs.unstable.zigbee2mqtt; + enable = true; + dataDir = "/var/lib/zigbee2mqtt"; + settings = { + homeassistant = lib.optionalAttrs config.services.home-assistant.enable { + discovery_topic = "homeassistant"; + status_topic = "hass/status"; + legacy_entity_attributes = true; + legacy_triggers = true; + }; + availability = true; + frontend = true; + device_options = { + retain = true; + }; + serial = { + port = "/dev/serial/by-id/usb-Silicon_Labs_Sonoff_Zigbee_3.0_USB_Dongle_Plus_0001-if00-port0"; + }; + advanced = { + channel = 20; + network_key = "!secret.yaml network_key"; + pan_id = 13001; + ext_pan_id = [ 79 1 73 47 250 136 124 222 ]; + transmit_power = 20; + }; + mqtt = { + version = 5; + server = "mqtt://localhost:1883"; + }; + }; + }; + }; +}