chromium,chromedriver: 129.0.6668.91 -> 129.0.6668.100
[NixPkgs.git] / pkgs / by-name / im / immich-machine-learning / package.nix
blob94cc69f50ed1bb867655485dd18d421eae6abcdb
2   lib,
3   fetchFromGitHub,
4   immich,
5   python3,
6   nixosTests,
7 }:
8 let
9   python = python3.override {
10     self = python;
12     packageOverrides = self: super: {
13       pydantic = super.pydantic_1;
15       versioningit = super.versioningit.overridePythonAttrs (_: {
16         doCheck = false;
17       });
19       albumentations = super.albumentations.overridePythonAttrs (old: rec {
20         version = "1.4.3";
21         src = fetchFromGitHub {
22           owner = "albumentations-team";
23           repo = "albumentations";
24           rev = version;
25           hash = "sha256-JIBwjYaUP4Sc1bVM/zlj45cz9OWpb/LOBsIqk1m+sQA=";
26         };
27         dependencies = old.dependencies ++ [
28           self.scikit-learn
29         ];
30       });
31     };
32   };
34 python.pkgs.buildPythonApplication rec {
35   pname = "immich-machine-learning";
36   inherit (immich) version;
37   src = "${immich.src}/machine-learning";
38   pyproject = true;
40   postPatch = ''
41     substituteInPlace pyproject.toml --replace-fail 'fastapi-slim' 'fastapi'
43     # AttributeError: module 'cv2' has no attribute 'Mat'
44     substituteInPlace app/test_main.py --replace-fail ": cv2.Mat" ""
45   '';
47   pythonRelaxDeps = [ "setuptools" ];
48   pythonRemoveDeps = [ "opencv-python-headless" ];
50   build-system = with python.pkgs; [
51     poetry-core
52     cython
53   ];
55   dependencies =
56     with python.pkgs;
57     [
58       insightface
59       opencv4
60       pillow
61       fastapi
62       uvicorn
63       aiocache
64       rich
65       ftfy
66       setuptools
67       python-multipart
68       orjson
69       gunicorn
70       huggingface-hub
71       tokenizers
72       pydantic
73     ]
74     ++ uvicorn.optional-dependencies.standard;
76   nativeCheckInputs = with python.pkgs; [
77     httpx
78     pytest-asyncio
79     pytest-mock
80     pytestCheckHook
81   ];
83   postInstall = ''
84     mkdir -p $out/share/immich
85     cp log_conf.json $out/share/immich
87     cp -r ann $out/${python.sitePackages}/
89     makeWrapper ${lib.getExe python.pkgs.gunicorn} "''${!outputBin}"/bin/machine-learning \
90       --prefix PYTHONPATH : "$out/${python.sitePackages}:${python.pkgs.makePythonPath dependencies}" \
91       --set-default MACHINE_LEARNING_WORKERS 1 \
92       --set-default MACHINE_LEARNING_WORKER_TIMEOUT 120 \
93       --set-default MACHINE_LEARNING_CACHE_FOLDER /var/cache/immich \
94       --set-default IMMICH_HOST "[::]" \
95       --set-default IMMICH_PORT 3003 \
96       --add-flags "app.main:app -k app.config.CustomUvicornWorker \
97         -w \"\$MACHINE_LEARNING_WORKERS\" \
98         -b \"\$IMMICH_HOST:\$IMMICH_PORT\" \
99         -t \"\$MACHINE_LEARNING_WORKER_TIMEOUT\"
100         --log-config-json $out/share/immich/log_conf.json"
101   '';
103   passthru.tests = {
104     inherit (nixosTests) immich;
105   };
107   meta = {
108     description = "Self-hosted photo and video backup solution (machine learning component)";
109     homepage = "https://immich.app/";
110     license = lib.licenses.agpl3Only;
111     maintainers = with lib.maintainers; [ jvanbruegge ];
112     mainProgram = "machine-learning";
113     inherit (immich.meta) platforms;
114   };