about summary refs log tree commit diff
path: root/nixpkgs/pkgs/servers/sonarr
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/servers/sonarr')
-rw-r--r--nixpkgs/pkgs/servers/sonarr/default.nix57
-rwxr-xr-xnixpkgs/pkgs/servers/sonarr/update.sh43
2 files changed, 100 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/servers/sonarr/default.nix b/nixpkgs/pkgs/servers/sonarr/default.nix
new file mode 100644
index 000000000000..f0a85b251db0
--- /dev/null
+++ b/nixpkgs/pkgs/servers/sonarr/default.nix
@@ -0,0 +1,57 @@
+{ lib, stdenv, fetchurl, dotnet-runtime, icu, ffmpeg, openssl, sqlite, curl, makeWrapper, nixosTests }:
+
+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-S9j6zXEJM963tki88awPW0uK0fQd1bBwBcsHBlDSg/E=";
+    arm64-linux_hash = "sha256-73FkmdliX5SNrQRRZeAkU0G96ehCd9mT8NVyJoZiA38=";
+    x64-osx_hash = "sha256-XZ4ITJtc2ENw7IAYrBZF0N/NCjUVve+SkWhu6kfQIQA=";
+    arm64-osx_hash = "sha256-2tA17mDuCX5X0U96Rp6QUQOVWvu9sPMOimD6kks+S00=";
+  }."${arch}-${os}_hash";
+in
+stdenv.mkDerivation rec {
+  pname = "sonarr";
+  version = "4.0.2.1183";
+
+  src = fetchurl {
+    url = "https://github.com/Sonarr/Sonarr/releases/download/v${version}/Sonarr.main.${version}.${os}-${arch}.tar.gz";
+    inherit hash;
+  };
+
+  nativeBuildInputs = [ makeWrapper ];
+
+  installPhase = ''
+    runHook preInstall
+
+    mkdir -p $out/{bin,share/sonarr-${version}}
+    cp -r * $out/share/sonarr-${version}/.
+
+    makeWrapper "${dotnet-runtime}/bin/dotnet" $out/bin/NzbDrone \
+      --add-flags "$out/share/sonarr-${version}/Sonarr.dll" \
+      --prefix PATH : ${lib.makeBinPath [ ffmpeg ]} \
+      --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ curl sqlite openssl icu ]}
+
+    runHook postInstall
+  '';
+
+  passthru = {
+    updateScript = ./update.sh;
+    tests.smoke-test = nixosTests.sonarr;
+  };
+
+  meta = {
+    description = "Smart PVR for newsgroup and bittorrent users";
+    homepage = "https://sonarr.tv/";
+    license = lib.licenses.gpl3Only;
+    maintainers = with lib.maintainers; [ fadenb purcell ];
+    mainProgram = "NzbDrone";
+    platforms = lib.platforms.all;
+  };
+}
diff --git a/nixpkgs/pkgs/servers/sonarr/update.sh b/nixpkgs/pkgs/servers/sonarr/update.sh
new file mode 100755
index 000000000000..8ccbc5ba9919
--- /dev/null
+++ b/nixpkgs/pkgs/servers/sonarr/update.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p curl gnused nix-prefetch jq
+
+set -e
+
+dirname="$(dirname "$0")"
+
+updateHash()
+{
+    version=$1
+    arch=$2
+    os=$3
+
+    hashKey="${arch}-${os}_hash"
+
+    url="https://github.com/Sonarr/Sonarr/releases/download/v${version}/Sonarr.main.${version}.${os}-${arch}.tar.gz";
+    hash=$(nix-prefetch-url --type sha256 $url)
+    sriHash="$(nix hash to-sri --type sha256 $hash)"
+
+    sed -i "s|$hashKey = \"[a-zA-Z0-9\/+-=]*\";|$hashKey = \"$sriHash\";|g" "$dirname/default.nix"
+}
+
+updateVersion()
+{
+    sed -i "s/version = \"[0-9.]*\";/version = \"$1\";/g" "$dirname/default.nix"
+}
+
+currentVersion=$(cd $dirname && nix eval --raw -f ../../.. sonarr.version)
+
+latestTag=$(curl https://api.github.com/repos/Sonarr/Sonarr/releases/latest | jq -r ".tag_name")
+latestVersion="$(expr $latestTag : 'v\(.*\)')"
+
+if [[ "$currentVersion" == "$latestVersion" ]]; then
+    echo "Sonarr is up-to-date: ${currentVersion}"
+    exit 0
+fi
+
+updateVersion $latestVersion
+
+updateHash $latestVersion x64 linux
+updateHash $latestVersion arm64 linux
+updateHash $latestVersion x64 osx
+updateHash $latestVersion arm64 osx