2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.nzbget;
|
|
|
|
pkg = pkgs.nzbget;
|
|
|
|
stateDir = "/var/lib/nzbget";
|
|
|
|
configFile = "${stateDir}/nzbget.conf";
|
2024-09-19 14:19:46 +00:00
|
|
|
configOpts = lib.concatStringsSep " " (lib.mapAttrsToList (name: value: "-o ${name}=${lib.escapeShellArg (toStr value)}") cfg.settings);
|
2021-09-18 10:52:07 +00:00
|
|
|
toStr = v:
|
|
|
|
if v == true then "yes"
|
|
|
|
else if v == false then "no"
|
2024-09-19 14:19:46 +00:00
|
|
|
else if lib.isInt v then toString v
|
2021-09-18 10:52:07 +00:00
|
|
|
else v;
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
2024-09-19 14:19:46 +00:00
|
|
|
(lib.mkRemovedOptionModule [ "services" "misc" "nzbget" "configFile" ] "The configuration of nzbget is now managed by users through the web interface.")
|
|
|
|
(lib.mkRemovedOptionModule [ "services" "misc" "nzbget" "dataDir" ] "The data directory for nzbget is now /var/lib/nzbget.")
|
|
|
|
(lib.mkRemovedOptionModule [ "services" "misc" "nzbget" "openFirewall" ] "The port used by nzbget is managed through the web interface so you should adjust your firewall rules accordingly.")
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
# interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.nzbget = {
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkEnableOption "NZBGet, for downloading files from news servers";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
user = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "nzbget";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "User account under which NZBGet runs";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
group = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "nzbget";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Group under which NZBGet runs";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-09-18 10:52:07 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
settings = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (oneOf [ bool int str ]);
|
2021-09-18 10:52:07 +00:00
|
|
|
default = {};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-09-18 10:52:07 +00:00
|
|
|
NZBGet configuration, passed via command line using switch -o. Refer to
|
2022-08-12 12:06:08 +00:00
|
|
|
<https://github.com/nzbget/nzbget/blob/master/nzbget.conf>
|
2021-09-18 10:52:07 +00:00
|
|
|
for details on supported values.
|
|
|
|
'';
|
|
|
|
example = {
|
|
|
|
MainDir = "/data";
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# implementation
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2021-09-18 10:52:07 +00:00
|
|
|
services.nzbget.settings = {
|
|
|
|
# allows nzbget to run as a "simple" service
|
|
|
|
OutputMode = "loggable";
|
|
|
|
# use journald for logging
|
|
|
|
WriteLog = "none";
|
|
|
|
ErrorTarget = "screen";
|
|
|
|
WarningTarget = "screen";
|
|
|
|
InfoTarget = "screen";
|
|
|
|
DetailTarget = "screen";
|
|
|
|
# required paths
|
|
|
|
ConfigTemplate = "${pkg}/share/nzbget/nzbget.conf";
|
|
|
|
WebDir = "${pkg}/share/nzbget/webui";
|
|
|
|
# nixos handles package updates
|
|
|
|
UpdateCheck = "none";
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.nzbget = {
|
|
|
|
description = "NZBGet Daemon";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = with pkgs; [
|
|
|
|
unrar
|
|
|
|
p7zip
|
|
|
|
];
|
2021-09-18 10:52:07 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
preStart = ''
|
|
|
|
if [ ! -f ${configFile} ]; then
|
|
|
|
${pkgs.coreutils}/bin/install -m 0700 ${pkg}/share/nzbget/nzbget.conf ${configFile}
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
StateDirectory = "nzbget";
|
|
|
|
StateDirectoryMode = "0750";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
UMask = "0002";
|
|
|
|
Restart = "on-failure";
|
|
|
|
ExecStart = "${pkg}/bin/nzbget --server --configfile ${stateDir}/nzbget.conf ${configOpts}";
|
|
|
|
ExecStop = "${pkg}/bin/nzbget --quit";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
users.users = lib.mkIf (cfg.user == "nzbget") {
|
2020-04-24 23:36:52 +00:00
|
|
|
nzbget = {
|
|
|
|
home = stateDir;
|
|
|
|
group = cfg.group;
|
|
|
|
uid = config.ids.uids.nzbget;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
users.groups = lib.mkIf (cfg.group == "nzbget") {
|
2020-04-24 23:36:52 +00:00
|
|
|
nzbget = {
|
|
|
|
gid = config.ids.gids.nzbget;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|