summaryrefslogtreecommitdiff
path: root/hosts/ahmed/torrenting/save-path.nix
diff options
context:
space:
mode:
authorLinnnus <[email protected]>2024-04-11 08:36:32 +0200
committerLinnnus <[email protected]>2024-05-09 14:06:08 +0200
commit070c681f42ebae7da3ac841dcc238e7b9c91ce6e (patch)
tree9348786c59370b11c3e352f569cb7b1ed3112395 /hosts/ahmed/torrenting/save-path.nix
parent959d86017e005d49b401032538c4e2a80191dfe8 (diff)
torrenting: Create different categories of downloads
Diffstat (limited to 'hosts/ahmed/torrenting/save-path.nix')
-rw-r--r--hosts/ahmed/torrenting/save-path.nix50
1 files changed, 50 insertions, 0 deletions
diff --git a/hosts/ahmed/torrenting/save-path.nix b/hosts/ahmed/torrenting/save-path.nix
new file mode 100644
index 0000000..47c6658
--- /dev/null
+++ b/hosts/ahmed/torrenting/save-path.nix
@@ -0,0 +1,50 @@
+{pkgs,lib,config,...}: let
+ downloadPath = "/srv/media/";
+
+ categories = [ "Movies" "Anime Movies" "Miscellaneous" ];
+in {
+ # Create the directory to which media will be downloaded. This will be used
+ # by qBittorent to hold files and Jellyfin will serve from it.
+ systemd.tmpfiles.rules = let
+ user = config.services.qbittorrent.user;
+ group = config.services.qbittorrent.group;
+ in
+ map (category: "d ${lib.strings.escapeC [" "] "${downloadPath}/${category}"} 0755 ${user} ${group}") categories;
+
+ # Configure qBittorrent to use the correct save path.
+ services.qbittorrent.settings = {
+ BitTorrent = {
+ "Session\\DefaultSavePath" = assert builtins.elem "Miscellaneous" categories; "${downloadPath}/Miscellaneous";
+ "Session\\TempPath" = "${config.services.qbittorrent.profile}/qBittorrent/temp";
+ "Session\\TempPathEnabled" = true;
+ };
+ Preferences = {
+ # Again??
+ "Downloads\\SavePath" = downloadPath;
+ };
+ };
+
+ # Create categories for qBittorrent with correct save paths.
+ # WARNING: qBittorrent does NOT like it when you change the categories used by active torrents.
+ systemd.services.qbittorrent.unitConfig = {
+ Requires = ["qbittorrent-create-categories.service"];
+ After = ["qbittorrent-create-categories.service"];
+ };
+ systemd.services.qbittorrent-create-categories = {
+ enable = true;
+ serviceConfig = {
+ Type = "oneshot";
+ User = config.services.qbittorrent.user;
+ Group = config.services.qbittorrent.group;
+ ExecStart = let
+ categoriesJson = lib.genAttrs categories (c: { "save_path" = "${downloadPath}/${c}"; });
+ categoriesFile = (pkgs.formats.json {}).generate "categories.json" categoriesJson;
+ categoriesPath = "${config.services.qbittorrent.profile}/qBittorrent/config/categories.json";
+ in pkgs.writeShellScript "qbittorrent-create-categories.sh" ''
+ ln -s -f ${categoriesFile} ${categoriesPath}
+ '';
+ };
+ };
+
+ # WARNING: Jellyfin has been manually configured to serve from the correct download paths.
+}