diff --git a/pkgs/servers/nextcloud/packages/apps/recognize.nix b/pkgs/servers/nextcloud/packages/apps/recognize.nix new file mode 100644 index 0000000000000..d72fb41600dd2 --- /dev/null +++ b/pkgs/servers/nextcloud/packages/apps/recognize.nix @@ -0,0 +1,137 @@ +{ + stdenv, + fetchurl, + lib, + nodejs, + python3, + util-linux, + ffmpeg, + + # Current derivation only suports linux-x86_64 (contributions welcome, without libTensorflow builtin webassembly can be used) + useLibTensorflow ? stdenv.isx86_64 && stdenv.isLinux, + + ncVersion, +}: +let + latestVersionForNc = { + "30" = { + version = "8.2.0"; + appHash = "sha256-CAORqBdxNQ0x+xIVY2zI07jvsKHaa7eH0jpVuP0eSW4="; + modelHash = "sha256-s8MQOLU490/Vr/U4GaGlbdrykOAQOKeWE5+tCzn6Dew="; + }; + "29" = { + version = "7.1.0"; + appHash = "sha256-qR4SrTHFAc4YWiZAsL94XcH4VZqYtkRLa0y+NdiFZus="; + modelHash = "sha256-M/j5wVOBLR7xMVJQWDUWAzLajRUBYEzHSNBsRSBUgfM="; + }; + "28" = { + # Once this version is no longer supported, we can remove the getAppValue replacements below + # The getAppValueString stuff will need to remain + version = "6.1.0"; + appHash = "sha256-225r2JnDOoURvLmzpmHp/QL6GDx9124/YTywbxH3/rk="; + modelHash = "sha256-4mhQM/ajpwjqTb8jSbEIdtSRrWZEOaMZQXAwcfSRQ/M="; + }; + }; + currentVersionInfo = latestVersionForNc.${ncVersion}; +in +stdenv.mkDerivation rec { + + pname = "nextcloud-app-recognise"; + version = currentVersionInfo.version; + + srcs = + [ + (fetchurl { + inherit version; + url = "https://github.com/nextcloud/recognize/releases/download/v${version}/recognize-${version}.tar.gz"; + hash = currentVersionInfo.appHash; + }) + + (fetchurl { + inherit version; + url = "https://github.com/nextcloud/recognize/archive/refs/tags/v${version}.tar.gz"; + hash = currentVersionInfo.modelHash; + }) + ] + ++ lib.optionals useLibTensorflow [ + (fetchurl rec { + # For version see LIBTENSORFLOW_VERSION in https://github.com/tensorflow/tfjs/blob/master/tfjs-node/scripts/deps-constants.js + version = "2.9.1"; + url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-${version}.tar.gz"; + hash = "sha256-f1ENJUbj214QsdEZRjaJAD1YeEKJKtPJW8pRz4KCAXM="; + }) + ]; + + unpackPhase = + '' + # Merge the app and the models from github + tar -xzpf "${builtins.elemAt srcs 0}" recognize; + tar -xzpf "${builtins.elemAt srcs 1}" -C recognize --strip-components=1 recognize-${version}/models + '' + + lib.optionalString useLibTensorflow '' + # Place the tensorflow lib at the right place for building + tar -xzpf "${builtins.elemAt srcs 2}" -C recognize/node_modules/@tensorflow/tfjs-node/deps + ''; + + postPatch = '' + # Make it clear we are not reading the node in settings + sed -i "/'node_binary'/s:'""':'Nix Controled':" recognize/lib/Service/SettingsService.php + + # Replace all occurences of node (and check that we actually remved them all) + test "$(grep "get[a-zA-Z]*('node_binary'" recognize/lib/**/*.php | wc -l)" -gt 0 + substituteInPlace recognize/lib/**/*.php \ + --replace-quiet "\$this->settingsService->getSetting('node_binary')" "'${nodejs}/bin/node'" \ + --replace-quiet "\$this->config->getAppValueString('node_binary', '""')" "'${nodejs}/bin/node'" \ + --replace-quiet "\$this->config->getAppValueString('node_binary')" "'${nodejs}/bin/node'" \ + --replace-quiet "\$this->config->getAppValue('node_binary', '""')" "'${nodejs}/bin/node'" \ + --replace-quiet "\$this->config->getAppValue('node_binary')" "'${nodejs}/bin/node'" + test "$(grep "get[a-zA-Z]*('node_binary'" recognize/lib/**/*.php | wc -l)" -eq 0 + + + + # Skip trying to install it... (less warnings in the log) + sed -i '/public function run/areturn ; //skip' recognize/lib/Migration/InstallDeps.php + + ln -s ${ffmpeg}/bin/ffmpeg recognize/node_modules/ffmpeg-static/ffmpeg + ''; + + nativeBuildInputs = lib.optionals useLibTensorflow [ + nodejs + nodejs.pkgs.node-pre-gyp + nodejs.pkgs.node-gyp + python3 + util-linux + ]; + + buildPhase = lib.optionalString useLibTensorflow '' + cd recognize + + # Install tfjs dependency + export CPPFLAGS="-I${nodejs}/include/node -Ideps/include" + cd node_modules/@tensorflow/tfjs-node + node-pre-gyp install --prefer-offline --build-from-source --nodedir=${nodejs}/include/node + cd - + + # Test tfjs returns exit code 0 + node src/test_libtensorflow.js + cd .. + ''; + installPhase = '' + approot="$(dirname $(dirname $(find -path '*/appinfo/info.xml' | head -n 1)))" + if [ -d "$approot" ]; + then + mv "$approot/" $out + chmod -R a-w $out + fi + ''; + + meta = with lib; { + license = licenses.agpl3Only; + maintainers = with maintainers; [ beardhatcode ]; + longDescription = '' + Nextcloud app that does Smart media tagging and face recognition with on-premises machine learning models. + This app goes through your media collection and adds fitting tags, automatically categorizing your photos and music. + ''; + homepage = "https://apps.nextcloud.com/apps/recognize"; + }; +} diff --git a/pkgs/servers/nextcloud/packages/default.nix b/pkgs/servers/nextcloud/packages/default.nix index 7158bf8a2d0a8..24eeec3c5557b 100644 --- a/pkgs/servers/nextcloud/packages/default.nix +++ b/pkgs/servers/nextcloud/packages/default.nix @@ -6,11 +6,12 @@ lib, pkgs, newScope, - apps, callPackage, + ncVersion, }: let + apps = lib.importJSON (./. + "/${ncVersion}.json"); packages = self: let @@ -55,5 +56,5 @@ let in (lib.makeExtensible (_: (lib.makeScope newScope packages))).extend ( - import ./thirdparty.nix + import ./thirdparty.nix { inherit ncVersion; } ) diff --git a/pkgs/servers/nextcloud/packages/thirdparty.nix b/pkgs/servers/nextcloud/packages/thirdparty.nix index bcf151bc93f0b..6ea612cf9ec66 100644 --- a/pkgs/servers/nextcloud/packages/thirdparty.nix +++ b/pkgs/servers/nextcloud/packages/thirdparty.nix @@ -1,3 +1,4 @@ +{ ncVersion }: _: { apps, callPackage, ... }: { @@ -6,6 +7,7 @@ _: self: super: { hmr_enabler = callPackage ./apps/hmr_enabler.nix { }; + recognize = callPackage ./apps/recognize.nix { inherit ncVersion; }; } ); diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index bda70a305edbe..fdeeda49613ea 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -4468,15 +4468,9 @@ with pkgs; inherit (callPackages ../servers/nextcloud {}) nextcloud28 nextcloud29 nextcloud30; - nextcloud28Packages = callPackage ../servers/nextcloud/packages { - apps = lib.importJSON ../servers/nextcloud/packages/28.json; - }; - nextcloud29Packages = callPackage ../servers/nextcloud/packages { - apps = lib.importJSON ../servers/nextcloud/packages/29.json; - }; - nextcloud30Packages = callPackage ../servers/nextcloud/packages { - apps = lib.importJSON ../servers/nextcloud/packages/30.json; - }; + nextcloud28Packages = callPackage ../servers/nextcloud/packages { ncVersion = "28"; }; + nextcloud29Packages = callPackage ../servers/nextcloud/packages { ncVersion = "29"; }; + nextcloud30Packages = callPackage ../servers/nextcloud/packages { ncVersion = "30"; }; nextcloud-client = qt6Packages.callPackage ../applications/networking/nextcloud-client { };