about summary refs log tree commit diff
path: root/pkgs/by-name/im
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/im')
-rw-r--r--pkgs/by-name/im/immersed-vr/package.nix2
-rw-r--r--pkgs/by-name/im/immich-cli/package.nix36
-rw-r--r--pkgs/by-name/im/immich-machine-learning/package.nix107
-rw-r--r--pkgs/by-name/im/immich/package.nix232
-rw-r--r--pkgs/by-name/im/immich/sources.json22
-rwxr-xr-xpkgs/by-name/im/immich/update.sh44
-rw-r--r--pkgs/by-name/im/implot/demos/default.nix2
7 files changed, 443 insertions, 2 deletions
diff --git a/pkgs/by-name/im/immersed-vr/package.nix b/pkgs/by-name/im/immersed-vr/package.nix
index f057d192ca97..7bf1f14574d4 100644
--- a/pkgs/by-name/im/immersed-vr/package.nix
+++ b/pkgs/by-name/im/immersed-vr/package.nix
@@ -31,6 +31,6 @@ let
     sourceProvenance = with sourceTypes; [ binaryNativeCode ];
   };
 
-in if stdenv.isDarwin
+in if stdenv.hostPlatform.isDarwin
 then callPackage ./darwin.nix { inherit pname version src meta; }
 else callPackage ./linux.nix { inherit pname version src meta; }
