biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / applications / video / frigate / default.nix
blob7ee4f6eba606f57db732061f2b88897aab35d354
1 { lib
2 , callPackage
3 , python312
4 , fetchFromGitHub
5 , fetchurl
6 , frigate
7 , nixosTests
8 }:
10 let
11   version = "0.14.1";
13   src = fetchFromGitHub {
14     name = "frigate-${version}-source";
15     owner = "blakeblackshear";
16     repo = "frigate";
17     rev = "refs/tags/v${version}";
18     hash = "sha256-PfUlo9ua4SVcQJTfmSVoEXHH1MUJ8A/w3kJHFpEzll8=";
19   };
21   frigate-web = callPackage ./web.nix {
22     inherit version src;
23   };
25   python = python312.override {
26     self = python;
27     packageOverrides = self: super: {
28       paho-mqtt = super.paho-mqtt_2;
29     };
30   };
32   # Tensorflow Lite models
33   # https://github.com/blakeblackshear/frigate/blob/v0.13.0/docker/main/Dockerfile#L96-L97
34   tflite_cpu_model = fetchurl {
35     url = "https://github.com/google-coral/test_data/raw/release-frogfish/ssdlite_mobiledet_coco_qat_postprocess.tflite";
36     hash = "sha256-kLszpjTgQZFMwYGapd+ZgY5sOWxNLblSwP16nP/Eck8=";
37   };
38   tflite_edgetpu_model = fetchurl {
39     url = "https://github.com/google-coral/test_data/raw/release-frogfish/ssdlite_mobiledet_coco_qat_postprocess_edgetpu.tflite";
40     hash = "sha256-Siviu7YU5XbVbcuRT6UnUr8PE0EVEnENNV2X+qGzVkE=";
41   };
43   # OpenVino models
44   # https://github.com/blakeblackshear/frigate/blob/v0.13.0/docker/main/Dockerfile#L101
45   openvino_model = fetchurl {
46     url = "https://github.com/openvinotoolkit/open_model_zoo/raw/master/data/dataset_classes/coco_91cl_bkgr.txt";
47     hash = "sha256-5Cj2vEiWR8Z9d2xBmVoLZuNRv4UOuxHSGZQWTJorXUQ=";
48   };
50 python.pkgs.buildPythonApplication rec {
51   pname = "frigate";
52   inherit version;
53   format = "other";
55   inherit src;
57   postPatch = ''
58     echo 'VERSION = "${version}"' > frigate/version.py
60     substituteInPlace frigate/app.py \
61       --replace-fail "Router(migrate_db)" 'Router(migrate_db, "${placeholder "out"}/share/frigate/migrations")'
63     substituteInPlace frigate/const.py \
64       --replace-fail "/media/frigate" "/var/lib/frigate" \
65       --replace-fail "/tmp/cache" "/var/cache/frigate" \
66       --replace-fail "/config" "/var/lib/frigate" \
67       --replace-fail "{CONFIG_DIR}/model_cache" "/var/cache/frigate/model_cache"
69     substituteInPlace frigate/comms/{config,detections,events}_updater.py frigate/comms/inter_process.py \
70       --replace-fail "ipc:///tmp/cache" "ipc:///run/frigate"
72     substituteInPlace frigate/detectors/detector_config.py \
73       --replace-fail "/labelmap.txt" "${placeholder "out"}/share/frigate/labelmap.txt"
75     # work around onvif-zeep idiosyncrasy
76     substituteInPlace frigate/ptz/onvif.py \
77       --replace-fail dist-packages site-packages
79     substituteInPlace frigate/config.py \
80       --replace-fail "/cpu_model.tflite" "${tflite_cpu_model}" \
81       --replace-fail "/edgetpu_model.tflite" "${tflite_edgetpu_model}"
83     substituteInPlace frigate/test/test_config.py \
84       --replace-fail "(MODEL_CACHE_DIR" "('/build/model_cache'" \
85       --replace-fail "/config/model_cache" "/build/model_cache"
86   '';
88   dontBuild = true;
90   propagatedBuildInputs = with python.pkgs; [
91     # docker/main/requirements.txt
92     scikit-build
93     # docker/main/requirements-wheel.txt
94     click
95     distutils
96     flask
97     flask-limiter
98     imutils
99     joserfc
100     markupsafe
101     matplotlib
102     norfair
103     numpy
104     onvif-zeep
105     opencv4
106     openvino
107     pandas
108     paho-mqtt
109     peewee
110     peewee-migrate
111     psutil
112     py3nvml
113     pydantic
114     pytz
115     pyyaml
116     pyzmq
117     requests
118     ruamel-yaml
119     scipy
120     setproctitle
121     tensorflow-bin
122     tzlocal
123     unidecode
124     ws4py
125   ];
127   installPhase = ''
128     runHook preInstall
130     mkdir -p $out/${python.sitePackages}/frigate
131     cp -R frigate/* $out/${python.sitePackages}/frigate/
133     mkdir -p $out/share/frigate
134     cp -R {migrations,labelmap.txt} $out/share/frigate/
136     cp --no-preserve=mode ${openvino_model} $out/share/frigate/coco_91cl_bkgr.txt
137     sed -i 's/truck/car/g' $out/share/frigate/coco_91cl_bkgr.txt
139     runHook postInstall
140   '';
142   nativeCheckInputs = with python.pkgs; [
143     pytestCheckHook
144   ];
146   disabledTests = [
147     # Test needs network access
148     "test_plus_labelmap"
149   ];
151   passthru = {
152     web = frigate-web;
153     inherit python;
154     pythonPath =(python.pkgs.makePythonPath propagatedBuildInputs) + ":${frigate}/${python.sitePackages}";
155     tests = {
156       inherit (nixosTests) frigate;
157     };
158   };
160   meta = with lib; {
161     changelog = "https://github.com/blakeblackshear/frigate/releases/tag/v${version}";
162     description = "NVR with realtime local object detection for IP cameras";
163     longDescription = ''
164       A complete and local NVR designed for Home Assistant with AI
165       object detection. Uses OpenCV and Tensorflow to perform realtime
166       object detection locally for IP cameras.
167     '';
168     homepage = "https://github.com/blakeblackshear/frigate";
169     license = licenses.mit;
170     maintainers = with maintainers; [ hexa ];
171   };