-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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
nextcloud: add recognize app #333545
Conversation
2c18298
to
d37b446
Compare
Related PR: #211631 |
pkgs/servers/nextcloud/packages/adapted/nextcloud-app-recognize.nix
Outdated
Show resolved
Hide resolved
pkgs/servers/nextcloud/packages/adapted/nextcloud-app-recognize.nix
Outdated
Show resolved
Hide resolved
pkgs/servers/nextcloud/packages/adapted/nextcloud-app-recognize.nix
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we don't need something like https://github.com/NuschtOS/nixos-modules/blob/da5286bc062adee0e0aaf2bd3b784b477c623422/modules/nextcloud.nix#L172-L183 but still https://github.com/NuschtOS/nixos-modules/blob/da5286bc062adee0e0aaf2bd3b784b477c623422/modules/nextcloud.nix#L210-L217 ?
To be clear: I'm very, very 👎 on doing any build steps at runtime.
I expect the JS code to be built correctly and to have the settings patched by this package to point to other Nix packages (I.e. node, ffmpeg etc.). I looked through those super-questionable[0] "migration" "steps"[1] and I really don't want to rely on any of that.
[0] to say the least
[1] https://github.com/nextcloud/recognize/blob/main/lib/Migration/InstallDeps.php
I was planning to wrap the |
I'm also going to add a third party app to the package set #328634 |
I don't use declerative nextcloud apps, so I must do it like this. So we want to patch the app before in nextcloudApps. |
That's OK, my comment was strictly about what I'd like to see (or not see) in nixpkgs.
Most likely yes. |
We managed to package third-party apps in #328634 So you can add your derivation into |
d37b446
to
c7ada99
Compare
Rebased on that. This app is not really third-party however. Unfortunately, I'm still unable to get the tfjs stuff to compile under nix as this thing seems to insist on downloading stuff. So I'm still stuck on:
If anyone knows how to fix it, that would be much appreciated. |
Yeah, we should probably change the naming. |
Yea, I think that should be possible. I'd like to first get the tfjs node thing working. Because atm, what I have looks horrible, and it does not even work: {
stdenv,
fetchurl,
lib,
nodejs,
python311,
python311Packages,
util-linux, # needed?
...
}:
stdenv.mkDerivation rec {
pname = "nextcloud-app-recognise";
version = "6.0.1";
srcs = [
(fetchurl {
inherit version;
url = "https://github.com/nextcloud/recognize/releases/download/v${version}/recognize-${version}.tar.gz";
hash = "sha256-HQHfcQY2N6INLfaLDWbWn0SSzvkSZqL0rPl2koqej6c=";
})
(fetchurl {
inherit version;
url = "https://github.com/nextcloud/recognize/archive/refs/tags/v${version}.tar.gz";
hash = "sha256-4iJVKz/HfzIUouiOK/NUkJUm4+p9meVptQwJ4OG1JaU=";
})
(fetchurl {
inherit version;
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.9.1.tar.gz";
hash = "sha256-f1ENJUbj214QsdEZRjaJAD1YeEKJKtPJW8pRz4KCAXM=";
})
(fetchurl {
inherit version;
url = "https://nodejs.org/download/release/v20.15.1/node-v20.15.1-headers.tar.gz";
hash = "sha256-jCMFxt9dFFJeBxHw2jgpVgCYffTCcQxzjAFACGKhdrQ=";
})
];
unpackPhase = ''
tar -xzpf "${builtins.elemAt srcs 0}" recognize;
tar -xzpf "${builtins.elemAt srcs 1}" recognize-${version}/models;
mv recognize-${version}/models recognize
#cd recognize/node_modules/@tensorflow/tfjs-node/deps
#tar -xzpf "${builtins.elemAt srcs 2}"
#cd -
cd recognize/node_modules/@tensorflow/tfjs-node/lib
tar -xzpf "${builtins.elemAt srcs 3}"
cd -
# recognize/node_modules/@tensorflow/tfjs-node/deps/lib/libtensorflow.so.2.9.1
'';
buildInputs = [
nodejs
nodejs.pkgs.node-pre-gyp
nodejs.pkgs.node-gyp
python311
util-linux
];
buildPhase = ''
mkdir tmphome
export HOME="$(realpath tmphome)"
sed -i "/'node_binary'/s:'""':'${nodejs}/bin/node':" recognize/lib/Service/SettingsService.php
cd recognize
set -x
#ln -sf -t node_modules/@tensorflow/tfjs-node/deps ${python311Packages.tensorflow}/*
ls node_modules/@tensorflow/tfjs-node/deps
export CPPFLAGS="-I${nodejs}/include/node -Ideps/include -I${python311Packages.tensorflow}/lib/python3.11/site-packages/tensorflow/include"
cd node_modules/@tensorflow/tfjs-node
echo "===="
ls deps/include
echo "===="
node-pre-gyp install --prefer-offline --build-from-source --nodedir=${nodejs}/include/node
cd -
#npm rebuild --prefer-offline @tensorflow/tfjs-node --build-addon-from-source
${nodejs}/bin/node src/test_libtensorflow.js
set +x
exit 1
cd -
'';
installPhase = ''
set -x
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";
};
} |
@beardhatcode I assume you already saw the hacky workaround in this comment? If not, I figured it might be useful to make the node tfjs thing build. |
Yes I did, but I would like something reproducible. It must be possible. |
31abb08
to
5043312
Compare
@Ma27 and @SuperSandro2000 , for me, this PR is complete (unless there is something I missed). |
Skimmed over it last week and it looks good so far. |
Has been working for me on my server for a couple of weeks now |
I added support for older Nextclouds as well now, see https://apps.nextcloud.com/apps/recognize#downloads. |
Can't wait to see this merged! |
@Ma27 we want to merge this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meta.changelog
and meta.description
are missing
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'" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--replace-quiet "\$this->config->getAppValueString('node_binary', '""')" "'${nodejs}/bin/node'" \ | |
--replace-quiet "\$this->config->getAppValueString('node_binary', '""')" "'${lib.getExe nodejs}'" \ |
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ln -s ${ffmpeg}/bin/ffmpeg recognize/node_modules/ffmpeg-static/ffmpeg | |
ln -s ${lib.getExe ffmpeg} recognize/node_modules/ffmpeg-static/ffmpeg |
nodejs.pkgs.node-pre-gyp | ||
nodejs.pkgs.node-gyp |
There was a problem hiding this comment.
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.
nodejs.pkgs.node-pre-gyp | |
nodejs.pkgs.node-gyp | |
node-pre-gyp | |
node-gyp |
cd recognize | ||
|
||
# Install tfjs dependency | ||
export CPPFLAGS="-I${nodejs}/include/node -Ideps/include" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export CPPFLAGS="-I${nodejs}/include/node -Ideps/include" | |
export CPPFLAGS="-I${lib.getDev nodejs}/include/node -Ideps/include" |
in | ||
stdenv.mkDerivation rec { | ||
|
||
pname = "nextcloud-app-recognise"; |
There was a problem hiding this comment.
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";
Would really like to backport this to 24.11. |
Successfully created backport PR for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error:
… while evaluating an expression to select 'drvPath' on it
at «internal»:1:552:
… while calling the 'derivationStrict' builtin
at «internal»:1:208:
(stack trace truncated; use '--show-trace' to show the full trace)
error: attribute 'node-pre-gyp' missing
at /home/ma27/Projects/nixpkgs/pkgs/servers/nextcloud/packages/apps/recognize.nix:100:17:
99| nodejs
100| nodejs.pkgs.node-pre-gyp
| ^
101| nodejs.pkgs.node-gyp
I'm sorry that it takes a while until I get to things sometimes, but did nobody even bother to evaluate this against latest master before merging?
EDIT: OK to be fair, this is a deprecated alias which makes me wonder why CI didn't complain. My money is on missing recurseIntoAttrs
somewhere. But still, this needs to change.
I ran it on the latest master @Ma27 . Or at least that was what I thought I did, but maybe not. I did the following: I rebased this PR on master, then I created and ran a vm for each of nextcloud{28,29,29} and I uploaded photos and videos and checked that it did what it should do. I also placed it on my server but that one is nixos-unstable. Should I have done something additionally, or could you tell me how you bumped into this issue? For future reference, #366247 should contain a fix for the alias thing. |
Description of changes
Cleans up the way nextcloud(28|29|30)Packages etc is defined. And adding a package for recognize with support for libtensorflow (darwin suport and GPU stuff is for another PR by someone who has those kinds of machines).
On my x86 linux it now says:
And it has
old intro
Alters the way nextcloud28Packages etc is defined to allow adding custom packages.In this case to add the recognize app which downloads the ML models at runtime (which is not compatible with the read only filesystem). Additionally, I also patch in the version of nodejs (in a very dirty way, for now). I tested it and it says
and
but also
This is mostly a request for comments on of how a thing like this can be done. So, @Ma27, @dotlambda, @onny, and @pyrox0 (the last 4 editors of the Nextcloud packages folder), what do you think?
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.