2016-05-04 08:58:01 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.nzbget;
|
2019-04-22 12:06:33 +00:00
|
|
|
pkg = pkgs.nzbget;
|
|
|
|
stateDir = "/var/lib/nzbget";
|
|
|
|
configFile = "${stateDir}/nzbget.conf";
|
|
|
|
configOpts = concatStringsSep " " (mapAttrsToList (name: value: "-o ${name}=${value}") nixosOpts);
|
2016-05-04 08:58:01 +00:00
|
|
|
|
2019-04-22 12:06:33 +00:00
|
|
|
nixosOpts = {
|
|
|
|
# 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";
|
|
|
|
};
|
2016-05-04 08:58:01 +00:00
|
|
|
|
2019-04-22 12:06:33 +00:00
|
|
|
in
|
|
|
|
{
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "misc" "nzbget" "configFile" ] "The configuration of nzbget is now managed by users through the web interface.")
|
|
|
|
(mkRemovedOptionModule [ "services" "misc" "nzbget" "dataDir" ] "The data directory for nzbget is now /var/lib/nzbget.")
|
|
|
|
(mkRemovedOptionModule [ "services" "misc" "nzbget" "openFirewall" ] "The port used by nzbget is managed through the web interface so you should adjust your firewall rules accordingly.")
|
|
|
|
];
|
|
|
|
|
2019-04-22 12:06:33 +00:00
|
|
|
# interface
|
2019-01-13 12:38:20 +00:00
|
|
|
|
2019-04-22 12:06:33 +00:00
|
|
|
options = {
|
|
|
|
services.nzbget = {
|
|
|
|
enable = mkEnableOption "NZBGet";
|
2019-01-13 12:38:20 +00:00
|
|
|
|
2016-05-04 08:58:01 +00:00
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "nzbget";
|
|
|
|
description = "User account under which NZBGet runs";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "nzbget";
|
|
|
|
description = "Group under which NZBGet runs";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-04-22 12:06:33 +00:00
|
|
|
# implementation
|
|
|
|
|
2016-05-04 08:58:01 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.nzbget = {
|
|
|
|
description = "NZBGet Daemon";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = with pkgs; [
|
|
|
|
unrar
|
|
|
|
p7zip
|
|
|
|
];
|
|
|
|
preStart = ''
|
2019-04-22 12:06:33 +00:00
|
|
|
if [ ! -f ${configFile} ]; then
|
|
|
|
${pkgs.coreutils}/bin/install -m 0700 ${pkg}/share/nzbget/nzbget.conf ${configFile}
|
2019-02-13 16:38:33 +00:00
|
|
|
fi
|
2017-10-30 00:37:56 +00:00
|
|
|
'';
|
|
|
|
|
2016-05-04 08:58:01 +00:00
|
|
|
serviceConfig = {
|
2019-04-22 12:06:33 +00:00
|
|
|
StateDirectory = "nzbget";
|
|
|
|
StateDirectoryMode = "0750";
|
2016-05-04 08:58:01 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2019-04-22 12:06:33 +00:00
|
|
|
UMask = "0002";
|
2016-05-04 08:58:01 +00:00
|
|
|
Restart = "on-failure";
|
2019-04-22 12:06:33 +00:00
|
|
|
ExecStart = "${pkg}/bin/nzbget --server --configfile ${stateDir}/nzbget.conf ${configOpts}";
|
|
|
|
ExecStop = "${pkg}/bin/nzbget --quit";
|
2016-05-04 08:58:01 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.users = mkIf (cfg.user == "nzbget") {
|
2016-05-04 08:58:01 +00:00
|
|
|
nzbget = {
|
2019-04-22 12:06:33 +00:00
|
|
|
home = stateDir;
|
2016-05-04 08:58:01 +00:00
|
|
|
group = cfg.group;
|
|
|
|
uid = config.ids.uids.nzbget;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.groups = mkIf (cfg.group == "nzbget") {
|
2016-05-04 08:58:01 +00:00
|
|
|
nzbget = {
|
|
|
|
gid = config.ids.gids.nzbget;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|