me like nix
1{ ... }:
2{
3 flake.modules.nixos.home-automation =
4 { pkgs, ... }:
5 {
6 # MQTT broker for Home Assistant (Tasmota devices, Frigate)
7 services.mosquitto = {
8 enable = true;
9 listeners = [
10 {
11 acl = [ "pattern readwrite #" ];
12 omitPasswordAuth = true;
13 settings.allow_anonymous = true;
14 }
15 ];
16 };
17
18 # Frigate NVR for camera recording and AI object detection
19 services.frigate = {
20 enable = true;
21 hostname = "frigate";
22 settings = {
23 mqtt = {
24 enabled = true;
25 host = "localhost";
26 port = 1883;
27 };
28
29 detectors = {
30 cpu = {
31 type = "cpu";
32 num_threads = 2;
33 };
34 };
35
36 cameras = {
37 picam = {
38 enabled = true;
39 ffmpeg = {
40 hwaccel_args = "preset-nvidia-h264";
41 inputs = [
42 {
43 path = "rtsp://pi:8554/picam";
44 roles = [
45 "detect"
46 "record"
47 ];
48 }
49 ];
50 };
51 detect = {
52 enabled = true;
53 width = 1920;
54 height = 1080;
55 fps = 3;
56 };
57 record = {
58 enabled = true;
59 retain = {
60 days = 7;
61 mode = "active_objects";
62 };
63 };
64 snapshots = {
65 enabled = true;
66 bounding_box = true;
67 retain = {
68 default = 14;
69 };
70 };
71 objects = {
72 track = [
73 "person"
74 "dog"
75 "cat"
76 "car"
77 ];
78 };
79 zones = {
80 driveway = {
81 coordinates = "0,0.243,1,0.544,1,1,0,1,0,0.75";
82 objects = [
83 "person"
84 "car"
85 "dog"
86 "cat"
87 ];
88 };
89 };
90 };
91
92 pizerocam = {
93 enabled = true;
94 ffmpeg = {
95 hwaccel_args = "preset-nvidia-h264";
96 inputs = [
97 {
98 path = "rtsp://pizero:8554/pizerocam";
99 roles = [ "record" ];
100 }
101 ];
102 };
103 detect = {
104 enabled = false;
105 };
106 record = {
107 enabled = true;
108 retain = {
109 days = 2;
110 mode = "all";
111 };
112 };
113 };
114 };
115
116 record = {
117 enabled = true;
118 retain = {
119 days = 7;
120 mode = "active_objects";
121 };
122 };
123 };
124 };
125
126 # Allow accessing Frigate over LAN
127 services.nginx.virtualHosts."frigate" = {
128 serverAliases = [ "_" ];
129 listen = [
130 { addr = "0.0.0.0"; port = 5000; }
131 ];
132 };
133
134 # Frigate manages many ffmpeg child processes that ignore SIGTERM
135 systemd.services.frigate.serviceConfig = {
136 TimeoutStopSec = 5;
137 KillMode = "mixed";
138 };
139
140 # Home Assistant service
141 services.home-assistant = {
142 enable = true;
143 customComponents = with pkgs.home-assistant-custom-components; [
144 frigate
145 ];
146 extraComponents = [
147 "esphome"
148 "met"
149 "radio_browser"
150 "homekit"
151 "homekit_controller"
152 "isal"
153 "mqtt"
154 "tasmota"
155 "wiz"
156 "google_translate"
157 "ecobee"
158 "ibeacon"
159 "go2rtc"
160 "generic"
161 ];
162 config = {
163 homeassistant = {
164 time_zone = "America/Toronto";
165 };
166 default_config = { };
167 zeroconf = { };
168 mqtt = { };
169 automation = [
170 {
171 id = "1766153071796";
172 alias = "Close Garage Door";
173 trigger = [
174 {
175 platform = "device";
176 device_id = "d8dedd8cd0ce1488d9830c455bb0a761";
177 domain = "cover";
178 entity_id = "cf36763543169888aa106b1acb02ad72";
179 type = "opened";
180 for = {
181 hours = 0;
182 minutes = 10;
183 seconds = 0;
184 };
185 }
186 ];
187 condition = [ ];
188 action = [
189 {
190 device_id = "d8dedd8cd0ce1488d9830c455bb0a761";
191 domain = "cover";
192 entity_id = "cf36763543169888aa106b1acb02ad72";
193 type = "close";
194 }
195 ];
196 mode = "single";
197 }
198 ];
199 };
200 };
201 };
202}