From e1a323aaf84728eaf21fb771e7971608334f79f1 Mon Sep 17 00:00:00 2001
From: detroyejr <detroyejr@outlook.com>
Date: Tue, 17 Dec 2024 22:55:21 -0500
Subject: [PATCH] plex-desktop: update sqlite write permissions

---
 pkgs/by-name/pl/plex-desktop/package.nix | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/pkgs/by-name/pl/plex-desktop/package.nix b/pkgs/by-name/pl/plex-desktop/package.nix
index 52d98ec47fbc4..bfa7e9bcfeb98 100644
--- a/pkgs/by-name/pl/plex-desktop/package.nix
+++ b/pkgs/by-name/pl/plex-desktop/package.nix
@@ -140,6 +140,17 @@ buildFHSEnv {
   runScript = writeShellScript "plex-desktop.sh" ''
     # Widevine won't download unless this directory exists.
     mkdir -p $HOME/.cache/plex/
+
+    # Copy the sqlite plugin database on first run.
+    PLEX_DB="$HOME/.local/share/plex/Plex Media Server/Plug-in Support/Databases"
+    if [[ ! -d "$PLEX_DB" ]]; then
+      mkdir -p "$PLEX_DB"
+      cp "${plex-desktop}/resources/com.plexapp.plugins.library.db" "$PLEX_DB"
+    fi
+
+    # db files should have write access.
+    chmod --recursive 750 "$PLEX_DB"
+
     PLEX_USR_PATH=${lib.makeSearchPath "usr/lib/x86_64-linux-gnu" [ plex-desktop ]}
 
     set -o allexport