2019-02-03 15:33:23 +00:00
|
|
|
{ config, stdenv, fetchurl, rpmextract, glibc
|
2015-04-16 19:15:59 +01:00
|
|
|
, dataDir ? "/var/lib/plex" # Plex's data directory must be baked into the package due to symlinks.
|
2019-02-03 15:33:23 +00:00
|
|
|
, enablePlexPass ? config.plex.enablePlexPass or false
|
2015-04-16 19:15:59 +01:00
|
|
|
}:
|
|
|
|
|
2016-01-17 12:11:27 +00:00
|
|
|
let
|
2016-09-08 07:35:22 +01:00
|
|
|
plexPass = throw "Plex pass has been removed at upstream's request; please unset nixpkgs.config.plex.pass";
|
|
|
|
plexpkg = if enablePlexPass then plexPass else {
|
2019-04-07 16:20:21 +01:00
|
|
|
version = "1.15.3.876";
|
|
|
|
vsnHash = "ad6e39743";
|
|
|
|
sha256 = "01g7wccm01kg3nhf3qrmwcn20nkpv0bqz6zqv2gq5v03ps58h6g5";
|
2016-01-17 12:11:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
in stdenv.mkDerivation rec {
|
2015-04-16 19:15:59 +01:00
|
|
|
name = "plex-${version}";
|
2016-01-17 12:11:27 +00:00
|
|
|
version = plexpkg.version;
|
|
|
|
vsnHash = plexpkg.vsnHash;
|
|
|
|
sha256 = plexpkg.sha256;
|
2015-04-16 19:15:59 +01:00
|
|
|
|
|
|
|
src = fetchurl {
|
2019-03-19 22:40:09 +00:00
|
|
|
url = "https://downloads.plex.tv/plex-media-server-new/${version}-${vsnHash}/redhat/plexmediaserver-${version}-${vsnHash}.x86_64.rpm";
|
2016-01-17 12:11:27 +00:00
|
|
|
inherit sha256;
|
2015-04-16 19:15:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
buildInputs = [ rpmextract glibc ];
|
|
|
|
|
|
|
|
phases = [ "unpackPhase" "installPhase" "fixupPhase" "distPhase" ];
|
|
|
|
|
|
|
|
unpackPhase = ''
|
|
|
|
rpmextract $src
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
install -d $out/usr/lib
|
|
|
|
cp -dr --no-preserve='ownership' usr/lib/plexmediaserver $out/usr/lib/
|
|
|
|
|
|
|
|
# Now we need to patch up the executables and libraries to work on Nix.
|
|
|
|
# Side note: PLEASE don't put spaces in your binary names. This is stupid.
|
2017-03-20 19:22:58 +00:00
|
|
|
for bin in "Plex Media Server" \
|
2018-10-21 04:46:45 +01:00
|
|
|
"Plex Commercial Skipper" \
|
2017-03-20 19:22:58 +00:00
|
|
|
"Plex DLNA Server" \
|
|
|
|
"Plex Media Scanner" \
|
|
|
|
"Plex Relay" \
|
|
|
|
"Plex Script Host" \
|
|
|
|
"Plex Transcoder" \
|
|
|
|
"Plex Tuner Service" ; do
|
2016-01-24 07:29:16 +00:00
|
|
|
patchelf --set-interpreter "${glibc.out}/lib/ld-linux-x86-64.so.2" "$out/usr/lib/plexmediaserver/$bin"
|
2019-03-19 22:40:09 +00:00
|
|
|
patchelf --set-rpath "$out/usr/lib/plexmediaserver/lib" "$out/usr/lib/plexmediaserver/$bin"
|
2015-04-16 19:15:59 +01:00
|
|
|
done
|
|
|
|
|
2015-09-06 09:21:43 +01:00
|
|
|
find $out/usr/lib/plexmediaserver/Resources -type f -a -perm -0100 \
|
2016-01-24 07:29:16 +00:00
|
|
|
-print -exec patchelf --set-interpreter "${glibc.out}/lib/ld-linux-x86-64.so.2" '{}' \;
|
2015-04-16 19:15:59 +01:00
|
|
|
|
|
|
|
# Our next problem is the "Resources" directory in /usr/lib/plexmediaserver.
|
|
|
|
# This is ostensibly a skeleton directory, which contains files that Plex
|
|
|
|
# copies into its folder in /var. Unfortunately, there are some SQLite
|
|
|
|
# databases in the directory that are opened at startup. Since these
|
|
|
|
# database files are read-only, SQLite chokes and Plex fails to start. To
|
|
|
|
# solve this, we keep the resources directory in the Nix store, but we
|
|
|
|
# rename the database files and replace the originals with symlinks to
|
|
|
|
# /var/lib/plex. Then, in the systemd unit, the base database files are
|
|
|
|
# copied to /var/lib/plex before starting Plex.
|
|
|
|
RSC=$out/usr/lib/plexmediaserver/Resources
|
|
|
|
for db in "com.plexapp.plugins.library.db"; do
|
|
|
|
mv $RSC/$db $RSC/base_$db
|
2018-09-30 19:13:25 +01:00
|
|
|
ln -s "${dataDir}/.skeleton/$db" $RSC/$db
|
2015-04-16 19:15:59 +01:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
|
|
|
homepage = http://plex.tv/;
|
|
|
|
license = licenses.unfree;
|
|
|
|
platforms = platforms.linux;
|
2017-06-24 18:00:30 +01:00
|
|
|
maintainers = with stdenv.lib.maintainers; [ colemickens forkk thoughtpolice pjones lnl7 ];
|
2015-04-16 19:15:59 +01:00
|
|
|
description = "Media / DLNA server";
|
|
|
|
longDescription = ''
|
|
|
|
Plex is a media server which allows you to store your media and play it
|
|
|
|
back across many different devices.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|