98 lines
3.3 KiB
Nix
98 lines
3.3 KiB
Nix
{ config, pkgs, ... }:
|
|
|
|
let
|
|
container_name = "frigate";
|
|
compose_file = "podman/frigate/compose.yaml";
|
|
config_dir = "/mnt/config/frigate";
|
|
data_dir = "/mnt/data/frigate";
|
|
in
|
|
|
|
{
|
|
config = {
|
|
environment.etc."${compose_file}".text =
|
|
/*
|
|
yaml
|
|
*/
|
|
''
|
|
services:
|
|
frigate:
|
|
image: ghcr.io/blakeblackshear/frigate:stable
|
|
container_name: frigate
|
|
shm_size: "512MB"
|
|
networks:
|
|
home-assistant_frontend:
|
|
home-assistant_backend:
|
|
volumes:
|
|
- ${config_dir}:/config
|
|
- ${data_dir}/clips:/media/frigate/clips
|
|
- ${data_dir}/recordings:/media/frigate/recordings
|
|
- ${data_dir}/exports:/media/frigate/exports
|
|
- /etc/localtime:/etc/localtime:ro
|
|
- type: tmpfs
|
|
target: /tmp/cache
|
|
tmpfs:
|
|
size: 2000000000
|
|
environment:
|
|
FRIGATE_MQTT_USER: $FRIGATE_MQTT_USER
|
|
FRIGATE_MQTT_PASSWORD: $FRIGATE_MQTT_PASSWORD
|
|
# --- frigate devices --- #
|
|
labels:
|
|
- traefik.enable=true
|
|
- traefik.docker.network=home-assistant_frontend
|
|
- traefik.http.services.frigate.loadbalancer.server.port=8971
|
|
- traefik.http.services.frigate.loadbalancer.server.scheme=http
|
|
- traefik.http.routers.frigate-https.entrypoints=websecure
|
|
- traefik.http.routers.frigate-https.rule=Host(`frigate.$DOMAIN_NAME`)
|
|
- traefik.http.routers.frigate-https.tls=true
|
|
- traefik.http.routers.frigate-https.tls.certresolver=cloudflare
|
|
restart: unless-stopped
|
|
|
|
networks:
|
|
home-assistant_backend:
|
|
external: true
|
|
home-assistant_frontend:
|
|
external: true
|
|
'';
|
|
|
|
systemd.services."${container_name}" = {
|
|
description = "Podman container : ${container_name}";
|
|
after = [ "traefik.service" "home-assistant.service" "pi-hole.service" ];
|
|
requires = [ "traefik.service" "home-assistant.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";
|
|
ExecStartPre = [
|
|
"${pkgs.bash}/bin/bash -c 'sleep $((RANDOM % 180))'"
|
|
"-${pkgs.podman-compose}/bin/podman-compose -f /etc/${compose_file} pull"
|
|
];
|
|
ExecStart = "${pkgs.podman-compose}/bin/podman-compose -f /etc/${compose_file} up --remove-orphans";
|
|
ExecStop = "${pkgs.podman-compose}/bin/podman-compose -f /etc/${compose_file} down";
|
|
Restart = "on-failure";
|
|
RestartSec = "5m";
|
|
StartLimitBurst = "3";
|
|
};
|
|
};
|
|
|
|
systemd.services."update-${container_name}" = {
|
|
description = "Update ${container_name} container";
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
ExecStart = "${pkgs.systemd}/bin/systemctl restart ${container_name}.service";
|
|
};
|
|
};
|
|
|
|
systemd.timers."update-${container_name}" = {
|
|
timerConfig = {
|
|
OnCalendar = "02:00";
|
|
RandomizedDelaySec = "60m";
|
|
Unit = "update-${container_name}.service";
|
|
};
|
|
wantedBy = [ "timers.target" ];
|
|
};
|
|
};
|
|
} |