{ 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: home-assistant networks: home-assistant_frontend: home-assistant_backend: volumes: - ${config_dir_1}:/config - /etc/localtime:/etc/localtime:ro - /run/dbus:/run/dbus:ro # --- home-assistant devices --- # labels: - traefik.enable=true - traefik.docker.network=home-assistant_frontend - 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(`home-assistant.$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: home-assistant_backend: volumes: - ${config_dir_2}:/mosquitto restart: unless-stopped networks: home-assistant_backend: external: true home-assistant_frontend: external: true ''; systemd.services.${container_name} = { description = "Podman container : ${container_name}"; after = [ "network.target" "traefik.service" "pi-hole.service" ]; requires = [ "traefik.service" ]; wantedBy = [ "multi-user.target" ]; path = [ pkgs.podman pkgs.coreutils ]; serviceConfig = { User = "numbus-admin"; Environment = [ "XDG_RUNTIME_DIR=/run/user/1000" ]; Type = "exec"; TimeoutStartSec = "600"; # Pull the latest image before running ExecStartPre = [ "${pkgs.coreutils}/bin/sleep 180" "-${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"; RestartSec = "5m"; StartLimitBurst = "3"; }; }; }; }