nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 249 lines 7.5 kB view raw
1{ 2 lib, 3 stdenv, 4 callPackage, 5 python313Packages, 6 fetchFromGitHub, 7 fetchurl, 8 ffmpeg-headless, 9 sqlite-vec, 10 frigate, 11 nixosTests, 12 fetchpatch, 13}: 14 15let 16 version = "0.16.4"; 17 18 src = fetchFromGitHub { 19 name = "frigate-${version}-source"; 20 owner = "blakeblackshear"; 21 repo = "frigate"; 22 tag = "v${version}"; 23 hash = "sha256-TPiCT/z0YuoQkQsxyZsRMQa0XwqMLCgwMbrASOKrMjA="; 24 }; 25 26 frigate-web = callPackage ./web.nix { 27 inherit version src; 28 }; 29 30 python = python313Packages.python.override { 31 packageOverrides = self: super: { 32 joserfc = super.joserfc.overridePythonAttrs (oldAttrs: { 33 version = "1.1.0"; 34 src = fetchFromGitHub { 35 owner = "authlib"; 36 repo = "joserfc"; 37 tag = version; 38 hash = "sha256-95xtUzzIxxvDtpHX/5uCHnTQTB8Fc08DZGUOR/SdKLs="; 39 }; 40 }); 41 }; 42 }; 43 python3Packages = python.pkgs; 44 45 # Tensorflow audio model 46 # https://github.com/blakeblackshear/frigate/blob/v0.15.0/docker/main/Dockerfile#L125 47 tflite_audio_model = fetchurl { 48 url = "https://www.kaggle.com/api/v1/models/google/yamnet/tfLite/classification-tflite/1/download"; 49 hash = "sha256-G5cbITJ2AnOl+49dxQToZ4OyeFO7MTXVVa4G8eHjZfM="; 50 }; 51 52 # Tensorflow Lite models 53 # https://github.com/blakeblackshear/frigate/blob/v0.15.0/docker/main/Dockerfile#L115-L117 54 tflite_cpu_model = fetchurl { 55 url = "https://github.com/google-coral/test_data/raw/release-frogfish/ssdlite_mobiledet_coco_qat_postprocess.tflite"; 56 hash = "sha256-kLszpjTgQZFMwYGapd+ZgY5sOWxNLblSwP16nP/Eck8="; 57 }; 58 tflite_edgetpu_model = fetchurl { 59 url = "https://github.com/google-coral/test_data/raw/release-frogfish/ssdlite_mobiledet_coco_qat_postprocess_edgetpu.tflite"; 60 hash = "sha256-Siviu7YU5XbVbcuRT6UnUr8PE0EVEnENNV2X+qGzVkE="; 61 }; 62 63 # TODO: OpenVino model 64 # https://github.com/blakeblackshear/frigate/blob/v0.15.0/docker/main/Dockerfile#L64-L77 65 # https://github.com/blakeblackshear/frigate/blob/v0.15.0/docker/main/Dockerfile#L120-L123 66 # Convert https://www.kaggle.com/models/tensorflow/ssdlite-mobilenet-v2 with https://github.com/blakeblackshear/frigate/blob/v0.15.0/docker/main/build_ov_model.py into OpenVino IR format 67 coco_91cl_bkgr = fetchurl { 68 url = "https://github.com/openvinotoolkit/open_model_zoo/raw/master/data/dataset_classes/coco_91cl_bkgr.txt"; 69 hash = "sha256-5Cj2vEiWR8Z9d2xBmVoLZuNRv4UOuxHSGZQWTJorXUQ="; 70 }; 71in 72python3Packages.buildPythonApplication rec { 73 pname = "frigate"; 74 inherit version; 75 pyproject = false; 76 77 inherit src; 78 79 patches = [ 80 ./constants.patch 81 # Fixes hardcoded path /media/frigate/clips/faces. Remove in next version. 82 (fetchpatch { 83 url = "https://github.com/blakeblackshear/frigate/commit/b86e6e484f64bd43b64d7adebe78671a7a426edb.patch"; 84 hash = "sha256-1+n0n0yCtjfAHkXzsZdIF0iCVdPGmsG7l8/VTqBVEjU="; 85 }) 86 ./ffmpeg.patch 87 ./ai-edge-litert.patch 88 ]; 89 90 postPatch = '' 91 echo 'VERSION = "${version}"' > frigate/version.py 92 93 substituteInPlace \ 94 frigate/app.py \ 95 frigate/test/test_{http,storage}.py \ 96 frigate/test/http_api/base_http_test.py \ 97 --replace-fail "Router(migrate_db)" 'Router(migrate_db, "${placeholder "out"}/share/frigate/migrations")' 98 99 substituteInPlace frigate/const.py \ 100 --replace-fail "/opt/frigate" "${placeholder "out"}/${python.sitePackages}" \ 101 --replace-fail "/media/frigate" "/var/lib/frigate" \ 102 --replace-fail "/tmp/cache" "/var/cache/frigate" \ 103 --replace-fail "/config" "/var/lib/frigate" \ 104 --replace-fail "{CONFIG_DIR}/model_cache" "/var/cache/frigate/model_cache" 105 106 substituteInPlace frigate/comms/{config,embeddings}_updater.py frigate/comms/{zmq_proxy,inter_process}.py \ 107 --replace-fail "ipc:///tmp/cache" "ipc:///run/frigate" 108 109 substituteInPlace frigate/db/sqlitevecq.py \ 110 --replace-fail "/usr/local/lib/vec0" "${lib.getLib sqlite-vec}/lib/vec0${stdenv.hostPlatform.extensions.sharedLibrary}" 111 112 # provide default paths for models and maps that are shipped with frigate 113 substituteInPlace frigate/config/config.py \ 114 --replace-fail "/cpu_model.tflite" "${tflite_cpu_model}" \ 115 --replace-fail "/edgetpu_model.tflite" "${tflite_edgetpu_model}" 116 117 substituteInPlace frigate/detectors/detector_config.py \ 118 --replace-fail "/labelmap.txt" "${placeholder "out"}/share/frigate/labelmap.txt" 119 120 substituteInPlace frigate/events/audio.py \ 121 --replace-fail "/cpu_audio_model.tflite" "${placeholder "out"}/share/frigate/cpu_audio_model.tflite" \ 122 --replace-fail "/audio-labelmap.txt" "${placeholder "out"}/share/frigate/audio-labelmap.txt" 123 ''; 124 125 dontBuild = true; 126 127 dependencies = with python3Packages; [ 128 # docker/main/requirements.txt 129 scikit-build 130 # docker/main/requirements-wheel.txt 131 ai-edge-litert 132 aiofiles 133 aiohttp 134 appdirs 135 argcomplete 136 contextlib2 137 click 138 distlib 139 fastapi 140 filelock 141 importlib-metadata 142 importlib-resources 143 google-generativeai 144 joserfc 145 levenshtein 146 markupsafe 147 netaddr 148 netifaces 149 norfair 150 numpy 151 ollama 152 onnxruntime 153 onvif-zeep-async 154 openai 155 opencv4 156 openvino 157 paho-mqtt 158 pandas 159 pathvalidate 160 peewee 161 peewee-migrate 162 prometheus-client 163 psutil 164 py3nvml 165 pyclipper 166 pydantic 167 python-multipart 168 pytz 169 py-vapid 170 pywebpush 171 pyzmq 172 requests 173 ruamel-yaml 174 scipy 175 setproctitle 176 shapely 177 slowapi 178 starlette 179 starlette-context 180 titlecase 181 transformers 182 tzlocal 183 unidecode 184 uvicorn 185 verboselogs 186 virtualenv 187 ws4py 188 ]; 189 190 installPhase = '' 191 runHook preInstall 192 193 mkdir -p $out/${python.sitePackages}/frigate 194 cp -R frigate/* $out/${python.sitePackages}/frigate/ 195 196 mkdir -p $out/share/frigate 197 cp -R {migrations,labelmap.txt,audio-labelmap.txt} $out/share/frigate/ 198 199 tar --extract --gzip --file ${tflite_audio_model} 200 cp --no-preserve=mode ./1.tflite $out/share/frigate/cpu_audio_model.tflite 201 202 cp --no-preserve=mode ${coco_91cl_bkgr} $out/share/frigate/coco_91cl_bkgr.txt 203 sed -i 's/truck/car/g' $out/share/frigate/coco_91cl_bkgr.txt 204 205 runHook postInstall 206 ''; 207 208 nativeCheckInputs = with python3Packages; [ 209 ffmpeg-headless 210 pytestCheckHook 211 ]; 212 213 # interpreter crash in onnxruntime on aarch64-linux 214 doCheck = !(stdenv.hostPlatform.system == "aarch64-linux"); 215 216 preCheck = '' 217 # Unavailable in the build sandbox 218 substituteInPlace frigate/const.py \ 219 --replace-fail "/var/lib/frigate" "$TMPDIR/" \ 220 --replace-fail "/var/cache/frigate" "$TMPDIR" 221 ''; 222 223 disabledTests = [ 224 # Test needs network access 225 "test_plus_labelmap" 226 ]; 227 228 passthru = { 229 web = frigate-web; 230 inherit python; 231 pythonPath = (python3Packages.makePythonPath dependencies) + ":${frigate}/${python.sitePackages}"; 232 tests = { 233 inherit (nixosTests) frigate; 234 }; 235 }; 236 237 meta = { 238 changelog = "https://github.com/blakeblackshear/frigate/releases/tag/${src.tag}"; 239 description = "NVR with realtime local object detection for IP cameras"; 240 longDescription = '' 241 A complete and local NVR designed for Home Assistant with AI 242 object detection. Uses OpenCV and Tensorflow to perform realtime 243 object detection locally for IP cameras. 244 ''; 245 homepage = "https://github.com/blakeblackshear/frigate"; 246 license = lib.licenses.mit; 247 maintainers = with lib.maintainers; [ hexa ]; 248 }; 249}