lock: 1.3.0 -> 1.3.4 (#364295)
[NixPkgs.git] / pkgs / by-name / im / immich-machine-learning / package.nix
blobe7bf36be81821461f540fae00645e81e5a793b3b
2   lib,
3   fetchFromGitHub,
4   immich,
5   python3,
6   nixosTests,
7   stdenv,
8 }:
9 let
10   python = python3.override {
11     self = python;
12   };
14 python.pkgs.buildPythonApplication rec {
15   pname = "immich-machine-learning";
16   inherit (immich) version;
17   src = "${immich.src}/machine-learning";
18   pyproject = true;
20   pythonRelaxDeps = [
21     "pillow"
22     "pydantic-settings"
23   ];
25   build-system = with python.pkgs; [
26     poetry-core
27     cython
28   ];
30   dependencies =
31     with python.pkgs;
32     [
33       insightface
34       opencv-python-headless
35       pillow
36       fastapi
37       uvicorn
38       pydantic
39       pydantic-settings
40       aiocache
41       rich
42       ftfy
43       python-multipart
44       orjson
45       gunicorn
46       huggingface-hub
47       tokenizers
48     ]
49     ++ uvicorn.optional-dependencies.standard;
51   # aarch64-linux tries to get cpu information from /sys, which isn't available
52   # inside the nix build sandbox.
53   doCheck = stdenv.buildPlatform.system != "aarch64-linux";
55   nativeCheckInputs = with python.pkgs; [
56     httpx
57     pytest-asyncio
58     pytest-mock
59     pytestCheckHook
60   ];
62   postInstall = ''
63     mkdir -p $out/share/immich
64     cp log_conf.json $out/share/immich
66     cp -r ann $out/${python.sitePackages}/
68     makeWrapper ${lib.getExe python.pkgs.gunicorn} "''${!outputBin}"/bin/machine-learning \
69       --prefix PYTHONPATH : "$out/${python.sitePackages}:${python.pkgs.makePythonPath dependencies}" \
70       --set-default MACHINE_LEARNING_WORKERS 1 \
71       --set-default MACHINE_LEARNING_WORKER_TIMEOUT 120 \
72       --set-default MACHINE_LEARNING_CACHE_FOLDER /var/cache/immich \
73       --set-default IMMICH_HOST "[::]" \
74       --set-default IMMICH_PORT 3003 \
75       --add-flags "app.main:app -k app.config.CustomUvicornWorker \
76         -w \"\$MACHINE_LEARNING_WORKERS\" \
77         -b \"\$IMMICH_HOST:\$IMMICH_PORT\" \
78         -t \"\$MACHINE_LEARNING_WORKER_TIMEOUT\"
79         --log-config-json $out/share/immich/log_conf.json"
80   '';
82   passthru.tests = {
83     inherit (nixosTests) immich;
84   };
86   meta = {
87     description = "${immich.meta.description} (machine learning component)";
88     homepage = "https://github.com/immich-app/immich/tree/main/machine-learning";
89     mainProgram = "machine-learning";
90     inherit (immich.meta) license maintainers platforms;
91   };