From 070c681f42ebae7da3ac841dcc238e7b9c91ce6e Mon Sep 17 00:00:00 2001 From: Linnnus Date: Thu, 11 Apr 2024 08:36:32 +0200 Subject: torrenting: Create different categories of downloads --- hosts/ahmed/torrenting/default.nix | 29 ++++----------------- hosts/ahmed/torrenting/save-path.nix | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 24 deletions(-) create mode 100644 hosts/ahmed/torrenting/save-path.nix diff --git a/hosts/ahmed/torrenting/default.nix b/hosts/ahmed/torrenting/default.nix index efa4403..c8e498b 100644 --- a/hosts/ahmed/torrenting/default.nix +++ b/hosts/ahmed/torrenting/default.nix @@ -4,42 +4,23 @@ options, config, ... -}: let - downloadPath = "/srv/media/"; -in { +}: { imports = [ ./wireguard.nix ./reverse-proxy.nix + ./save-path.nix ]; - # Configure the actual qBittorrent service. services.qbittorrent = { enable = true; - settings = { - BitTorrent = { - # Use the specified download path for finished torrents. - "Session\\DefaultSavePath" = downloadPath; - "Session\\TempPath" = "${config.services.qbittorrent.profile}/qBittorrent/temp"; - "Session\\TempPathEnabled" = true; - }; - Preferences = { - # Again?? - "Downloads\\SavePath" = downloadPath; + # Configure credentials. This should be safe to keep here, since the password is hashed. + "WebUI\\Username" = "linus"; + "WebUI\\Password_PBKDF2" = "@ByteArray(wOEz+v4PMOZTIUxD+NI0sQ==:uEp16/vHvNgv71RcHHBuxm7WgjqgVZpuEWEG1KnCxrCxGX1n3y2cqQyGYDLBlpyGv8rjk3G0g+d5xuxW1izV2g==)"; }; }; }; - # WARNING: Jellyfin has been manually configured to serve from the correct download path. services.jellyfin.enable = true; - - # 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 [ - "d ${downloadPath} 0755 ${user} ${group}" - ]; } 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. +} -- cgit v1.2.3