From 2efc4798a0a0e368e532ae80fe0e3d3a32f27184 Mon Sep 17 00:00:00 2001 From: TheWanderingCrow Date: Fri, 7 Mar 2025 09:50:26 -0500 Subject: [PATCH] frigate config working --- flake.lock | 6 +- modules/users/overseer/services/default.nix | 2 +- modules/users/overseer/services/frigate.nix | 165 +++++++++++--------- 3 files changed, 99 insertions(+), 74 deletions(-) diff --git a/flake.lock b/flake.lock index f6439e6..bdecd90 100644 --- a/flake.lock +++ b/flake.lock @@ -516,11 +516,11 @@ "nvf": "nvf" }, "locked": { - "lastModified": 1741285115, - "narHash": "sha256-Q0reKAntl3W8EP9uuAX/3QsPrO41Jvyqw3B6grov8yc=", + "lastModified": 1741295152, + "narHash": "sha256-pNRZ90e/ClXm/e7ViCXR26q06GMjKurHOHw9v0grBVo=", "owner": "TheWanderingCrow", "repo": "nvix", - "rev": "d2e0cc331ae40341e367b3c846c234d5d0841988", + "rev": "87c3dbcbe9b00b0a96d8101d986d0f078aebae7c", "type": "github" }, "original": { diff --git a/modules/users/overseer/services/default.nix b/modules/users/overseer/services/default.nix index 1c01065..9826f5a 100644 --- a/modules/users/overseer/services/default.nix +++ b/modules/users/overseer/services/default.nix @@ -3,10 +3,10 @@ ./bar-assistant.nix ./homebox.nix ./homepage.nix - ./bookstack.nix ./the-nest.nix ./umami.nix ./lubelogger.nix ./openhab.nix + ./frigate.nix ]; } diff --git a/modules/users/overseer/services/frigate.nix b/modules/users/overseer/services/frigate.nix index f1375f7..8f6ad6d 100644 --- a/modules/users/overseer/services/frigate.nix +++ b/modules/users/overseer/services/frigate.nix @@ -1,103 +1,128 @@ -{ - lib, - config, - ... -}: { - services.go2rtc = { - enable = true; - - settings = { - streams = { - wce-0001 = [ - "ffmpeg:#input=-timeout 30000000 -i rtsp://thingino:thingino@192.168.0.173:554/ch0" - - "ffmpeg:wce-0001#audio=opus" - ]; - - wce-0001_sub = "ffmpeg:#input=-timeout 30000000 -i rtsp://thingino:thingino@192.168.0.173:554/ch1"; - - wce-0002 = [ - "ffmpeg:#input=-timeout 30000000 -i rtsp://thingino:thingino@192.168.0.26:554/ch0" - - "ffmpeg:wce-0002#audio=opus" - ]; - - wce-0002_sub = "ffmpeg:#input=-timeout 30000000 -i rtsp://thingino:thingino@192.168.0.26:554/ch1"; +let + volumePath = "/overseer/services"; +in + { + pkgs, + lib, + config, + ... + }: let + frigateConfig = pkgs.writeText "config.yaml" (lib.generators.toYAML {} { + tls.enabled = false; # off because we're doing ssl through nginx + mqtt = { + # TODO: add mqtt broker + enabled = false; }; - }; - }; - - services.frigate = { - enable = true; - - hostname = "frigate.wanderingcrow.net"; - - settings = { + ################### + # go2rtc restream # + ################### + go2rtc = { + streams = { + wce-0001 = [ + "rtsp://thingino:thingino@192.168.0.173:554/ch0" + ]; + wce-0001_sub = [ + "rtsp://thingino:thingino@192.168.0.173:554/ch1" + ]; + wce-0002 = [ + "rtsp://thingino:thingino@192.168.0.26:554/ch0" + ]; + wce-0002_sub = [ + "rtsp://thingino:thingino@192.168.0.26:554/ch1" + ]; + }; + }; + ################# + # Camera config # + ################# cameras = { wce-0001 = { ffmpeg = { inputs = [ { - path = "rtsp://127.0.0.1:8554/wce-0001?timeout=30"; - - input_args = "preset-rtsp-restream-low-latency"; - + path = "rtsp://127.0.0.1:8554/wce-0001"; roles = ["record"]; } - { - path = "rtsp://127.0.0.1:8554/wce-0001_sub?timeout=30"; - - input_args = "preset-rtsp-restream-low-latency"; - - roles = ["detect" "audio"]; + path = "rtsp://127.0.0.1:8554/wce-0001_sub"; + roles = ["detect"]; } ]; }; - motion = { mask = [ - "0.005,0.006,0.005,0.041,0.195,0.041,0.196,0.008" - - "0.904,0.007,0.903,0.042,0.994,0.042,0.994,0.006" + "0,0,0,0.04,0.201,0.043,0.199,0.005" + "0.864,0,0.865,0.043,1,0.043,1,0" ]; }; - - live.stream_name = "wce-0001"; + live.stream_name = "wce-0001_sub"; + detect.enabled = false; }; - wce-0002 = { ffmpeg = { inputs = [ { - path = "rtsp://127.0.0.1:8554/wce-0002?timeout=30"; - - input_args = "preset-rtsp-restream-low-latency"; - + path = "rtsp://127.0.0.1:8554/wce-0002"; roles = ["record"]; } - { - path = "rtsp://127.0.0.1:8554/wce-0002_sub?timeout=30"; - - input_args = "preset-rtsp-restream-low-latency"; - - roles = ["detect" "audio"]; + path = "rtsp://127.0.0.1:8554/wce-0002_sub"; + roles = ["detect"]; } ]; }; - motion = { mask = [ - "0.005,0.006,0.005,0.041,0.195,0.041,0.196,0.008" - - "0.904,0.007,0.903,0.042,0.994,0.042,0.994,0.006" + "0,0,0,0.04,0.201,0.043,0.199,0.005" + "0.864,0,0.865,0.043,1,0.043,1,0" ]; }; - - live.stream_name = "wce-0002"; + live.stream_name = "wce-0002_sub"; + detect.enabled = false; }; }; - }; - }; -} + }); + in + lib.mkIf config.user.overseer.enable { + systemd.tmpfiles.rules = [ + "d ${volumePath}/frigate" + "d ${volumePath}/frigate/config" + "d ${volumePath}/frigate/media/frigate" + ]; + ########### + # Service # + ########### + + virtualisation.oci-containers = { + backend = "podman"; + containers = { + "frigate" = { + image = "ghcr.io/blakeblackshear/frigate:stable"; + volumes = [ + "/etc/localtime:/etc/localtime:ro" + "${volumePath}/frigate/media/frigate:/media/frigate" + "${frigateConfig}:/config/config.yaml:ro" + ]; + extraOptions = [ + "--shm-size=612m" + "--ip=10.88.0.10" + ]; + }; + }; + }; + + services.nginx = { + enable = true; + recommendedProxySettings = true; + virtualHosts = { + "frigate.wanderingcrow.net" = { + forceSSL = true; + useACMEHost = "frigate.wanderingcrow.net"; + locations."/" = { + proxyPass = "http://10.88.0.10:8971"; + proxyWebsockets = true; + }; + }; + }; + }; + }