2019-12-18 07:57:31 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.qbittorrent;
|
|
|
|
configDir = "${cfg.dataDir}/.config";
|
|
|
|
openFilesLimit = 4096;
|
2020-07-31 04:17:28 +00:00
|
|
|
in
|
|
|
|
{
|
2019-12-18 07:57:31 +00:00
|
|
|
options.services.qbittorrent = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Run qBittorrent headlessly as systemwide daemon
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/qbittorrent";
|
|
|
|
description = ''
|
|
|
|
The directory where qBittorrent will create files.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "qbittorrent";
|
|
|
|
description = ''
|
|
|
|
User account under which qBittorrent runs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "qbittorrent";
|
|
|
|
description = ''
|
|
|
|
Group under which qBittorrent runs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8080;
|
|
|
|
description = ''
|
|
|
|
qBittorrent web UI port.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-01-01 23:24:36 +00:00
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Open services.qBittorrent.port to the outside network.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-12-18 07:57:31 +00:00
|
|
|
openFilesLimit = mkOption {
|
|
|
|
default = openFilesLimit;
|
|
|
|
description = ''
|
|
|
|
Number of files to allow qBittorrent to open.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.qbittorrent ];
|
|
|
|
|
|
|
|
nixpkgs.overlays = [
|
2020-01-04 22:30:00 +00:00
|
|
|
(final: prev: {
|
|
|
|
qbittorrent = prev.qbittorrent.override { guiSupport = false; };
|
2020-01-04 05:06:31 +00:00
|
|
|
})
|
2019-12-18 07:57:31 +00:00
|
|
|
];
|
|
|
|
|
2020-01-01 23:24:36 +00:00
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ cfg.port ];
|
|
|
|
allowedUDPPorts = [ cfg.port ];
|
|
|
|
};
|
|
|
|
|
2019-12-18 07:57:31 +00:00
|
|
|
systemd.services.qbittorrent = {
|
|
|
|
after = [ "network.target" ];
|
|
|
|
description = "qBittorrent Daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.qbittorrent ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.qbittorrent}/bin/qbittorrent-nox \
|
|
|
|
--profile=${configDir} \
|
|
|
|
--webui-port=${toString cfg.port}
|
|
|
|
'';
|
|
|
|
# To prevent "Quit & shutdown daemon" from working; we want systemd to
|
|
|
|
# manage it!
|
|
|
|
Restart = "on-success";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
UMask = "0002";
|
|
|
|
LimitNOFILE = cfg.openFilesLimit;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users = mkIf (cfg.user == "qbittorrent") {
|
|
|
|
qbittorrent = {
|
|
|
|
group = cfg.group;
|
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
|
|
|
description = "qBittorrent Daemon user";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-01-04 05:06:31 +00:00
|
|
|
users.groups =
|
|
|
|
mkIf (cfg.group == "qbittorrent") { qbittorrent = { gid = null; }; };
|
2019-12-18 07:57:31 +00:00
|
|
|
};
|
|
|
|
}
|