diff options
Diffstat (limited to 'nixpkgs/pkgs/servers/photoprism')
-rw-r--r-- | nixpkgs/pkgs/servers/photoprism/backend.nix | 38 | ||||
-rw-r--r-- | nixpkgs/pkgs/servers/photoprism/default.nix | 88 | ||||
-rw-r--r-- | nixpkgs/pkgs/servers/photoprism/frontend.nix | 28 | ||||
-rw-r--r-- | nixpkgs/pkgs/servers/photoprism/libtensorflow.nix | 89 |
4 files changed, 243 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/servers/photoprism/backend.nix b/nixpkgs/pkgs/servers/photoprism/backend.nix new file mode 100644 index 000000000000..7403f4dc897f --- /dev/null +++ b/nixpkgs/pkgs/servers/photoprism/backend.nix @@ -0,0 +1,38 @@ +{ lib, buildGoModule, coreutils, libtensorflow, src, version, ... }: + +buildGoModule rec { + inherit src version; + pname = "photoprism-backend"; + + buildInputs = [ + coreutils + libtensorflow + ]; + + ldflags = [ + "-s" + "-w" + "-X main.version=${version}" + ]; + + postPatch = '' + substituteInPlace internal/commands/passwd.go --replace '/bin/stty' "${coreutils}/bin/stty" + ''; + + vendorHash = "sha256-mt2L5vf57/MntjtfJVua799nF4CkRYI8payLoPc0oQA="; + + subPackages = [ "cmd/photoprism" ]; + + # https://github.com/mattn/go-sqlite3/issues/822 + CGO_CFLAGS = "-Wno-return-local-addr"; + + # https://github.com/tensorflow/tensorflow/issues/43847 + CGO_LDFLAGS = "-fuse-ld=gold"; + + meta = with lib; { + homepage = "https://photoprism.app"; + description = "Photoprism's backend"; + license = licenses.agpl3Only; + maintainers = with maintainers; [ benesim ]; + }; +} diff --git a/nixpkgs/pkgs/servers/photoprism/default.nix b/nixpkgs/pkgs/servers/photoprism/default.nix new file mode 100644 index 000000000000..f2f7914394b8 --- /dev/null +++ b/nixpkgs/pkgs/servers/photoprism/default.nix @@ -0,0 +1,88 @@ +{ pkgs, lib, stdenv, fetchFromGitHub, fetchzip, darktable, rawtherapee, ffmpeg, libheif, exiftool, imagemagick, makeWrapper, testers }: + +let + version = "231128-f48ff16ef"; + pname = "photoprism"; + + src = fetchFromGitHub { + owner = pname; + repo = pname; + rev = version; + hash = "sha256-gVxKa5JKGz5VSVCuJHat0DWCYaUH+9an6JsYUPe9muQ="; + }; + + libtensorflow = pkgs.callPackage ./libtensorflow.nix { }; + backend = pkgs.callPackage ./backend.nix { inherit libtensorflow src version; }; + frontend = pkgs.callPackage ./frontend.nix { inherit src version; }; + + fetchModel = { name, hash }: + fetchzip { + inherit hash; + url = "https://dl.photoprism.org/tensorflow/${name}.zip"; + stripRoot = false; + }; + + facenet = fetchModel { + name = "facenet"; + hash = "sha256-aS5kkNhxOLSLTH/ipxg7NAa1w9X8iiG78jmloR1hpRo="; + }; + + nasnet = fetchModel { + name = "nasnet"; + hash = "sha256-bF25jPmZLyeSWy/CGXZE/VE2UupEG2q9Jmr0+1rUYWE="; + }; + + nsfw = fetchModel { + name = "nsfw"; + hash = "sha256-zy/HcmgaHOY7FfJUY6I/yjjsMPHR2Ote9ppwqemBlfg="; + }; + + assets_path = "$out/share/${pname}"; +in +stdenv.mkDerivation { + inherit pname version; + + nativeBuildInputs = [ + makeWrapper + ]; + + dontUnpack = true; + dontBuild = true; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin ${assets_path} + + # install backend + ln -s ${backend}/bin/photoprism $out/bin/photoprism + wrapProgram $out/bin/photoprism \ + --set PHOTOPRISM_ASSETS_PATH ${assets_path} \ + --set PHOTOPRISM_DARKTABLE_BIN ${darktable}/bin/darktable-cli \ + --set PHOTOPRISM_RAWTHERAPEE_BIN ${rawtherapee}/bin/rawtherapee-cli \ + --set PHOTOPRISM_HEIFCONVERT_BIN ${libheif}/bin/heif-convert \ + --set PHOTOPRISM_FFMPEG_BIN ${ffmpeg}/bin/ffmpeg \ + --set PHOTOPRISM_EXIFTOOL_BIN ${exiftool}/bin/exiftool \ + --set PHOTOPRISM_IMAGEMAGICK_BIN ${imagemagick}/bin/convert + + # install frontend + ln -s ${frontend}/assets/* ${assets_path} + # install tensorflow models + ln -s ${nasnet}/nasnet ${assets_path} + ln -s ${nsfw}/nsfw ${assets_path} + ln -s ${facenet}/facenet ${assets_path} + + runHook postInstall + ''; + + passthru.tests.version = testers.testVersion { package = pkgs.photoprism; }; + + meta = with lib; { + homepage = "https://photoprism.app"; + description = "Personal Photo Management powered by Go and Google TensorFlow"; + inherit (libtensorflow.meta) platforms; + license = licenses.agpl3Only; + maintainers = with maintainers; [ benesim ]; + mainProgram = "photoprism"; + }; +} diff --git a/nixpkgs/pkgs/servers/photoprism/frontend.nix b/nixpkgs/pkgs/servers/photoprism/frontend.nix new file mode 100644 index 000000000000..782efb1d0d3d --- /dev/null +++ b/nixpkgs/pkgs/servers/photoprism/frontend.nix @@ -0,0 +1,28 @@ +{ lib, buildNpmPackage, src, version }: + +buildNpmPackage { + inherit src version; + pname = "photoprism-frontend"; + + postPatch = '' + cd frontend + ''; + + npmDepsHash = "sha256-4bAWSSy7kvG1ChzEb2iuxgWxnkjtJlr7Lm7USbgsmAw="; + + installPhase = '' + runHook preInstall + + mkdir $out + cp -r ../assets $out/ + + runHook postInstall + ''; + + meta = with lib; { + homepage = "https://photoprism.app"; + description = "Photoprism's frontend"; + license = licenses.agpl3Only; + maintainers = with maintainers; [ benesim ]; + }; +} diff --git a/nixpkgs/pkgs/servers/photoprism/libtensorflow.nix b/nixpkgs/pkgs/servers/photoprism/libtensorflow.nix new file mode 100644 index 000000000000..e1c8f9338cc8 --- /dev/null +++ b/nixpkgs/pkgs/servers/photoprism/libtensorflow.nix @@ -0,0 +1,89 @@ +{ lib, stdenv, fetchurl, ... }: +let + inherit (stdenv.hostPlatform) system; +in +stdenv.mkDerivation rec { + pname = "libtensorflow-photoprism"; + version = "1.15.2"; + + srcs = [ + # Photoprism-packaged libtensorflow tarball (with pre-built libs for both arm64 and amd64) + # We need this specific version because of https://github.com/photoprism/photoprism/issues/222 + (fetchurl { + sha256 = { + x86_64-linux = "sha256-bZAC3PJxqcjuGM4RcNtzYtkg3FD3SrO5beDsPoKenzc="; + aarch64-linux = "sha256-qnj4vhSWgrk8SIjzIH1/4waMxMsxMUvqdYZPaSaUJRk="; + }.${system}; + + url = + let + systemName = { + x86_64-linux = "amd64"; + aarch64-linux = "arm64"; + }.${system}; + in + "https://dl.photoprism.app/tensorflow/${systemName}/libtensorflow-${systemName}-${version}.tar.gz"; + }) + # Upstream tensorflow tarball (with .h's photoprism's tarball is missing) + (fetchurl { + url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.15.0.tar.gz"; + sha256 = "sha256-3sv9WnCeztNSP1XM+iOTN6h+GrPgAO/aNhfbeeEDTe0="; + }) + ]; + + sourceRoot = "."; + + unpackPhase = '' + sources=($srcs) + + mkdir downstream upstream + tar xf ''${sources[0]} --directory downstream + tar xf ''${sources[1]} --directory upstream + + mv downstream/lib . + mv upstream/{include,LICENSE,THIRD_PARTY_TF_C_LICENSES} . + rm -r downstream upstream + + cd lib + ln -sT libtensorflow.so{,.1} + ln -sT libtensorflow_framework.so{,.1} + cd .. + ''; + + # Patch library to use our libc, libstdc++ and others + patchPhase = + let + rpath = lib.makeLibraryPath [ stdenv.cc.libc stdenv.cc.cc.lib ]; + in + '' + chmod -R +w lib + patchelf --set-rpath "${rpath}:$out/lib" lib/libtensorflow.so + patchelf --set-rpath "${rpath}" lib/libtensorflow_framework.so + ''; + + buildPhase = '' + # Write pkg-config file. + mkdir lib/pkgconfig + cat > lib/pkgconfig/tensorflow.pc << EOF + Name: TensorFlow + Version: ${version} + Description: Library for computation using data flow graphs for scalable machine learning + Requires: + Libs: -L$out/lib -ltensorflow + Cflags: -I$out/include/tensorflow + EOF + ''; + + installPhase = '' + mkdir -p $out + cp -r LICENSE THIRD_PARTY_TF_C_LICENSES lib include $out + ''; + + meta = with lib; { + homepage = "https://dl.photoprism.app/tensorflow/"; + description = "Libtensorflow version for usage with photoprism backend"; + platforms = [ "x86_64-linux" "aarch64-linux" ]; + license = licenses.asl20; + maintainers = with maintainers; [ benesim ]; + }; +} |