lol

plex: add support for custom scanners

+60 -7
+24
nixos/modules/services/misc/plex.nix
··· 65 65 ''; 66 66 }; 67 67 68 + extraScanners = mkOption { 69 + type = types.listOf types.path; 70 + default = []; 71 + description = '' 72 + A list of paths to extra scanners to install in Plex's scanners 73 + directory. 74 + 75 + Every time the systemd unit for Plex starts up, all of the symlinks 76 + in Plex's scanners directory will be cleared and this module will 77 + symlink all of the paths specified here to that directory. 78 + ''; 79 + example = literalExample '' 80 + [ 81 + (fetchFromGitHub { 82 + owner = "ZeroQI"; 83 + repo = "Absolute-Series-Scanner"; 84 + rev = "773a39f502a1204b0b0255903cee4ed02c46fde0"; 85 + sha256 = "4l+vpiDdC8L/EeJowUgYyB3JPNTZ1sauN8liFAcK+PY="; 86 + }) 87 + ] 88 + ''; 89 + }; 90 + 68 91 package = mkOption { 69 92 type = types.package; 70 93 default = pkgs.plex; ··· 113 136 # Configuration for our FHS userenv script 114 137 PLEX_DATADIR=cfg.dataDir; 115 138 PLEX_PLUGINS=concatMapStringsSep ":" builtins.toString cfg.extraPlugins; 139 + PLEX_SCANNERS=concatMapStringsSep ":" builtins.toString cfg.extraScanners; 116 140 117 141 # The following variables should be set by the FHS userenv script: 118 142 # PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR
+36 -7
pkgs/servers/plex/default.nix
··· 63 63 test -d "$pluginDir" || mkdir -p "$pluginDir" 64 64 65 65 # First, remove all of the symlinks in the plugins directory. 66 - echo "Removing old symlinks" 67 - for f in $(ls "$pluginDir/"); do 68 - if [[ -L "$pluginDir/$f" ]]; then 69 - echo "Removing plugin symlink: $pluginDir/$f" 70 - rm "$pluginDir/$f" 71 - fi 72 - done 66 + while IFS= read -r -d $'\0' f; do 67 + echo "Removing plugin symlink: $f" 68 + done < <(find "$pluginDir" -type l -print0) 73 69 74 70 echo "Symlinking plugins" 75 71 IFS=':' read -ra pluginsArray <<< "$PLEX_PLUGINS" ··· 84 80 echo "Symlinking plugin at: $path" 85 81 ln -s "$path" "$dest" 86 82 fi 83 + done 84 + fi 85 + 86 + if [[ -n "''${PLEX_SCANNERS:-}" ]]; then 87 + for scannerType in Common Movies Music Series; do 88 + echo "Preparing $scannerType scanners directory" 89 + 90 + scannerDir="$PLEX_DATADIR/Plex Media Server/Scanners/$scannerType" 91 + test -d "$scannerDir" || mkdir -p "$scannerDir" 92 + 93 + # First, remove all of the symlinks in the scanners directory. 94 + echo "Removing old symlinks" 95 + while IFS= read -r -d $'\0' f; do 96 + echo "Removing scanner symlink: $f" 97 + done < <(find "$scannerDir" -type l -print0) 98 + 99 + echo "Symlinking scanners" 100 + IFS=':' read -ra scannersArray <<< "$PLEX_SCANNERS" 101 + for path in "''${scannersArray[@]}"; do 102 + # The provided source should contain a 'Scanners' directory; symlink 103 + # from inside that. 104 + subpath="$path/Scanners/$scannerType" 105 + while IFS= read -r -d $'\0' file; do 106 + dest="$scannerDir/$(basename "$file")" 107 + 108 + if [[ -f "$dest" || -L "$dest" ]]; then 109 + echo "Error symlinking scanner from $file to $dest: file or directory already exists" 110 + else 111 + echo "Symlinking scanner at: $file" 112 + ln -s "$file" "$dest" 113 + fi 114 + done < <(find "$subpath" -type f -print0) 115 + done 87 116 done 88 117 fi 89 118