summary refs log tree commit diff
path: root/pkgs/servers/plex/raw.nix
diff options
context:
space:
mode:
authorSamir Hafez <me@samirhafez.com>2020-11-26 12:47:34 +0000
committerSamir Hafez <me@samirhafez.com>2020-11-30 14:41:03 +0000
commit8a20b502c870213a707c8dd43c61b8121cb65077 (patch)
treef22a957a1ed5aaf534b33bfbd279c28972077a89 /pkgs/servers/plex/raw.nix
parent19908dd99da03196ffbe9d30e7ee01c7e7cc614d (diff)
downloadnixpkgs-8a20b502c870213a707c8dd43c61b8121cb65077.tar
nixpkgs-8a20b502c870213a707c8dd43c61b8121cb65077.tar.gz
nixpkgs-8a20b502c870213a707c8dd43c61b8121cb65077.tar.bz2
nixpkgs-8a20b502c870213a707c8dd43c61b8121cb65077.tar.lz
nixpkgs-8a20b502c870213a707c8dd43c61b8121cb65077.tar.xz
nixpkgs-8a20b502c870213a707c8dd43c61b8121cb65077.tar.zst
nixpkgs-8a20b502c870213a707c8dd43c61b8121cb65077.zip
plex: Add an updateScript
Diffstat (limited to 'pkgs/servers/plex/raw.nix')
-rw-r--r--pkgs/servers/plex/raw.nix25
1 files changed, 25 insertions, 0 deletions
diff --git a/pkgs/servers/plex/raw.nix b/pkgs/servers/plex/raw.nix
index 7ed3bf8bfec..a6ec8dc23d7 100644
--- a/pkgs/servers/plex/raw.nix
+++ b/pkgs/servers/plex/raw.nix
@@ -1,6 +1,10 @@
 { stdenv
 , fetchurl
 , dpkg
+, writeScript
+, curl
+, jq
+, common-updater-scripts
 }:
 
 # The raw package that fetches and extracts the Plex RPM. Override the source
@@ -52,6 +56,27 @@ stdenv.mkDerivation rec {
   dontPatchELF = true;
   dontAutoPatchelf = true;
 
+  passthru.updateScript = writeScript "${pname}-updater" ''
+    #!${stdenv.shell}
+    set -eu -o pipefail
+    PATH=${stdenv.lib.makeBinPath [curl jq common-updater-scripts]}:$PATH
+
+    plexApiJson=$(curl -sS https://plex.tv/api/downloads/5.json)
+    latestVersion="$(echo $plexApiJson | jq .computer.Linux.version | tr -d '"\n')"
+
+    for platform in ${stdenv.lib.concatStringsSep " " meta.platforms}; do
+      arch=$(echo $platform | cut -d '-' -f1)
+      dlUrl="$(echo $plexApiJson | jq --arg arch "$arch" -c '.computer.Linux.releases[] | select(.distro == "debian") | select(.build | contains($arch)) .url' | tr -d '"\n')"
+
+      latestSha="$(nix-prefetch-url $dlUrl)"
+
+      # The script will not perform an update when the version attribute is up to date from previous platform run
+      # We need to clear it before each run
+      update-source-version plexRaw 0 $(yes 0 | head -64 | tr -d "\n") --system=$platform
+      update-source-version plexRaw "$latestVersion" "$latestSha" --system=$platform
+    done
+  '';
+
   meta = with stdenv.lib; {
     homepage = "https://plex.tv/";
     license = licenses.unfree;