Files
nix/modules/homelab/services/qbittorrent/default.nix

88 lines
2.1 KiB
Nix

{ pkgs, config, lib, ... }:
let
cfg = config.modules.services.qbittorrent;
ids = 2003;
default_port = 8080;
data_dir = "/var/lib/qBittorrent";
in
{
options.modules.services.qbittorrent = {
enable = lib.mkEnableOption "enables qbittorrent";
# set port options
port = lib.mkOption {
type = lib.types.int;
default = 7103;
description = "set port for qbittorrent (default: ${toString default_port}";
};
backup = lib.mkOption {
type = lib.types.bool;
default = true;
description = "enable backups for qbittorrent";
};
};
config = lib.mkIf cfg.enable {
# declare qbittorrent group
users.groups.qbittorrent = { gid = ids; };
# declare qbittorrent user
users.users.qbittorrent = {
description = "qbittorrent server user";
uid = ids;
isSystemUser = true;
home = data_dir;
createHome = true;
group = "qbittorrent";
extraGroups = [ "media" ];
};
# enable the qbittorrent service
services.qbittorrent = {
enable = true;
openFirewall = true;
user = "qbittorrent";
group = "qbittorrent";
profileDir = data_dir;
webuiPort = cfg.port;
# torrentingPort = cfg.port;
};
# override umask to make permissions work out
systemd.services.qbittorrent = {
serviceConfig = {
UMask = lib.mkForce "0007";
# User = "qbittorrent";
# Group = "qbittorrent";
};
# add systemd service to VPN network namespace
vpnConfinement = {
enable = true;
vpnNamespace = "wgmex";
};
};
# # open firewall
# networking.firewall.allowedTCPPorts = [ cfg.port ];
# internal reverse proxy entry
services.nginx.virtualHosts.".snowbelle.lan" = {
enableACME = false;
forceSSL = true;
sslCertificate = config.sops.secrets."ssl_blakedheld_crt".path;
sslCertificateKey = config.sops.secrets."ssl_blakedheld_key".path;
locations."/" = {
proxyPass = "http://127.0.0.1:${toString cfg.port}";
};
};
# add to backups
modules.system.backups.paths = lib.mkIf cfg.backup [ data_dir ];
};
}