2024-10-21 12:31:30 +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
|
2024-10-11 10:34:38 +07:00
|
|
|
lib.mkMerge [
|
|
|
|
(mkIf (podman.enable && qbittorrent.enable) {
|
2024-06-18 20:24:28 +07:00
|
|
|
services.caddy.virtualHosts.${domain}.extraConfig = ''
|
|
|
|
reverse_proxy ${ip}:8080
|
|
|
|
'';
|
|
|
|
|
2024-11-24 20:16:30 +07:00
|
|
|
services.nginx.virtualHosts.${domain} = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://${ip}:8080";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-06-18 20:24:28 +07:00
|
|
|
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
|
2024-10-21 12:31:30 +07:00
|
|
|
opts = {
|
|
|
|
sopsFile = ../../secrets/ntfy.yaml;
|
|
|
|
};
|
2024-09-07 19:57:38 +07:00
|
|
|
in
|
|
|
|
{
|
|
|
|
"ntfy/tokens/homeserver" = opts;
|
|
|
|
};
|
|
|
|
templates = {
|
2024-10-21 12:31:30 +07:00
|
|
|
"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
|
2024-10-21 12:31:30 +07:00
|
|
|
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
|
|
|
|
# $10 = %I | Info Hash v1
|
|
|
|
# $11 = %J | Info Hash v2
|
|
|
|
# $12 = %K | Torrent ID
|
2024-09-07 19:57:38 +07:00
|
|
|
|
2024-10-21 12:31:30 +07:00
|
|
|
size=$(echo $8 | numfmt --to=iec)
|
|
|
|
curl -X POST \
|
|
|
|
-H "Authorization: Bearer $NTFY_TOKEN" \
|
|
|
|
-H "X-Title: $1" \
|
|
|
|
-H "X-Tags: white_check_mark,$2" \
|
|
|
|
-d "Number of Files: $7, Size: $size" \
|
|
|
|
https://ntfy.tigor.web.id/qbittorrent?priority=4
|
|
|
|
''
|
|
|
|
);
|
|
|
|
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 "Starts downloading" \
|
|
|
|
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"
|
|
|
|
];
|
2024-10-21 12:31:30 +07:00
|
|
|
environmentFiles = [ config.sops.templates."qbittorrent-ntfy-env".path ];
|
2024-09-07 19:57:38 +07:00
|
|
|
labels = {
|
|
|
|
"io.containers.autoupdate" = "registry";
|
|
|
|
};
|
|
|
|
};
|
2024-10-11 10:34:38 +07:00
|
|
|
})
|
2024-10-21 12:31:30 +07:00
|
|
|
{ profile.services.ntfy-sh.client.settings.subscribe = [ { topic = "qbittorrent"; } ]; }
|
2024-10-11 10:34:38 +07:00
|
|
|
]
|