dotfiles/system/modules/qbittorrent.nix

78 lines
2.5 KiB
Nix
Raw Permalink Normal View History

2023-12-01 23:45:17 +07:00
{ config
, lib
, pkgs
, ...
}:
2023-11-29 01:50:24 +07:00
let
cfg = config.services.qbittorrent-nox;
in {
options.services.qbittorrent-nox = {
enable = lib.mkEnableOption "qbittorrent-nox";
2023-12-01 23:45:17 +07:00
2024-08-15 09:06:06 +07:00
package = lib.mkPackageOption pkgs "qbittorrent-nox" { };
2023-12-01 23:45:17 +07:00
2023-11-29 01:50:24 +07:00
ui.addToFirewall = lib.mkOption {
description = "Add the web UI port to firewall";
type = lib.types.bool;
default = false;
};
ui.port = lib.mkOption {
description = "Web UI port";
type = lib.types.port;
default = 8080;
};
2023-12-01 23:45:17 +07:00
2023-11-29 01:50:24 +07:00
torrent.addToFirewall = lib.mkOption {
description = "Add the torrenting port to firewall";
type = lib.types.bool;
default = true;
};
torrent.port = lib.mkOption {
description = "Torrenting port";
type = with lib.types; nullOr port;
default = null;
};
};
2023-12-01 23:45:17 +07:00
2023-11-29 01:50:24 +07:00
config = lib.mkIf cfg.enable {
networking.firewall.allowedTCPPorts =
lib.optional (cfg.torrent.addToFirewall && cfg.torrent.port != null) cfg.torrent.port
2023-12-01 23:45:17 +07:00
++ lib.optional cfg.ui.addToFirewall cfg.ui.port;
2023-11-29 01:50:24 +07:00
networking.firewall.allowedUDPPorts =
lib.optional (cfg.torrent.addToFirewall && cfg.torrent.port != null) cfg.torrent.port;
2023-12-01 23:45:17 +07:00
users.users.qbittorrent-nox = {
isSystemUser = true;
group = "qbittorrent-nox";
home = "/var/lib/qbittorrent-nox";
};
users.groups.qbittorrent-nox = { };
2023-11-29 01:50:24 +07:00
systemd.services.qbittorrent-nox = {
description = "qBittorrent-nox service";
wants = [ "network-online.target" ];
after = [ "local-fs.target" "network-online.target" "nss-lookup.target" ];
wantedBy = [ "multi-user.target" ];
unitConfig.Documentation = "man:qbittorrent-nox(1)";
2023-12-01 23:45:17 +07:00
# required for reverse proxying
2023-11-29 01:50:24 +07:00
preStart = ''
if [[ ! -f /var/lib/qbittorrent-nox/qBittorrent/config/qBittorrent.conf ]]; then
mkdir -p /var/lib/qbittorrent-nox/qBittorrent/config
2023-12-01 23:45:17 +07:00
echo "Preferences\WebUI\HostHeaderValidation=false" >> /var/lib/qbittorrent-nox/qBittorrent/config/qBittorrent.conf
2023-11-29 01:50:24 +07:00
fi
'';
serviceConfig = {
User = "qbittorrent-nox";
Group = "qbittorrent-nox";
StateDirectory = "qbittorrent-nox";
WorkingDirectory = "/var/lib/qbittorrent-nox";
ExecStart = ''
${cfg.package}/bin/qbittorrent-nox ${lib.optionalString (cfg.torrent.port != null) "--torrenting-port=${toString cfg.torrent.port}"} \
--webui-port=${toString cfg.ui.port} --profile=/var/lib/qbittorrent-nox
'';
};
};
};
}