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