Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 110 lines 3.2 kB view raw
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.41.9.9961-46083195d"; 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 = "1gxiwzv799w2b18mlq1yx5z3x9k51f88yc9k7mmcn5a224a11kxf"; 26 } 27 else 28 fetchurl { 29 url = "https://downloads.plex.tv/plex-media-server-new/${version}/debian/plexmediaserver_${version}_amd64.deb"; 30 sha256 = "0hnwsh9x48xx9grgv4j30ymbr7v9bdfkl3dnfwjbqr0g3zb22av2"; 31 }; 32 33 outputs = [ 34 "out" 35 "basedb" 36 ]; 37 38 nativeBuildInputs = [ dpkg ]; 39 40 installPhase = '' 41 runHook preInstall 42 mkdir -p "$out/lib" 43 cp -dr --no-preserve='ownership' usr/lib/plexmediaserver $out/lib/ 44 45 # Location of the initial Plex plugins database 46 f=$out/lib/plexmediaserver/Resources/com.plexapp.plugins.library.db 47 48 # Store the base database in the 'basedb' output 49 cat $f > $basedb 50 51 # Overwrite the base database in the Plex package with an absolute symlink 52 # to the '/db' file; we create this path in the FHS userenv (see the "plex" 53 # package). 54 ln -fs /db $f 55 runHook postInstall 56 ''; 57 58 # We're running in a FHS userenv; don't patch anything 59 dontPatchShebangs = true; 60 dontStrip = true; 61 dontPatchELF = true; 62 dontAutoPatchelf = true; 63 64 passthru.updateScript = writeScript "${pname}-updater" '' 65 #!${stdenv.shell} 66 set -eu -o pipefail 67 PATH=${ 68 lib.makeBinPath [ 69 curl 70 jq 71 common-updater-scripts 72 ] 73 }:$PATH 74 75 plexApiJson=$(curl -sS https://plex.tv/api/downloads/5.json) 76 latestVersion="$(echo $plexApiJson | jq .computer.Linux.version | tr -d '"\n')" 77 78 for platform in ${lib.concatStringsSep " " meta.platforms}; do 79 arch=$(echo $platform | cut -d '-' -f1) 80 dlUrl="$(echo $plexApiJson | jq --arg arch "$arch" -c '.computer.Linux.releases[] | select(.distro == "debian") | select(.build | contains($arch)) .url' | tr -d '"\n')" 81 82 latestSha="$(nix-prefetch-url $dlUrl)" 83 84 update-source-version plexRaw "$latestVersion" "$latestSha" --system=$platform --ignore-same-version 85 done 86 ''; 87 88 meta = with lib; { 89 homepage = "https://plex.tv/"; 90 sourceProvenance = with sourceTypes; [ binaryNativeCode ]; 91 license = licenses.unfree; 92 platforms = [ 93 "x86_64-linux" 94 "aarch64-linux" 95 ]; 96 maintainers = with maintainers; [ 97 badmutex 98 forkk 99 lnl7 100 pjones 101 thoughtpolice 102 MayNiklas 103 ]; 104 description = "Media library streaming server"; 105 longDescription = '' 106 Plex is a media server which allows you to store your media and play it 107 back across many different devices. 108 ''; 109 }; 110}