2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.sabnzbd;
|
|
|
|
inherit (pkgs) sabnzbd;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.sabnzbd = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "the sabnzbd server";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "sabnzbd" { };
|
2021-12-06 16:07:01 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
configFile = mkOption {
|
2021-02-05 17:12:51 +00:00
|
|
|
type = types.path;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "/var/lib/sabnzbd/sabnzbd.ini";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Path to config file.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = "sabnzbd";
|
2021-02-05 17:12:51 +00:00
|
|
|
type = types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "User to run the service as";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
2021-02-05 17:12:51 +00:00
|
|
|
type = types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "sabnzbd";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Group to run the service as";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2024-02-29 20:09:43 +00:00
|
|
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2024-02-29 20:09:43 +00:00
|
|
|
Open ports in the firewall for the sabnzbd web interface
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2024-02-29 20:09:43 +00:00
|
|
|
users.users = mkIf (cfg.user == "sabnzbd") {
|
|
|
|
sabnzbd = {
|
|
|
|
uid = config.ids.uids.sabnzbd;
|
|
|
|
group = cfg.group;
|
|
|
|
description = "sabnzbd user";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
users.groups = mkIf (cfg.group == "sabnzbd") {
|
|
|
|
sabnzbd.gid = config.ids.gids.sabnzbd;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.sabnzbd = {
|
|
|
|
description = "sabnzbd server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
GuessMainPID = "no";
|
2024-02-29 20:09:43 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
StateDirectory = "sabnzbd";
|
2021-12-06 16:07:01 +00:00
|
|
|
ExecStart = "${lib.getBin cfg.package}/bin/sabnzbd -d -f ${cfg.configFile}";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
2024-02-29 20:09:43 +00:00
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ 8080 ];
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|