1{
2 pkgs,
3 lib,
4 ...
5}:
6
7{
8 name = "frigate";
9 meta = { inherit (pkgs.frigate.meta) maintainers; };
10
11 nodes = {
12 machine = {
13 services.frigate = {
14 enable = true;
15
16 hostname = "localhost";
17
18 settings = {
19 mqtt.enabled = false;
20
21 cameras.test = {
22 ffmpeg = {
23 input_args = "-fflags nobuffer -strict experimental -fflags +genpts+discardcorrupt -r 10 -use_wallclock_as_timestamps 1";
24 inputs = [
25 {
26 path = "http://127.0.0.1:8080";
27 roles = [
28 "record"
29 ];
30 }
31 ];
32 };
33 };
34
35 record.enabled = true;
36 };
37 };
38
39 systemd.services.video-stream = {
40 description = "Start a test stream that frigate can capture";
41 before = [
42 "frigate.service"
43 ];
44 wantedBy = [
45 "multi-user.target"
46 ];
47 serviceConfig = {
48 DynamicUser = true;
49 ExecStart = "${lib.getExe pkgs.ffmpeg-headless} -re -f lavfi -i smptebars=size=1280x720:rate=5 -f mpegts -listen 1 http://0.0.0.0:8080";
50 Restart = "always";
51 };
52 };
53
54 environment.systemPackages = with pkgs; [ httpie ];
55 };
56 };
57
58 testScript = ''
59 start_all()
60
61 # wait until frigate is up
62 machine.wait_for_unit("frigate.service")
63 machine.wait_for_open_port(5001)
64
65 # extract admin password from logs
66 machine.wait_until_succeeds("journalctl -u frigate.service -o cat | grep -q 'Password: '")
67 password = machine.execute("journalctl -u frigate.service -o cat | grep -oP '([a-f0-9]{32})'")[1]
68
69 # login and store session
70 machine.log(machine.succeed(f"http --check-status --session=frigate post http://localhost/api/login user=admin password={password}"))
71
72 # make authenticated api request
73 machine.log(machine.succeed("http --check-status --session=frigate get http://localhost/api/version"))
74
75 # make unauthenticated api request
76 machine.log(machine.succeed("http --check-status get http://localhost:5000/api/version"))
77
78 # wait for a recording to appear
79 machine.wait_for_file("/var/cache/frigate/test@*.mp4")
80 '';
81}