Skip to content

Commit

Permalink
Merge pull request NixOS#105166 from SamirHafez/plex-updateScript
Browse files Browse the repository at this point in the history
plex: Add an updateScript
  • Loading branch information
elseym authored Dec 1, 2020
2 parents c85ce0c + 8a20b50 commit eb079d2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkgs/servers/plex/raw.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit eb079d2

Please sign in to comment.