push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
# The actual Plex package that we run is a FHS userenv of the "raw" package.
{
stdenv,
buildFHSEnv,
writeScript,
plexRaw,
# Old argument for overriding the Plex data directory; not used for this
# version of Plex, but still around for backwards-compatibility.
dataDir ? "/var/lib/plex",
}:
buildFHSEnv {
pname = "plexmediaserver";
inherit (plexRaw) version meta;
# Plex does some magic to detect if it is already running.
# The separate PID namespace somehow breaks this and Plex is thinking it's already
# running and refuses to start.
unsharePid = false;
# This script is run when we start our Plex binary
runScript = writeScript "plex-run-script" ''
#!${stdenv.shell}
set -eu
# The root path to our Plex installation
root=${plexRaw}/lib/plexmediaserver
# Path to where we're storing our Plex data files. We default to storing
# them in the user's home directory under the XDG-compatible location, but
# allow overriding with an environment variable so the location can be
# configured in our NixOS module.
#
# NOTE: the old version of Plex used /var/lib/plex as the default location,
# but this package shouldn't assume that we're going to run Plex with the
# ability to write to /var/lib, so using a subdirectory of $HOME when none
# is specified feels less likely to have permission errors.
if [[ -z "''${PLEX_DATADIR:-}" ]]; then
PLEX_DATADIR="$HOME/.local/share/plex"
fi
if [[ ! -d "$PLEX_DATADIR" ]]; then
echo "Creating Plex data directory: $PLEX_DATADIR"
mkdir -p "$PLEX_DATADIR"
fi
# The database is stored under the given directory
db="$PLEX_DATADIR/.skeleton/com.plexapp.plugins.library.db"
# If we don't have a database in the expected path, then create one by
# copying our base database to that location.
if ! test -f "$db"; then
echo "Copying base database file to: $db"
mkdir -p "$(dirname "$db")"
cat "${plexRaw.basedb}" > "$db"
fi
# Set up symbolic link at '/db', which is linked to by our Plex package
# (see the 'plexRaw' package).
ln -s "$db" /db
# If we have a plugin list (set by our NixOS module), we create plugins in
# the data directory as expected. This is a colon-separated list of paths.
if [[ -n "''${PLEX_PLUGINS:-}" ]]; then
echo "Preparing plugin directory"
pluginDir="$PLEX_DATADIR/Plex Media Server/Plug-ins"
test -d "$pluginDir" || mkdir -p "$pluginDir"
# First, remove all of the symlinks in the plugins directory.
while IFS= read -r -d $'\0' f; do
echo "Removing plugin symlink: $f"
rm "$f"
done < <(find "$pluginDir" -type l -print0)
echo "Symlinking plugins"
IFS=':' read -ra pluginsArray <<< "$PLEX_PLUGINS"
for path in "''${pluginsArray[@]}"; do
dest="$pluginDir/$(basename "$path")"
if [[ ! -d "$path" ]]; then
echo "Error symlinking plugin from $path: no such directory"
elif [[ -d "$dest" || -L "$dest" ]]; then
echo "Error symlinking plugin from $path to $dest: file or directory already exists"
else
echo "Symlinking plugin at: $path"
ln -s "$path" "$dest"
fi
done
fi
if [[ -n "''${PLEX_SCANNERS:-}" ]]; then
for scannerType in Common Movies Music Series; do
echo "Preparing $scannerType scanners directory"
scannerDir="$PLEX_DATADIR/Plex Media Server/Scanners/$scannerType"
test -d "$scannerDir" || mkdir -p "$scannerDir"
# First, remove all of the symlinks in the scanners directory.
echo "Removing old symlinks"
while IFS= read -r -d $'\0' f; do
echo "Removing scanner symlink: $f"
rm "$f"
done < <(find "$scannerDir" -type l -print0)
echo "Symlinking scanners"
IFS=':' read -ra scannersArray <<< "$PLEX_SCANNERS"
for path in "''${scannersArray[@]}"; do
# The provided source should contain a 'Scanners' directory; symlink
# from inside that.
subpath="$path/Scanners/$scannerType"
while IFS= read -r -d $'\0' file; do
dest="$scannerDir/$(basename "$file")"
if [[ -f "$dest" || -L "$dest" ]]; then
echo "Error symlinking scanner from $file to $dest: file or directory already exists"
else
echo "Symlinking scanner at: $file"
ln -s "$file" "$dest"
fi
done < <(find "$subpath" -type f -print0)
done
done
fi
# Tell Plex to use the data directory as the "Application Support"
# directory, otherwise it tries to write things into the user's home
# directory.
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="$PLEX_DATADIR"
# Tell Plex where the 'home' directory for itself is.
export PLEX_MEDIA_SERVER_HOME="${plexRaw}/lib/plexmediaserver"
# Actually run Plex, prepending LD_LIBRARY_PATH with the libraries from
# the Plex package.
LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$root exec "$root/Plex Media Server"
'';
}

109
pkgs/servers/plex/raw.nix Normal file
View File

@@ -0,0 +1,109 @@
{
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.42.2.10156-f737b826c";
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 = "sha256-Vm38oO+zhFyHBy6fDuMphDlaqM43BIdLniQ7VJDMAQU=";
}
else
fetchurl {
url = "https://downloads.plex.tv/plex-media-server-new/${version}/debian/plexmediaserver_${version}_amd64.deb";
sha256 = "sha256-1ieh7qc1UBTorqQTKUQgKzM96EtaKZZ8HYq9ILf+X3M=";
};
outputs = [
"out"
"basedb"
];
nativeBuildInputs = [ dpkg ];
installPhase = ''
runHook preInstall
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
runHook postInstall
'';
# 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=${
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 ${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)"
update-source-version plexRaw "$latestVersion" "$latestSha" --system=$platform --ignore-same-version
done
'';
meta = with lib; {
homepage = "https://plex.tv/";
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
license = licenses.unfree;
platforms = [
"x86_64-linux"
"aarch64-linux"
];
maintainers = with maintainers; [
badmutex
forkk
lnl7
pjones
thoughtpolice
MayNiklas
];
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.
'';
};
}