about summary refs log tree commit diff
path: root/pkgs/by-name/pl
diff options
context:
space:
mode:
authordetroyejr2024-06-29 10:16:40 -0400
committerdetroyejr2024-07-16 12:35:48 -0400
commit101f71dce0a2747f0f1b79362dea38b966551bb4 (patch)
tree2108769dbb545aaf5255452d3c3264df06b07abd /pkgs/by-name/pl
parent41844ddf269f3100aa6712434f330732688a90e3 (diff)
plex-desktop: init at 1.96.0
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Diffstat (limited to 'pkgs/by-name/pl')
-rw-r--r--pkgs/by-name/pl/plex-desktop/package.nix151
-rwxr-xr-xpkgs/by-name/pl/plex-desktop/update.sh83
2 files changed, 234 insertions, 0 deletions
diff --git a/pkgs/by-name/pl/plex-desktop/package.nix b/pkgs/by-name/pl/plex-desktop/package.nix
new file mode 100644
index 000000000000..5e015d4ac90c
--- /dev/null
+++ b/pkgs/by-name/pl/plex-desktop/package.nix
@@ -0,0 +1,151 @@
+{ alsa-lib
+, autoPatchelfHook
+, buildFHSEnv
+, dbus
+, elfutils
+, expat
+, extraEnv ? { }
+, fetchFromGitLab
+, fetchurl
+, glib
+, glibc
+, lib
+, libGL
+, libapparmor
+, libbsd
+, libedit
+, libffi_3_3
+, libgcrypt
+, libglvnd
+, makeShellWrapper
+, sqlite
+, squashfsTools
+, stdenv
+, tcp_wrappers
+, udev
+, waylandpp
+, writeShellScript
+, xkeyboard_config
+, xorg
+, xz
+, zstd
+}:
+let
+  pname = "plex-desktop";
+  version = "1.96.0";
+  rev = "69";
+  meta = {
+    homepage = "https://plex.tv/";
+    description = "Streaming media player for Plex";
+    longDescription = ''
+      Plex for Linux is your client for playback on the Linux
+      desktop. It features the point and click interface you see in your browser
+      but uses a more powerful playback engine as well as
+      some other advance features.
+    '';
+    maintainers = with lib.maintainers; [ detroyejr ];
+    license = lib.licenses.unfree;
+    platforms = [ "x86_64-linux" ];
+    mainProgram = "plex-desktop";
+  };
+
+  # The latest unstable version isn't compatible with libraries that ship in the snap.
+  libglvnd-1_4_0 = libglvnd.overrideAttrs {
+    src = fetchFromGitLab {
+      domain = "gitlab.freedesktop.org";
+      owner = "glvnd";
+      repo = "libglvnd";
+      rev = "v1.4.0";
+      sha256 = "sha256-Y6JHRygXcZtnrdnqi1Lzyvh/635gwZWnMeW9aRCpxxs";
+    };
+  };
+  plex-desktop = stdenv.mkDerivation {
+    inherit pname version meta;
+
+    src = fetchurl {
+      url = "https://api.snapcraft.io/api/v1/snaps/download/qc6MFRM433ZhI1XjVzErdHivhSOhlpf0_${rev}.snap";
+      hash = "sha512-rECc8rK1ENAL5mXdabO8ynudCaSzz0yygOyg4gMbCtddgqwSOanP24/oguzPLr3zdRMC3VSf9B3hr2BGQ54tzg==";
+    };
+
+    nativeBuildInputs = [ squashfsTools ];
+
+    buildInputs = [
+      alsa-lib
+      autoPatchelfHook
+      dbus
+      elfutils
+      expat
+      glib
+      glibc
+      libGL
+      libapparmor
+      libbsd
+      libedit
+      libffi_3_3
+      libgcrypt
+      makeShellWrapper
+      sqlite
+      squashfsTools
+      stdenv.cc.cc
+      tcp_wrappers
+      udev
+      waylandpp
+      xorg.libXinerama
+      xz
+      zstd
+    ];
+
+    unpackPhase = ''
+      runHook preUnpack
+      unsquashfs "$src"
+      cd squashfs-root
+      runHook postUnpack
+    '';
+
+    dontWrapQtApps = true;
+
+    installPhase =
+      ''
+        runHook preInstall
+
+        cp -r . $out
+
+        ln -s ${libedit}/lib/libedit.so.0 $out/lib/libedit.so.2
+        rm $out/usr/lib/x86_64-linux-gnu/libasound.so.2
+        ln -s ${alsa-lib}/lib/libasound.so.2 $out/usr/lib/x86_64-linux-gnu/libasound.so.2
+        rm $out/usr/lib/x86_64-linux-gnu/libasound.so.2.0.0
+        ln -s ${alsa-lib}/lib/libasound.so.2.0.0 $out/usr/lib/x86_64-linux-gnu/libasound.so.2.0.0
+
+        runHook postInstall
+      '';
+  };
+in
+buildFHSEnv {
+    name = "${pname}-${version}";
+    targetPkgs = pkgs: [ xkeyboard_config ];
+
+    extraInstallCommands = ''
+      mkdir -p $out/share/applications $out/share/icons/hicolor/scalable/apps
+      install -m 444 -D ${plex-desktop}/meta/gui/plex-desktop.desktop $out/share/applications/plex-desktop.desktop
+      substituteInPlace $out/share/applications/plex-desktop.desktop \
+        --replace-warn \
+        'Icon=''${SNAP}/meta/gui/icon.png' \
+        'Icon=${plex-desktop}/meta/gui/icon.png' \
+        --replace-fail \
+        'Exec=plex-desktop' \
+        'Exec=plex-desktop-${version}'
+    '';
+
+    runScript = writeShellScript "plex-desktop.sh" ''
+      # Widevine won't download unless this directory exists.
+      mkdir -p $HOME/.cache/plex/
+      PLEX_USR_PATH=${lib.makeSearchPath "usr/lib/x86_64-linux-gnu"  [ plex-desktop ]}
+
+      set -o allexport
+      LD_LIBRARY_PATH=${lib.makeLibraryPath [ plex-desktop libglvnd-1_4_0 ]}:$PLEX_USR_PATH
+      LIBGL_DRIVERS_PATH=$PLEX_USR_PATH/dri
+      ${lib.toShellVars extraEnv}
+      exec ${plex-desktop}/Plex.sh
+  '';
+}
+
diff --git a/pkgs/by-name/pl/plex-desktop/update.sh b/pkgs/by-name/pl/plex-desktop/update.sh
new file mode 100755
index 000000000000..0cc509fb2b72
--- /dev/null
+++ b/pkgs/by-name/pl/plex-desktop/update.sh
@@ -0,0 +1,83 @@
+#!/usr/bin/env nix-shell
+#! nix-shell -i bash -p curl jq git gnused gnugrep
+
+
+# executing this script without arguments will
+# - find the newest stable plex-desktop version avaiable on snapcraft (https://snapcraft.io/plex-desktop)
+# - read the current plex-desktop version from the current nix expression
+# - update the nix expression if the versions differ
+# - try to build the updated version, exit if that fails
+# - give instructions for upstreaming
+
+# As an optional argument you can specify the snapcraft channel to update to.
+# Default is `stable` and only stable updates should be pushed to nixpkgs. For
+# testing you may specify `candidate` or `edge`.
+
+
+channel="${1:-stable}" # stable/candidate/edge
+nixpkgs="$(git rev-parse --show-toplevel)"
+plex_nix="$nixpkgs/pkgs/by-name/pl/plex-desktop/package.nix"
+
+
+#
+# find the newest stable plex-desktop version avaiable on snapcraft
+#
+
+# create bash array from snap info
+snap_info=($(
+  curl -s -H 'X-Ubuntu-Series: 16' \
+    "https://api.snapcraft.io/api/v1/snaps/details/plex-desktop?channel=$channel" \
+  | jq --raw-output \
+    '.revision,.download_sha512,.version,.last_updated'
+))
+
+# "revision" is the actual version identifier on snapcraft, the "version" is
+# just for human consumption. Revision is just an integer that gets increased
+# by one every (stable or unstable) release.
+revision="${snap_info[0]}"
+# We need to escape the slashes
+hash="$(nix-hash --to-sri --type sha512 ${snap_info[1]} | sed 's|/|\\/|g')"
+upstream_version="${snap_info[2]}"
+last_updated="${snap_info[3]}"
+echo "Latest $channel release is $upstream_version from $last_updated."
+#
+# read the current plex-desktop version from the currently *committed* nix expression
+#
+
+current_version=$(
+  grep 'version\s*=' "$plex_nix" \
+  | sed -Ene 's/.*"(.*)".*/\1/p'
+)
+
+echo "Current version: $current_version"
+
+#
+# update the nix expression if the versions differ
+#
+
+if [[ "$current_version" == "$upstream_version" ]]; then
+  echo "Plex is already up-to-date"
+  exit 0
+fi
+
+echo "Updating from ${current_version} to ${upstream_version}, released on ${last_updated}"
+
+# search-and-replace revision, hash and version
+sed --regexp-extended \
+  -e 's/rev\s*=\s*"[0-9]+"\s*;/rev = "'"${revision}"'";/' \
+  -e 's/hash\s*=\s*"[^"]*"\s*;/hash = "'"${hash}"'";/' \
+  -e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \
+  -i "$plex_nix"
+
+#
+# try to build the updated version
+#
+
+if ! nix-build -A plex-desktop "$nixpkgs"; then
+  echo "The updated plex-desktop failed to build."
+  exit 1
+fi
+
+# Commit changes
+git add "$plex_nix"
+git commit -m "plex-desktop: ${current_version} -> ${upstream_version}"