{ config, pkgs, ... }: let container_name = "home-assistant"; compose-dir = "docker-compose/hass"; config-dir = "/mnt/config-storage/docker-data/hass"; in { config = { environment.etc."${compose-dir}/compose.yaml".text = /* yaml */ '' services: home-assistant: image: ghcr.io/home-assistant/home-assistant:latest container_name: home-assistant networks: hass_frontend: hass_backend: volumes: - ${config-dir}/config:/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(`hass.$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: frigate-mqtt user: 1000:1000 networks: hass_backend: volumes: - ${config-dir}/mqtt:/mosquitto restart: unless-stopped networks: hass_backend: name: hass_backend driver: bridge ipam: config: - subnet: "172.16.4.0/24" gateway: "172.16.4.254" hass_frontend: external: true ''; systemd.services.hass = { description = "Docker container : ${container_name}"; after = [ "network.target" "docker.service" "docker.socket" "traefik.service" ]; requires = [ "docker.service" ]; wantedBy = ["multi-user.target"]; path = [ pkgs.docker ]; serviceConfig = { Type = "exec"; # Pull the latest image before running ExecStartPre = "${pkgs.docker}/bin/docker compose -f /etc/${compose-dir}/compose.yaml pull"; # Bring the service up ExecStart = "${pkgs.docker}/bin/docker compose -f /etc/${compose-dir}/compose.yaml up --remove-orphans"; # Take it down gracefully ExecStop = "${pkgs.docker}/bin/docker compose -f /etc/${compose-dir}/compose.yaml down"; Restart = "on-failure"; }; }; }; }