nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchurl,
5 dpkg,
6 writeScript,
7 curl,
8 jq,
9 common-updater-scripts,
10}:
11
12# The raw package that fetches and extracts the Plex RPM. Override the source
13# and version of this derivation if you want to use a Plex Pass version of the
14# server, and the FHS userenv and corresponding NixOS module should
15# automatically pick up the changes.
16stdenv.mkDerivation rec {
17 version = "1.42.2.10156-f737b826c";
18 pname = "plexmediaserver";
19
20 # Fetch the source
21 src =
22 if stdenv.hostPlatform.system == "aarch64-linux" then
23 fetchurl {
24 url = "https://downloads.plex.tv/plex-media-server-new/${version}/debian/plexmediaserver_${version}_arm64.deb";
25 sha256 = "sha256-Vm38oO+zhFyHBy6fDuMphDlaqM43BIdLniQ7VJDMAQU=";
26 }
27 else
28 fetchurl {
29 url = "https://downloads.plex.tv/plex-media-server-new/${version}/debian/plexmediaserver_${version}_amd64.deb";
30 sha256 = "sha256-1ieh7qc1UBTorqQTKUQgKzM96EtaKZZ8HYq9ILf+X3M=";
31 };
32 outputs = [
33 "out"
34 "basedb"
35 ];
36
37 nativeBuildInputs = [ dpkg ];
38
39 installPhase = ''
40 runHook preInstall
41 mkdir -p "$out/lib"
42 cp -dr --no-preserve='ownership' usr/lib/plexmediaserver $out/lib/
43
44 # Location of the initial Plex plugins database
45 f=$out/lib/plexmediaserver/Resources/com.plexapp.plugins.library.db
46
47 # Store the base database in the 'basedb' output
48 cat $f > $basedb
49
50 # Overwrite the base database in the Plex package with an absolute symlink
51 # to the '/db' file; we create this path in the FHS userenv (see the "plex"
52 # package).
53 ln -fs /db $f
54 runHook postInstall
55 '';
56
57 # We're running in a FHS userenv; don't patch anything
58 dontPatchShebangs = true;
59 dontStrip = true;
60 dontPatchELF = true;
61 dontAutoPatchelf = true;
62
63 passthru.updateScript = writeScript "${pname}-updater" ''
64 #!${stdenv.shell}
65 set -eu -o pipefail
66 PATH=${
67 lib.makeBinPath [
68 curl
69 jq
70 common-updater-scripts
71 ]
72 }:$PATH
73
74 plexApiJson=$(curl -sS https://plex.tv/api/downloads/5.json)
75 latestVersion="$(echo $plexApiJson | jq .computer.Linux.version | tr -d '"\n')"
76
77 for platform in ${lib.concatStringsSep " " meta.platforms}; do
78 arch=$(echo $platform | cut -d '-' -f1)
79 dlUrl="$(echo $plexApiJson | jq --arg arch "$arch" -c '.computer.Linux.releases[] | select(.distro == "debian") | select(.build | contains($arch)) .url' | tr -d '"\n')"
80
81 latestSha="$(nix-prefetch-url $dlUrl)"
82
83 update-source-version plexRaw "$latestVersion" "$latestSha" --system=$platform --ignore-same-version
84 done
85 '';
86
87 meta = {
88 homepage = "https://plex.tv/";
89 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
90 license = lib.licenses.unfree;
91 platforms = [
92 "x86_64-linux"
93 "aarch64-linux"
94 ];
95 maintainers = with lib.maintainers; [
96 badmutex
97 forkk
98 lnl7
99 pjones
100 thoughtpolice
101 MayNiklas
102 ];
103 description = "Media library streaming server";
104 longDescription = ''
105 Plex is a media server which allows you to store your media and play it
106 back across many different devices.
107 '';
108 };
109}