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