{ config, lib, namespace, ... }: with lib; let cfg = config.${namespace}.services.home-assistant; in { config = mkIf cfg.enable { virtualisation.oci-containers.containers.esphome = { autoStart = true; image = "ghcr.io/esphome/esphome"; # host networking is required for mDNS (multicast UDP) to work so that # ESPHome can discover devices via .local and perform OTA updates # without needing to know device IPs in advance. extraOptions = [ "--network=host" ]; devices = [ "/dev/ttyUSB0" ]; privileged = true; volumes = [ "/esphome:/config" # Persist the PlatformIO core dir (penv, packages, platforms) so the # pioarduino penv_setup.py dependency install only runs once rather # than on every container restart. "/esphome/.platformio:/root/.platformio" ]; environment = { TZ = "America/Chicago"; }; }; # Open the ESPHome dashboard port networking.firewall.allowedTCPPorts = [ 6052 ]; }; }