2024-09-07 19:57:38 +07:00
|
|
|
{ config, lib, pkgs, ... }:
|
2024-06-18 20:24:28 +07:00
|
|
|
let
|
|
|
|
name = "qbittorrent";
|
|
|
|
domain = "${name}.tigor.web.id";
|
|
|
|
podman = config.profile.podman;
|
|
|
|
qbittorrent = podman.qbittorrent;
|
|
|
|
inherit (lib) mkIf;
|
2024-09-07 19:57:38 +07:00
|
|
|
inherit (lib.strings) optionalString;
|
2024-06-18 20:24:28 +07:00
|
|
|
ip = "10.88.0.7";
|
|
|
|
image = "lscr.io/linuxserver/qbittorrent:latest";
|
|
|
|
volume = "/nas/torrents";
|
|
|
|
user = config.profile.user;
|
|
|
|
uid = toString user.uid;
|
|
|
|
gid = toString user.gid;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
config = mkIf (podman.enable && qbittorrent.enable) {
|
|
|
|
services.caddy.virtualHosts.${domain}.extraConfig = ''
|
|
|
|
reverse_proxy ${ip}:8080
|
|
|
|
'';
|
|
|
|
|
|
|
|
system.activationScripts."podman-${name}" = ''
|
2024-06-18 21:00:43 +07:00
|
|
|
mkdir -p ${volume}/{config,downloads,progress,watch}
|
|
|
|
chown ${uid}:${gid} ${volume} ${volume}/{config,downloads,progress,watch}
|
2024-06-18 20:24:28 +07:00
|
|
|
'';
|
|
|
|
|
2024-09-07 19:57:38 +07:00
|
|
|
|
|
|
|
sops = {
|
|
|
|
secrets =
|
|
|
|
let
|
|
|
|
opts = { sopsFile = ../../secrets/ntfy.yaml; };
|
|
|
|
in
|
|
|
|
{
|
|
|
|
"ntfy/tokens/homeserver" = opts;
|
|
|
|
};
|
|
|
|
templates = {
|
|
|
|
"qbittorrent-ntfy-env".content = /*sh*/ ''
|
|
|
|
NTFY_TOKEN=${config.sops.placeholder."ntfy/tokens/homeserver"}
|
|
|
|
'';
|
2024-06-19 12:49:23 +07:00
|
|
|
};
|
2024-06-18 20:24:28 +07:00
|
|
|
};
|
2024-09-07 19:57:38 +07:00
|
|
|
|
|
|
|
virtualisation.oci-containers.containers.${name} =
|
|
|
|
let
|
|
|
|
finish-notify-script = pkgs.writeScriptBin "notify-finish.sh" (optionalString config.services.ntfy-sh.enable /*sh*/ ''
|
|
|
|
#!/bin/bash
|
|
|
|
# $1 = %N | Torrent Name
|
|
|
|
# $2 = %L | Category
|
|
|
|
# $3 = %G | Tags
|
|
|
|
# $4 = %F | Content Path
|
|
|
|
# $5 = %R | Root Path
|
|
|
|
# $6 = %D | Save Path
|
|
|
|
# $7 = %C | Number of files
|
|
|
|
# $8 = %Z | Torrent Size
|
|
|
|
# $9 = %T | Current Tracker
|
2024-09-07 20:12:52 +07:00
|
|
|
# $10 = %I | Info Hash v1
|
2024-09-07 19:57:38 +07:00
|
|
|
# $11 = %J | Info Hash v2
|
|
|
|
# $12 = %K | Torrent ID
|
|
|
|
|
|
|
|
curl -X POST \
|
|
|
|
-H "Authorization: Bearer $NTFY_TOKEN" \
|
2024-09-07 19:59:13 +07:00
|
|
|
-H "X-Title: $1" \
|
2024-09-07 19:57:38 +07:00
|
|
|
-H "X-Tags: white_check_mark,$2" \
|
|
|
|
-d "Number of Files: $7, Size: $8" \
|
2024-09-07 20:12:52 +07:00
|
|
|
https://ntfy.tigor.web.id/qbittorrent
|
|
|
|
'');
|
|
|
|
start-notify-script = pkgs.writeScriptBin "notify-start.sh" (optionalString config.services.ntfy-sh.enable /*sh*/ ''
|
|
|
|
#!/bin/bash
|
|
|
|
curl -X POST \
|
|
|
|
-H "Authorization: Bearer $NTFY_TOKEN" \
|
|
|
|
-H "X-Title: $1" \
|
|
|
|
-H "X-Tags: rocket,$2" \
|
|
|
|
-d "Number of Files: $7, Size: $8" \
|
|
|
|
https://ntfy.tigor.web.id/qbittorrent
|
2024-09-07 19:57:38 +07:00
|
|
|
'');
|
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit image;
|
|
|
|
hostname = name;
|
|
|
|
autoStart = true;
|
|
|
|
environment = {
|
|
|
|
PUID = uid;
|
|
|
|
PGID = gid;
|
|
|
|
TZ = "Asia/Jakarta";
|
|
|
|
WEBUI_PORT = "8080";
|
|
|
|
TORRENTING_PORT = "6881";
|
|
|
|
};
|
|
|
|
volumes = [
|
|
|
|
"${volume}/config:/config"
|
|
|
|
"${volume}/downloads:/downloads"
|
|
|
|
"${volume}/progress:/progress"
|
|
|
|
"${volume}/watch:/watch"
|
|
|
|
"${finish-notify-script}/bin/notify-finish.sh:/bin/notify-finish"
|
2024-09-07 20:12:52 +07:00
|
|
|
"${start-notify-script}/bin/notify-start.sh:/bin/notify-start"
|
2024-09-07 19:57:38 +07:00
|
|
|
];
|
|
|
|
ports = [
|
|
|
|
"6881:6881"
|
|
|
|
"6881:6881/udp"
|
|
|
|
];
|
|
|
|
extraOptions = [
|
|
|
|
"--ip=${ip}"
|
|
|
|
"--network=podman"
|
|
|
|
];
|
|
|
|
environmentFiles = [
|
|
|
|
config.sops.templates."qbittorrent-ntfy-env".path
|
|
|
|
];
|
|
|
|
labels = {
|
|
|
|
"io.containers.autoupdate" = "registry";
|
|
|
|
};
|
|
|
|
};
|
2024-06-18 20:24:28 +07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|