1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8with lib;
9
10let
11
12 cfg = config.services.sabnzbd;
13 inherit (pkgs) sabnzbd;
14
15in
16
17{
18
19 ###### interface
20
21 options = {
22 services.sabnzbd = {
23 enable = mkEnableOption "the sabnzbd server";
24
25 package = mkPackageOption pkgs "sabnzbd" { };
26
27 configFile = mkOption {
28 type = types.path;
29 default = "/var/lib/sabnzbd/sabnzbd.ini";
30 description = "Path to config file.";
31 };
32
33 user = mkOption {
34 default = "sabnzbd";
35 type = types.str;
36 description = "User to run the service as";
37 };
38
39 group = mkOption {
40 type = types.str;
41 default = "sabnzbd";
42 description = "Group to run the service as";
43 };
44
45 openFirewall = mkOption {
46 type = types.bool;
47 default = false;
48 description = ''
49 Open ports in the firewall for the sabnzbd web interface
50 '';
51 };
52 };
53 };
54
55 ###### implementation
56
57 config = mkIf cfg.enable {
58 users.users = mkIf (cfg.user == "sabnzbd") {
59 sabnzbd = {
60 uid = config.ids.uids.sabnzbd;
61 group = cfg.group;
62 description = "sabnzbd user";
63 };
64 };
65
66 users.groups = mkIf (cfg.group == "sabnzbd") {
67 sabnzbd.gid = config.ids.gids.sabnzbd;
68 };
69
70 systemd.services.sabnzbd = {
71 description = "sabnzbd server";
72 wantedBy = [ "multi-user.target" ];
73 after = [ "network.target" ];
74 serviceConfig = {
75 Type = "forking";
76 GuessMainPID = "no";
77 User = cfg.user;
78 Group = cfg.group;
79 StateDirectory = "sabnzbd";
80 ExecStart = "${lib.getBin cfg.package}/bin/sabnzbd -d -f ${cfg.configFile}";
81 };
82 };
83
84 networking.firewall = mkIf cfg.openFirewall {
85 allowedTCPPorts = [ 8080 ];
86 };
87 };
88}