diff --git a/pkgs/by-name/im/immich-cli/package.nix b/pkgs/by-name/im/immich-cli/package.nix
new file mode 100644
index 000000000000..d41dc764f26d
--- /dev/null
+++ b/pkgs/by-name/im/immich-cli/package.nix
@@ -0,0 +1,36 @@
+{
+  lib,
+  immich,
+  buildNpmPackage,
+  nodejs,
+  makeWrapper,
+}:
+buildNpmPackage {
+  pname = "immich-cli";
+  src = "${immich.src}/cli";
+  inherit (immich.sources.components.cli) version npmDepsHash;
+
+  nativeBuildInputs = [ makeWrapper ];
+
+  inherit (immich.web) preBuild;
+
+  installPhase = ''
+    runHook preInstall
+
+    mkdir -p $out
+    mv package.json package-lock.json node_modules dist $out/
+
+    makeWrapper ${lib.getExe nodejs} $out/bin/immich --add-flags $out/dist/index.js
+
+    runHook postInstall
+  '';
+
+  meta = {
+    description = "Self-hosted photo and video backup solution (command line interface)";
+    homepage = "https://immich.app/docs/features/command-line-interface";
+    license = lib.licenses.agpl3Only;
+    maintainers = with lib.maintainers; [ jvanbruegge ];
+    inherit (nodejs.meta) platforms;
+    mainProgram = "immich";
+  };
+}
diff --git a/pkgs/by-name/im/immich-machine-learning/package.nix b/pkgs/by-name/im/immich-machine-learning/package.nix
new file mode 100644
index 000000000000..5b35ecfaea04
--- /dev/null
+++ b/pkgs/by-name/im/immich-machine-learning/package.nix
@@ -0,0 +1,107 @@
+{
+  lib,
+  fetchFromGitHub,
+  immich,
+  python3,
+}:
+let
+  python = python3.override {
+    self = python;
+
+    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 {
+  pname = "immich-machine-learning";
+  inherit (immich) version;
+  src = "${immich.src}/machine-learning";
+  pyproject = true;
+
+  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" ];
+  pythonRemoveDeps = [ "opencv-python-headless" ];
+
+  build-system = with python.pkgs; [
+    poetry-core
+    cython
+  ];
+
+  dependencies =
+    with python.pkgs;
+    [
+      insightface
+      opencv4
+      pillow
+      fastapi
+      uvicorn
+      aiocache
+      rich
+      ftfy
+      setuptools
+      python-multipart
+      orjson
+      gunicorn
+      huggingface-hub
+      tokenizers
+      pydantic
+    ]
+    ++ uvicorn.optional-dependencies.standard;
+
+  nativeCheckInputs = with python.pkgs; [
+    httpx
+    pytest-asyncio
+    pytest-mock
+    pytestCheckHook
+  ];
+
+  postInstall = ''
+    mkdir -p $out/share/immich
+    cp log_conf.json $out/share/immich
+
+    cp -r ann $out/${python.sitePackages}/
+
+    makeWrapper ${lib.getExe python.pkgs.gunicorn} "''${!outputBin}"/bin/machine-learning \
+      --prefix PYTHONPATH : "$out/${python.sitePackages}:$PYTHONPATH" \
+      --set-default MACHINE_LEARNING_WORKERS 1 \
+      --set-default MACHINE_LEARNING_WORKER_TIMEOUT 120 \
+      --set-default MACHINE_LEARNING_CACHE_FOLDER /var/cache/immich \
+      --set-default IMMICH_HOST "[::]" \
+      --set-default IMMICH_PORT 3003 \
+      --add-flags "app.main:app -k app.config.CustomUvicornWorker \
+        -w \"\$MACHINE_LEARNING_WORKERS\" \
+        -b \"\$IMMICH_HOST:\$IMMICH_PORT\" \
+        -t \"\$MACHINE_LEARNING_WORKER_TIMEOUT\"
+        --log-config-json $out/share/immich/log_conf.json"
+  '';
+
+  meta = {
+    description = "Self-hosted photo and video backup solution (machine learning component)";
+    homepage = "https://immich.app/";
+    license = lib.licenses.agpl3Only;
+    maintainers = with lib.maintainers; [ jvanbruegge ];
+    mainProgram = "machine-learning";
+    inherit (immich.meta) platforms;
+  };
+}
diff --git a/pkgs/by-name/im/immich/package.nix b/pkgs/by-name/im/immich/package.nix
new file mode 100644
index 000000000000..fe62f0ddc354
--- /dev/null
+++ b/pkgs/by-name/im/immich/package.nix
@@ -0,0 +1,232 @@
+{
+  lib,
+  stdenvNoCC,
+  buildNpmPackage,
+  fetchFromGitHub,
+  python3,
+  nodejs,
+  node-gyp,
+  runCommand,
+  nixosTests,
+  immich-machine-learning,
+  # build-time deps
+  glib,
+  pkg-config,
+  makeWrapper,
+  curl,
+  cacert,
+  unzip,
+  # runtime deps
+  ffmpeg-headless,
+  imagemagick,
+  libraw,
+  libheif,
+  vips,
+  perl,
+}:
+let
+  buildNpmPackage' = buildNpmPackage.override { inherit nodejs; };
+  sources = lib.importJSON ./sources.json;
+  inherit (sources) version;
+
+  buildLock = {
+    sources =
+      builtins.map
+        (p: {
+          name = p.pname;
+          inherit (p) version;
+          inherit (p.src) rev;
+        })
+        [
+          imagemagick
+          libheif
+          libraw
+        ];
+
+    packages = [ ];
+  };
+
+  # The geodata website is not versioned, so we use the internet archive
+  geodata =
+    runCommand "immich-geodata"
+      {
+        outputHash = "sha256-imqSfzXaEMNo9T9tZr80sr/89n19kiFc8qwidFzRUaY=";
+        outputHashMode = "recursive";
+        nativeBuildInputs = [
+          cacert
+          curl
+          unzip
+        ];
+
+        meta.license = lib.licenses.cc-by-40;
+      }
+      ''
+        mkdir $out
+        url="https://web.archive.org/web/20240724153050/http://download.geonames.org/export/dump"
+        curl -Lo ./cities500.zip "$url/cities500.zip"
+        curl -Lo $out/admin1CodesASCII.txt "$url/admin1CodesASCII.txt"
+        curl -Lo $out/admin2Codes.txt "$url/admin2Codes.txt"
+        curl -Lo $out/ne_10m_admin_0_countries.geojson \
+          https://raw.githubusercontent.com/nvkelso/natural-earth-vector/ca96624a56bd078437bca8184e78163e5039ad19/geojson/ne_10m_admin_0_countries.geojson
+
+        unzip ./cities500.zip -d $out/
+        echo "2024-07-24T15:30:50Z" > $out/geodata-date.txt
+      '';
+
+  src = fetchFromGitHub {
+    owner = "immich-app";
+    repo = "immich";
+    rev = "v${version}";
+    inherit (sources) hash;
+  };
+
+  openapi = buildNpmPackage' {
+    pname = "immich-openapi-sdk";
+    inherit version;
+    src = "${src}/open-api/typescript-sdk";
+    inherit (sources.components."open-api/typescript-sdk") npmDepsHash;
+
+    installPhase = ''
+      runHook preInstall
+
+      npm config delete cache
+      npm prune --omit=dev --omit=optional
+
+      mkdir -p $out
+      mv package.json package-lock.json node_modules build $out/
+
+      runHook postInstall
+    '';
+  };
+
+  web = buildNpmPackage' {
+    pname = "immich-web";
+    inherit version;
+    src = "${src}/web";
+    inherit (sources.components.web) npmDepsHash;
+
+    preBuild = ''
+      rm node_modules/@immich/sdk
+      ln -s ${openapi} node_modules/@immich/sdk
+      # Rollup does not find the dependency otherwise
+      ln -s node_modules/@immich/sdk/node_modules/@oazapfts node_modules/
+    '';
+
+    installPhase = ''
+      runHook preInstall
+
+      cp -r build $out
+
+      runHook postInstall
+    '';
+  };
+
+  node-addon-api = stdenvNoCC.mkDerivation rec {
+    pname = "node-addon-api";
+    version = "8.0.0";
+    src = fetchFromGitHub {
+      owner = "nodejs";
+      repo = "node-addon-api";
+      rev = "v${version}";
+      hash = "sha256-k3v8lK7uaEJvcaj1sucTjFZ6+i5A6w/0Uj9rYlPhjCE=";
+    };
+    installPhase = ''
+      mkdir $out
+      cp -r *.c *.h *.gyp *.gypi index.js package-support.json package.json tools $out/
+    '';
+  };
+
+  vips' = vips.overrideAttrs (prev: {
+    mesonFlags = prev.mesonFlags ++ [ "-Dtiff=disabled" ];
+  });
+in
+buildNpmPackage' {
+  pname = "immich";
+  inherit version;
+  src = "${src}/server";
+  inherit (sources.components.server) npmDepsHash;
+
+  nativeBuildInputs = [
+    pkg-config
+    python3
+    makeWrapper
+    glib
+    node-gyp
+  ];
+
+  buildInputs = [
+    ffmpeg-headless
+    imagemagick
+    libraw
+    libheif
+    vips' # Required for sharp
+  ];
+
+  # Required because vips tries to write to the cache dir
+  makeCacheWritable = true;
+
+  preBuild = ''
+    cd node_modules/sharp
+
+    mkdir node_modules
+    ln -s ${node-addon-api} node_modules/node-addon-api
+
+    ${lib.getExe nodejs} install/check
+
+    rm -r node_modules
+
+    cd ../..
+    rm -r node_modules/@img/sharp*
+  '';
+
+  installPhase = ''
+    runHook preInstall
+
+    npm config delete cache
+    npm prune --omit=dev
+
+    mkdir -p $out/build
+    mv package.json package-lock.json node_modules dist resources $out/
+    ln -s ${web} $out/build/www
+    ln -s ${geodata} $out/build/geodata
+
+    echo '${builtins.toJSON buildLock}' > $out/build/build-lock.json
+
+    makeWrapper ${lib.getExe nodejs} $out/bin/admin-cli --add-flags $out/dist/main --add-flags cli
+    makeWrapper ${lib.getExe nodejs} $out/bin/server --add-flags $out/dist/main --chdir $out \
+      --set IMMICH_BUILD_DATA $out/build --set NODE_ENV production \
+      --suffix PATH : "${
+        lib.makeBinPath [
+          perl
+          ffmpeg-headless
+        ]
+      }"
+
+    runHook postInstall
+  '';
+
+  passthru = {
+    tests = {
+      inherit (nixosTests) immich;
+    };
+
+    machine-learning = immich-machine-learning;
+
+    inherit
+      src
+      sources
+      web
+      geodata
+      ;
+    updateScript = ./update.sh;
+  };
+
+  meta = {
+    description = "Self-hosted photo and video backup solution";
+    homepage = "https://immich.app/";
+    license = lib.licenses.agpl3Only;
+    maintainers = with lib.maintainers; [ jvanbruegge ];
+    platforms = lib.platforms.linux;
+    mainProgram = "server";
+  };
+}
diff --git a/pkgs/by-name/im/immich/sources.json b/pkgs/by-name/im/immich/sources.json
new file mode 100644
index 000000000000..a07d6c0b1b29
--- /dev/null
+++ b/pkgs/by-name/im/immich/sources.json
@@ -0,0 +1,22 @@
+{
+  "version": "1.115.0",
+  "hash": "sha256-H2FCR55redomrDjnnCQys47AaYbWEmlxO5NJEcVMBwY=",
+  "components": {
+    "cli": {
+      "npmDepsHash": "sha256-+zKtPHXjBd1KAKvI5xaY2/9qzVUg+8Ho/wrV9+TlU64=",
+      "version": "2.2.19"
+    },
+    "server": {
+      "npmDepsHash": "sha256-6CehRhPepspDpQW1h0Bx7EpH7hn42Ygqma/6wim14jA=",
+      "version": "1.115.0"
+    },
+    "web": {
+      "npmDepsHash": "sha256-ZmXfYktgOmMkDjfqSGyyflr2CmnC9yVnJ1gAcmd6A00=",
+      "version": "1.115.0"
+    },
+    "open-api/typescript-sdk": {
+      "npmDepsHash": "sha256-l1mLYFpFQjYxytY0ZWLq+ldUhZA6so0HqPgCABt0s9k=",
+      "version": "1.115.0"
+    }
+  }
+}
diff --git a/pkgs/by-name/im/immich/update.sh b/pkgs/by-name/im/immich/update.sh
new file mode 100755
index 000000000000..a1a5e2e0585c
--- /dev/null
+++ b/pkgs/by-name/im/immich/update.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p curl jq prefetch-npm-deps nix-prefetch-github coreutils
+
+set -euo pipefail
+cd "$(dirname "${BASH_SOURCE[0]}")"
+
+old_version=$(jq -r ".version" sources.json || echo -n "0.0.1")
+version=$(curl -s "https://api.github.com/repos/immich-app/immich/releases/latest" | jq -r ".tag_name")
+version="${version#v}"
+
+echo "Updating to $version"
+
+if [[ "$old_version" == "$version" ]]; then
+    echo "Already up to date!"
+    exit 0
+fi
+
+echo "Fetching src"
+src_hash=$(nix-prefetch-github immich-app immich --rev "v${version}" | jq -r .hash)
+upstream_src="https://raw.githubusercontent.com/immich-app/immich/v$version"
+
+sources_tmp="$(mktemp)"
+cat <<EOF > "$sources_tmp"
+{
+  "version": "$version",
+  "hash": "$src_hash",
+  "components": {}
+}
+EOF
+
+lock=$(mktemp)
+for npm_component in cli server web "open-api/typescript-sdk"; do
+    echo "fetching $npm_component"
+    curl -s -o "$lock" "$upstream_src/$npm_component/package-lock.json"
+    hash=$(prefetch-npm-deps "$lock")
+    echo "$(jq --arg npm_component "$npm_component" \
+      --arg hash "$hash" \
+      --arg version "$(jq -r '.version' <"$lock")" \
+      '.components += {($npm_component): {npmDepsHash: $hash, version: $version}}' \
+      "$sources_tmp")" > "$sources_tmp"
+done
+
+rm "$lock"
+mv "$sources_tmp" sources.json
diff --git a/pkgs/by-name/im/implot/demos/default.nix b/pkgs/by-name/im/implot/demos/default.nix
index b3a369668c1d..677448924dee 100644
--- a/pkgs/by-name/im/implot/demos/default.nix
+++ b/pkgs/by-name/im/implot/demos/default.nix
@@ -72,7 +72,7 @@ stdenv.mkDerivation rec {
     homepage = "https://github.com/epezent/implot_demos";
     broken =
       stdenv.hostPlatform.isAarch64 # Target "mandel" relies on AVX2
-      || stdenv.isDarwin;
+      || stdenv.hostPlatform.isDarwin;
     license = lib.licenses.mit;
     maintainers = with lib.maintainers; [ SomeoneSerge ];
     mainProgram = "implot-demos";