2024-09-10 20:14:40 -04:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.aux.system.services.qbittorrent;
|
|
|
|
UID = 850;
|
|
|
|
GID = 850;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
aux.system.services.qbittorrent = {
|
|
|
|
enable = lib.mkEnableOption "Enables qBittorrent.";
|
|
|
|
home = lib.mkOption {
|
|
|
|
default = "/var/lib/qbittorrent";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Where to store qBittorrent's files";
|
|
|
|
};
|
|
|
|
url = lib.mkOption {
|
|
|
|
default = "";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The complete URL where qBittorrent is hosted.";
|
|
|
|
example = "https://qbittorrent.example.com";
|
|
|
|
};
|
2024-09-13 11:25:39 -04:00
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "8080";
|
|
|
|
description = "The port to host qBittorrent on.";
|
|
|
|
};
|
2024-09-10 20:14:40 -04:00
|
|
|
user = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "qbittorrent";
|
|
|
|
description = "User account under which qBittorrent runs.";
|
|
|
|
};
|
|
|
|
group = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "qbittorrent";
|
|
|
|
description = "Group under which qBittorrent runs.";
|
|
|
|
};
|
2024-09-13 11:25:39 -04:00
|
|
|
vpn = {
|
|
|
|
enable = lib.mkEnableOption "Enables a VPN.";
|
|
|
|
privateKey = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Wireguard private key.";
|
|
|
|
};
|
|
|
|
};
|
2024-09-10 20:14:40 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services = {
|
|
|
|
nginx.virtualHosts."${cfg.url}" = {
|
|
|
|
useACMEHost = pkgs.util.getDomainFromURL cfg.url;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
2024-09-13 11:25:39 -04:00
|
|
|
proxyPass = "http://127.0.0.1:${cfg.port}";
|
2024-09-10 20:14:40 -04:00
|
|
|
extraConfig = ''
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
proxy_set_header X-Forwarded-Host $host;
|
|
|
|
proxy_set_header X-Forwarded-Server $host;
|
2024-09-10 20:19:40 -04:00
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
2024-09-10 20:14:40 -04:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-13 11:25:39 -04:00
|
|
|
virtualisation = {
|
|
|
|
podman.autoPrune.enable = true;
|
|
|
|
oci-containers.containers = {
|
|
|
|
qbittorrent = {
|
|
|
|
image = "lscr.io/linuxserver/qbittorrent:latest";
|
|
|
|
environment = {
|
|
|
|
PUID = (builtins.toString UID);
|
|
|
|
PGID = (builtins.toString GID);
|
|
|
|
WEBUI_PORT = "${cfg.port}";
|
|
|
|
};
|
|
|
|
volumes = [
|
|
|
|
"${cfg.home}:/config"
|
|
|
|
"${cfg.home}/qBittorrent/downloads:/downloads"
|
|
|
|
];
|
|
|
|
# Forward ports to gluetun if VPN is enabled. Otherwise, open ports directly
|
|
|
|
extraOptions = lib.mkIf cfg.vpn.enable [ "--network=container:gluetun" ];
|
|
|
|
dependsOn = lib.mkIf cfg.vpn.enable [ "gluetun" ];
|
|
|
|
ports = lib.mkIf (!cfg.vpn.enable) [ "${cfg.port}:${cfg.port}" ];
|
|
|
|
};
|
2024-09-10 20:14:40 -04:00
|
|
|
|
2024-09-13 11:25:39 -04:00
|
|
|
gluetun = lib.mkIf cfg.vpn.enable {
|
|
|
|
image = "qmcgaw/gluetun:latest";
|
|
|
|
extraOptions = [
|
|
|
|
"--cap-add=NET_ADMIN"
|
|
|
|
"--device=/dev/net/tun"
|
|
|
|
];
|
|
|
|
environment = {
|
|
|
|
VPN_SERVICE_PROVIDER = "protonvpn";
|
|
|
|
VPN_TYPE = "wireguard";
|
|
|
|
WIREGUARD_PRIVATE_KEY = config.secrets.services.protonvpn.privateKey;
|
|
|
|
SERVER_COUNTRIES = "Netherlands";
|
|
|
|
TZ = "America/New_York";
|
|
|
|
};
|
|
|
|
ports = [ "${cfg.port}:${cfg.port}" ];
|
|
|
|
};
|
2024-09-10 20:14:40 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users = {
|
|
|
|
users.${cfg.user} = {
|
|
|
|
description = "qBittorrent user";
|
|
|
|
isNormalUser = false;
|
|
|
|
group = cfg.group;
|
|
|
|
uid = UID;
|
|
|
|
};
|
|
|
|
groups.${cfg.group}.gid = GID;
|
|
|
|
};
|
|
|
|
|
2024-09-13 11:25:39 -04:00
|
|
|
systemd.services.nginx.wants = [ config.systemd.services.podman-qbittorrent.name ];
|
2024-09-10 20:14:40 -04:00
|
|
|
};
|
|
|
|
}
|