{ config, pkgs, ... }: let container_name = "home-assistant"; compose_file = "podman/home-assistant/compose.yaml"; config_dir_1 = "/mnt/config/home-assistant"; config_dir_2 = "/mnt/config/mqtt"; in { config = { environment.etc."${compose_file}".text = /* yaml */ '' services: home-assistant: image: ghcr.io/home-assistant/home-assistant:latest container_name: ${container_name} networks: hass_frontend: hass_backend: volumes: - ${config_dir_1}:/config - /etc/localtime:/etc/localtime:ro - /run/dbus:/run/dbus:ro # --- hass devices --- # labels: - traefik.enable=true - traefik.http.services.home-assistant.loadbalancer.server.port=8123 - traefik.http.services.home-assistant.loadbalancer.server.scheme=http - traefik.http.routers.home-assistant-https.entrypoints=websecure - traefik.http.routers.home-assistant-https.rule=Host(`${container_name}.$DOMAIN_NAME`) - traefik.http.routers.home-assistant-https.tls=true - traefik.http.routers.home-assistant-https.tls.certresolver=cloudflare restart: unless-stopped frigate-mqtt: image: eclipse-mosquitto container_name: mqtt user: 1000:1000 networks: hass_backend: volumes: - ${config_dir_2}:/mosquitto restart: unless-stopped networks: hass_backend: external: true hass_frontend: external: true ''; systemd.services.hass = { description = "Podman container : ${container_name}"; after = [ "network.target" "traefik.service" ]; requires = [ "network.target" ]; wantedBy = ["multi-user.target"]; path = [ pkgs.podman-compose ]; serviceConfig = { Type = "exec"; # Pull the latest image before running ExecStartPre = "${pkgs.podman-compose}/bin/podman-compose -f /etc/${compose_file} pull"; # Bring the service up ExecStart = "${pkgs.podman-compose}/bin/podman-compose -f /etc/${compose_file} up --remove-orphans"; # Take it down gracefully ExecStop = "${pkgs.podman-compose}/bin/podman-compose -f /etc/${compose_file} down"; Restart = "on-failure"; }; }; }; }