at 17.09-beta 84 lines 3.5 kB view raw
1{ stdenv, fetchurl, rpmextract, glibc 2, dataDir ? "/var/lib/plex" # Plex's data directory must be baked into the package due to symlinks. 3, enablePlexPass ? false 4}: 5 6let 7 plexPass = throw "Plex pass has been removed at upstream's request; please unset nixpkgs.config.plex.pass"; 8 plexpkg = if enablePlexPass then plexPass else { 9 version = "1.7.5.4035"; 10 vsnHash = "313f93718"; 11 sha256 = "89b8585e561046a8422d520ebcdae784f5dc3c895aac8d313c435cc6b58795b8"; 12 }; 13 14in stdenv.mkDerivation rec { 15 name = "plex-${version}"; 16 version = plexpkg.version; 17 vsnHash = plexpkg.vsnHash; 18 sha256 = plexpkg.sha256; 19 20 src = fetchurl { 21 url = "https://downloads.plex.tv/plex-media-server/${version}-${vsnHash}/plexmediaserver-${version}-${vsnHash}.x86_64.rpm"; 22 inherit sha256; 23 }; 24 25 buildInputs = [ rpmextract glibc ]; 26 27 phases = [ "unpackPhase" "installPhase" "fixupPhase" "distPhase" ]; 28 29 unpackPhase = '' 30 rpmextract $src 31 ''; 32 33 installPhase = '' 34 install -d $out/usr/lib 35 cp -dr --no-preserve='ownership' usr/lib/plexmediaserver $out/usr/lib/ 36 37 # Now we need to patch up the executables and libraries to work on Nix. 38 # Side note: PLEASE don't put spaces in your binary names. This is stupid. 39 for bin in "Plex Media Server" \ 40 "Plex DLNA Server" \ 41 "Plex Media Scanner" \ 42 "Plex Media Server Tests" \ 43 "Plex Relay" \ 44 "Plex Script Host" \ 45 "Plex Transcoder" \ 46 "Plex Tuner Service" ; do 47 patchelf --set-interpreter "${glibc.out}/lib/ld-linux-x86-64.so.2" "$out/usr/lib/plexmediaserver/$bin" 48 patchelf --set-rpath "$out/usr/lib/plexmediaserver" "$out/usr/lib/plexmediaserver/$bin" 49 done 50 51 find $out/usr/lib/plexmediaserver/Resources -type f -a -perm -0100 \ 52 -print -exec patchelf --set-interpreter "${glibc.out}/lib/ld-linux-x86-64.so.2" '{}' \; 53 54 # executables need libstdc++.so.6 55 ln -s "${stdenv.lib.makeLibraryPath [ stdenv.cc.cc ]}/libstdc++.so.6" "$out/usr/lib/plexmediaserver/libstdc++.so.6" 56 57 # Our next problem is the "Resources" directory in /usr/lib/plexmediaserver. 58 # This is ostensibly a skeleton directory, which contains files that Plex 59 # copies into its folder in /var. Unfortunately, there are some SQLite 60 # databases in the directory that are opened at startup. Since these 61 # database files are read-only, SQLite chokes and Plex fails to start. To 62 # solve this, we keep the resources directory in the Nix store, but we 63 # rename the database files and replace the originals with symlinks to 64 # /var/lib/plex. Then, in the systemd unit, the base database files are 65 # copied to /var/lib/plex before starting Plex. 66 RSC=$out/usr/lib/plexmediaserver/Resources 67 for db in "com.plexapp.plugins.library.db"; do 68 mv $RSC/$db $RSC/base_$db 69 ln -s ${dataDir}/.skeleton/$db $RSC/$db 70 done 71 ''; 72 73 meta = with stdenv.lib; { 74 homepage = http://plex.tv/; 75 license = licenses.unfree; 76 platforms = platforms.linux; 77 maintainers = with stdenv.lib.maintainers; [ colemickens forkk thoughtpolice pjones lnl7 ]; 78 description = "Media / DLNA server"; 79 longDescription = '' 80 Plex is a media server which allows you to store your media and play it 81 back across many different devices. 82 ''; 83 }; 84}