From 7c659746767ae1b8fca38e8f838fe023010df750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Tue, 24 Sep 2024 08:55:10 -0700 Subject: [PATCH 1/5] immich.machine-learning: drop packageOverrides argument There is no need for it and it cannot be used to override the machine learning component used by the immich package. --- pkgs/by-name/im/immich/machine-learning.nix | 41 +++++++++------------ 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/pkgs/by-name/im/immich/machine-learning.nix b/pkgs/by-name/im/immich/machine-learning.nix index 7a6451825118..5217518ff17a 100644 --- a/pkgs/by-name/im/immich/machine-learning.nix +++ b/pkgs/by-name/im/immich/machine-learning.nix @@ -4,33 +4,28 @@ fetchFromGitHub, immich, python3, - # Override Python packages using - # self: super: { pkg = super.pkg.overridePythonAttrs (oldAttrs: { ... }); } - # Applied after defaultOverrides - packageOverrides ? self: super: { }, }: let - defaultOverrides = self: super: { - pydantic = super.pydantic_1; - - versioningit = super.versioningit.overridePythonAttrs (_: { - doCheck = false; - }); - - albumentations = super.albumentations.overridePythonAttrs (_: rec { - version = "1.4.3"; - src = fetchFromGitHub { - owner = "albumentations-team"; - repo = "albumentations"; - rev = version; - hash = "sha256-JIBwjYaUP4Sc1bVM/zlj45cz9OWpb/LOBsIqk1m+sQA="; - }; - }); - }; - python = python3.override { self = python; - packageOverrides = lib.composeExtensions defaultOverrides packageOverrides; + + packageOverrides = self: super: { + pydantic = super.pydantic_1; + + versioningit = super.versioningit.overridePythonAttrs (_: { + doCheck = false; + }); + + albumentations = super.albumentations.overridePythonAttrs (_: rec { + version = "1.4.3"; + src = fetchFromGitHub { + owner = "albumentations-team"; + repo = "albumentations"; + rev = version; + hash = "sha256-JIBwjYaUP4Sc1bVM/zlj45cz9OWpb/LOBsIqk1m+sQA="; + }; + }); + }; }; in python.pkgs.buildPythonApplication { From 797b7e1ce7115a08b476fcc85dec675f6eb15fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Tue, 24 Sep 2024 08:57:31 -0700 Subject: [PATCH 2/5] immich: clean up after update script --- pkgs/by-name/im/immich/update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/im/immich/update.sh b/pkgs/by-name/im/immich/update.sh index 1558577b8b60..a1a5e2e0585c 100755 --- a/pkgs/by-name/im/immich/update.sh +++ b/pkgs/by-name/im/immich/update.sh @@ -41,4 +41,4 @@ for npm_component in cli server web "open-api/typescript-sdk"; do done rm "$lock" -cp "$sources_tmp" sources.json +mv "$sources_tmp" sources.json From 2b4480d1611182ff31c0d29fdcd862f1ce417e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Tue, 24 Sep 2024 09:11:11 -0700 Subject: [PATCH 3/5] immich-machine-learning: move from immich.machine-learning A top-level attribute makes sure Hydra builds it (though that already happens on Linux through the NixOS test) and that nixpkgs-review picks it up. --- .../package.nix} | 3 +-- pkgs/by-name/im/immich/package.nix | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) rename pkgs/by-name/im/{immich/machine-learning.nix => immich-machine-learning/package.nix} (98%) diff --git a/pkgs/by-name/im/immich/machine-learning.nix b/pkgs/by-name/im/immich-machine-learning/package.nix similarity index 98% rename from pkgs/by-name/im/immich/machine-learning.nix rename to pkgs/by-name/im/immich-machine-learning/package.nix index 5217518ff17a..b5e15c6d040b 100644 --- a/pkgs/by-name/im/immich/machine-learning.nix +++ b/pkgs/by-name/im/immich-machine-learning/package.nix @@ -1,6 +1,5 @@ { lib, - src, fetchFromGitHub, immich, python3, @@ -31,7 +30,7 @@ in python.pkgs.buildPythonApplication { pname = "immich-machine-learning"; inherit (immich) version; - src = "${src}/machine-learning"; + src = "${immich.src}/machine-learning"; pyproject = true; postPatch = '' diff --git a/pkgs/by-name/im/immich/package.nix b/pkgs/by-name/im/immich/package.nix index ea64fd65945c..fe62f0ddc354 100644 --- a/pkgs/by-name/im/immich/package.nix +++ b/pkgs/by-name/im/immich/package.nix @@ -8,7 +8,7 @@ node-gyp, runCommand, nixosTests, - callPackage, + immich-machine-learning, # build-time deps glib, pkg-config, @@ -210,7 +210,7 @@ buildNpmPackage' { inherit (nixosTests) immich; }; - machine-learning = callPackage ./machine-learning.nix { inherit src; }; + machine-learning = immich-machine-learning; inherit src From 7cdda564e00cca1a146df5620daff06bd7db664e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Tue, 24 Sep 2024 09:53:24 -0700 Subject: [PATCH 4/5] nixos/immich: override machine-learning with cfg.package Otherwise they could use different versions: nix-repl> (immich.overrideAttrs { version = "0"; }).machine-learning.version "1.115.0" --- nixos/modules/services/web-apps/immich.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/web-apps/immich.nix b/nixos/modules/services/web-apps/immich.nix index 1e46f3b855df..ca6b6dd62413 100644 --- a/nixos/modules/services/web-apps/immich.nix +++ b/nixos/modules/services/web-apps/immich.nix @@ -290,7 +290,7 @@ in wantedBy = [ "multi-user.target" ]; inherit (cfg.machine-learning) environment; serviceConfig = commonServiceConfig // { - ExecStart = lib.getExe cfg.package.machine-learning; + ExecStart = lib.getExe (cfg.package.machine-learning.override { immich = cfg.package; }); CacheDirectory = "immich"; User = cfg.user; Group = cfg.group; From ce46c05311c483b0196a252a659e61e4f128359f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Tue, 24 Sep 2024 11:05:13 -0700 Subject: [PATCH 5/5] immich-machine-learning: run tests --- pkgs/by-name/im/immich-machine-learning/package.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/im/immich-machine-learning/package.nix b/pkgs/by-name/im/immich-machine-learning/package.nix index b5e15c6d040b..5b35ecfaea04 100644 --- a/pkgs/by-name/im/immich-machine-learning/package.nix +++ b/pkgs/by-name/im/immich-machine-learning/package.nix @@ -35,6 +35,9 @@ python.pkgs.buildPythonApplication { postPatch = '' substituteInPlace pyproject.toml --replace-fail 'fastapi-slim' 'fastapi' + + # AttributeError: module 'cv2' has no attribute 'Mat' + substituteInPlace app/test_main.py --replace-fail ": cv2.Mat" "" ''; pythonRelaxDeps = [ "setuptools" ]; @@ -66,7 +69,12 @@ python.pkgs.buildPythonApplication { ] ++ uvicorn.optional-dependencies.standard; - doCheck = false; + nativeCheckInputs = with python.pkgs; [ + httpx + pytest-asyncio + pytest-mock + pytestCheckHook + ]; postInstall = '' mkdir -p $out/share/immich