Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nextcloud: add recognize app #333545

Merged
merged 14 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions pkgs/servers/nextcloud/packages/apps/recognize.nix
Original file line number Diff line number Diff line change
@@ -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,
beardhatcode marked this conversation as resolved.
Show resolved Hide resolved

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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo snuck in here:

pname = "nextcloud-app-recognize";

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'" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--replace-quiet "\$this->config->getAppValueString('node_binary', '""')" "'${nodejs}/bin/node'" \
--replace-quiet "\$this->config->getAppValueString('node_binary', '""')" "'${lib.getExe nodejs}'" \

--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'"
beardhatcode marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ln -s ${ffmpeg}/bin/ffmpeg recognize/node_modules/ffmpeg-static/ffmpeg
ln -s ${lib.getExe ffmpeg} recognize/node_modules/ffmpeg-static/ffmpeg

'';

nativeBuildInputs = lib.optionals useLibTensorflow [
nodejs
nodejs.pkgs.node-pre-gyp
nodejs.pkgs.node-gyp
Comment on lines +100 to +101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are only aliases for top-level attributes.

Suggested change
nodejs.pkgs.node-pre-gyp
nodejs.pkgs.node-gyp
node-pre-gyp
node-gyp

python3
util-linux
];

buildPhase = lib.optionalString useLibTensorflow ''
cd recognize

# Install tfjs dependency
export CPPFLAGS="-I${nodejs}/include/node -Ideps/include"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export CPPFLAGS="-I${nodejs}/include/node -Ideps/include"
export CPPFLAGS="-I${lib.getDev 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";
};
}
5 changes: 3 additions & 2 deletions pkgs/servers/nextcloud/packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
lib,
pkgs,
newScope,
apps,
callPackage,
ncVersion,
}:

let
apps = lib.importJSON (./. + "/${ncVersion}.json");
packages =
self:
let
Expand Down Expand Up @@ -55,5 +56,5 @@ let

in
(lib.makeExtensible (_: (lib.makeScope newScope packages))).extend (
import ./thirdparty.nix
import ./thirdparty.nix { inherit ncVersion; }
)
2 changes: 2 additions & 0 deletions pkgs/servers/nextcloud/packages/thirdparty.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ ncVersion }:
_:
{ apps, callPackage, ... }:
{
Expand All @@ -6,6 +7,7 @@ _:
self: super: {

hmr_enabler = callPackage ./apps/hmr_enabler.nix { };
recognize = callPackage ./apps/recognize.nix { inherit ncVersion; };

}
);
Expand Down
12 changes: 3 additions & 9 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4531,15 +4531,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 { };

Expand Down
Loading