about summary refs log tree commit diff
path: root/pkgs/tools/video
diff options
context:
space:
mode:
authorJanik <80165193+Janik-Haag@users.noreply.github.com>2023-07-13 23:44:37 +0200
committerGitHub <noreply@github.com>2023-07-13 23:44:37 +0200
commit406fa0477cbbd262b03e749679f1496d5a80dc62 (patch)
treea395c8e80d64addb204305e8c4675e44db10f73d /pkgs/tools/video
parent141bacd77bdf8d51b79612edbb6967adbfca337e (diff)
parent2868e85d93d6a60fdfd64031bcaf82f313553b80 (diff)
Merge pull request #240119 from josephst/recyclarr
Diffstat (limited to 'pkgs/tools/video')
-rw-r--r--pkgs/tools/video/recyclarr/default.nix88
-rwxr-xr-xpkgs/tools/video/recyclarr/update.sh46
2 files changed, 134 insertions, 0 deletions
diff --git a/pkgs/tools/video/recyclarr/default.nix b/pkgs/tools/video/recyclarr/default.nix
new file mode 100644
index 0000000000000..1ad38489c5552
--- /dev/null
+++ b/pkgs/tools/video/recyclarr/default.nix
@@ -0,0 +1,88 @@
+{ lib
+, stdenv
+, fetchurl
+, makeWrapper
+, autoPatchelfHook
+, fixDarwinDylibNames
+, darwin
+, recyclarr
+, git
+, icu
+, testers
+, zlib
+}:
+let
+  os =
+    if stdenv.isDarwin
+    then "osx"
+    else "linux";
+
+  arch = {
+    x86_64-linux = "x64";
+    aarch64-linux = "arm64";
+    x86_64-darwin = "x64";
+    aarch64-darwin = "arm64";
+  }."${stdenv.hostPlatform.system}"
+    or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
+
+  hash = {
+    x64-linux_hash = "sha256-aEcinTJlO++rTeyqGJea0TWtleH6fyooA8RhT0Qj24c=";
+    arm64-linux_hash = "sha256-9Gyk09zAGzahP8FCGxj037vaK8h++3M5R2Qqop99Gs4=";
+    x64-osx_hash = "sha256-c87eOZBz+RtbIi+dlXKKVMyPI8JqYDuiaL4xOkDRFn0=";
+    arm64-osx_hash = "sha256-zSHgLXRDB6UA7V0LFgLq9ChqB40IHIJJxRqAYyVFlB8=";
+  }."${arch}-${os}_hash";
+
+  libPath = {
+    osx = "DYLD_LIBRARY_PATH : ${lib.makeLibraryPath [darwin.ICU zlib]}";
+    linux = "LD_LIBRARY_PATH : ${lib.makeLibraryPath [icu zlib]}";
+  }."${os}";
+
+in
+stdenv.mkDerivation rec {
+  pname = "recyclarr";
+  version = "5.1.0";
+
+  src = fetchurl {
+    url = "https://github.com/recyclarr/recyclarr/releases/download/v${version}/recyclarr-${os}-${arch}.tar.xz";
+    inherit hash;
+  };
+
+  sourceRoot = ".";
+
+  nativeBuildInputs = [ makeWrapper ]
+    ++ lib.optional stdenv.isLinux autoPatchelfHook
+    ++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
+  buildInputs = [ icu zlib ];
+
+  installPhase = ''
+    runHook preInstall
+
+    install -Dm755 recyclarr -t $out/bin
+
+    runHook postInstall
+  '';
+
+  postInstall = ''
+    wrapProgram $out/bin/recyclarr \
+      --prefix PATH : ${lib.makeBinPath [git]} \
+      --prefix ${libPath}
+  '';
+
+  dontStrip = true; # stripping messes up dotnet single-file deployment
+
+  passthru = {
+    updateScript = ./update.sh;
+    tests.version = testers.testVersion {
+      package = recyclarr;
+    };
+  };
+
+  meta = with lib; {
+    description = "Automatically sync TRaSH guides to your Sonarr and Radarr instances";
+    homepage = "https://recyclarr.dev/";
+    changelog = "https://github.com/recyclarr/recyclarr/releases/tag/v${version}";
+    license = licenses.mit;
+    maintainers = with maintainers; [ josephst ];
+    platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
+  };
+}
diff --git a/pkgs/tools/video/recyclarr/update.sh b/pkgs/tools/video/recyclarr/update.sh
new file mode 100755
index 0000000000000..83942439cc284
--- /dev/null
+++ b/pkgs/tools/video/recyclarr/update.sh
@@ -0,0 +1,46 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -I nixpkgs=./. -i bash -p curl jq common-updater-scripts gnused nix coreutils
+#shellcheck shell=bash
+
+set -euo pipefail
+
+latestVersion=$(curl -s ${GITHUB_TOKEN:+ -H "Authorization: Bearer $GITHUB_TOKEN"} https://api.github.com/repos/recyclarr/recyclarr/releases?per_page=1 \
+    | jq -r ".[0].tag_name" \
+    | sed 's/^v//')
+currentVersion=$(nix-instantiate --eval -E "with import ./. {}; recyclarr.version or (lib.getVersion recyclarr)" | tr -d '"')
+
+if [[ "$currentVersion" == "$latestVersion" ]]; then
+    echo "recyclarr is up-to-date: $currentVersion"
+    exit 0
+fi
+
+function get_hash() {
+    local os=$1
+    local arch=$2
+    local version=$3
+
+    local pkg_hash=$(nix-prefetch-url --type sha256 \
+        https://github.com/recyclarr/recyclarr/releases/download/v"${version}"/recyclarr-"${os}"-"${arch}".tar.xz)
+    nix hash to-sri "sha256:$pkg_hash"
+}
+
+# aarch64-darwin
+# reset version first so that all platforms are always updated and in sync
+update-source-version recyclarr 0 "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" --system="aarch64-darwin"
+update-source-version recyclarr "$latestVersion" $(get_hash osx arm64 "$latestVersion") --system="aarch64-darwin"
+
+# x86_64-darwin
+# reset version first so that all platforms are always updated and in sync
+update-source-version recyclarr 0 "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" --system="x86_64-darwin"
+update-source-version recyclarr "$latestVersion" $(get_hash osx x64 "$latestVersion") --system="x86_64-darwin"
+
+# aarch64-linux
+# reset version first so that all platforms are always updated and in sync
+update-source-version recyclarr 0 "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" --system="aarch64-linux"
+update-source-version recyclarr "$latestVersion" $(get_hash linux arm64 "$latestVersion") --system="aarch64-linux"
+
+# x86_64-linux
+# reset version first so that all platforms are always updated and in sync
+update-source-version recyclarr 0 "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" --system="x86_64-linux"
+update-source-version recyclarr "$latestVersion" $(get_hash linux x64 "$latestVersion") --system="x86_64-linux"
+