4a7f99d55d
Part of: https://github.com/NixOS/nixpkgs/issues/108938 meta = with stdenv.lib; is a widely used pattern. We want to slowly remove the `stdenv.lib` indirection and encourage people to use `lib` directly. Thus let’s start with the meta field. This used a rewriting script to mostly automatically replace all occurances of this pattern, and add the `lib` argument to the package header if it doesn’t exist yet. The script in its current form is available at https://cs.tvl.fyi/depot@2f807d7f141068d2d60676a89213eaa5353ca6e0/-/blob/users/Profpatsch/nixpkgs-rewriter/default.nix
98 lines
3.2 KiB
Nix
98 lines
3.2 KiB
Nix
{ lib, stdenv
|
|
, fetchurl
|
|
, dpkg
|
|
, writeScript
|
|
, curl
|
|
, jq
|
|
, common-updater-scripts
|
|
}:
|
|
|
|
# The raw package that fetches and extracts the Plex RPM. Override the source
|
|
# and version of this derivation if you want to use a Plex Pass version of the
|
|
# server, and the FHS userenv and corresponding NixOS module should
|
|
# automatically pick up the changes.
|
|
stdenv.mkDerivation rec {
|
|
version = "1.21.1.3842-b0c7a97d9";
|
|
pname = "plexmediaserver";
|
|
|
|
# Fetch the source
|
|
src = if stdenv.hostPlatform.system == "aarch64-linux" then fetchurl {
|
|
url = "https://downloads.plex.tv/plex-media-server-new/${version}/debian/plexmediaserver_${version}_arm64.deb";
|
|
sha256 = "0wq8q9dvdwciazidvh9plxjzngjr6ibg077yksxhy41dv14vkw7s";
|
|
} else fetchurl {
|
|
url = "https://downloads.plex.tv/plex-media-server-new/${version}/debian/plexmediaserver_${version}_amd64.deb";
|
|
sha256 = "14pa50kvgi4m5hbw4a0q7y3s4xn9ghvnm4vdim9g18p1khfmwmwp";
|
|
};
|
|
|
|
outputs = [ "out" "basedb" ];
|
|
|
|
nativeBuildInputs = [ dpkg ];
|
|
|
|
phases = [ "unpackPhase" "installPhase" "fixupPhase" "distPhase" ];
|
|
|
|
unpackPhase = ''
|
|
dpkg-deb -R $src .
|
|
'';
|
|
|
|
installPhase = ''
|
|
mkdir -p "$out/lib"
|
|
cp -dr --no-preserve='ownership' usr/lib/plexmediaserver $out/lib/
|
|
|
|
# Location of the initial Plex plugins database
|
|
f=$out/lib/plexmediaserver/Resources/com.plexapp.plugins.library.db
|
|
|
|
# Store the base database in the 'basedb' output
|
|
cat $f > $basedb
|
|
|
|
# Overwrite the base database in the Plex package with an absolute symlink
|
|
# to the '/db' file; we create this path in the FHS userenv (see the "plex"
|
|
# package).
|
|
ln -fs /db $f
|
|
'';
|
|
|
|
# We're running in a FHS userenv; don't patch anything
|
|
dontPatchShebangs = true;
|
|
dontStrip = true;
|
|
dontPatchELF = true;
|
|
dontAutoPatchelf = true;
|
|
|
|
passthru.updateScript = writeScript "${pname}-updater" ''
|
|
#!${stdenv.shell}
|
|
set -eu -o pipefail
|
|
PATH=${stdenv.lib.makeBinPath [curl jq common-updater-scripts]}:$PATH
|
|
|
|
plexApiJson=$(curl -sS https://plex.tv/api/downloads/5.json)
|
|
latestVersion="$(echo $plexApiJson | jq .computer.Linux.version | tr -d '"\n')"
|
|
|
|
for platform in ${stdenv.lib.concatStringsSep " " meta.platforms}; do
|
|
arch=$(echo $platform | cut -d '-' -f1)
|
|
dlUrl="$(echo $plexApiJson | jq --arg arch "$arch" -c '.computer.Linux.releases[] | select(.distro == "debian") | select(.build | contains($arch)) .url' | tr -d '"\n')"
|
|
|
|
latestSha="$(nix-prefetch-url $dlUrl)"
|
|
|
|
# The script will not perform an update when the version attribute is up to date from previous platform run
|
|
# We need to clear it before each run
|
|
update-source-version plexRaw 0 $(yes 0 | head -64 | tr -d "\n") --system=$platform
|
|
update-source-version plexRaw "$latestVersion" "$latestSha" --system=$platform
|
|
done
|
|
'';
|
|
|
|
meta = with lib; {
|
|
homepage = "https://plex.tv/";
|
|
license = licenses.unfree;
|
|
platforms = [ "x86_64-linux" "aarch64-linux" ];
|
|
maintainers = with maintainers; [
|
|
badmutex
|
|
colemickens
|
|
forkk
|
|
lnl7
|
|
pjones
|
|
thoughtpolice
|
|
];
|
|
description = "Media library streaming server";
|
|
longDescription = ''
|
|
Plex is a media server which allows you to store your media and play it
|
|
back across many different devices.
|
|
'';
|
|
};
|
|
}
|