at 23.11-pre 1.7 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 (lib.mdDoc "the sabnzbd server"); 19 20 package = mkOption { 21 type = types.package; 22 default = pkgs.sabnzbd; 23 defaultText = lib.literalExpression "pkgs.sabnzbd"; 24 description = lib.mdDoc "The sabnzbd executable package run by the service."; 25 }; 26 27 configFile = mkOption { 28 type = types.path; 29 default = "/var/lib/sabnzbd/sabnzbd.ini"; 30 description = lib.mdDoc "Path to config file."; 31 }; 32 33 user = mkOption { 34 default = "sabnzbd"; 35 type = types.str; 36 description = lib.mdDoc "User to run the service as"; 37 }; 38 39 group = mkOption { 40 type = types.str; 41 default = "sabnzbd"; 42 description = lib.mdDoc "Group to run the service as"; 43 }; 44 }; 45 }; 46 47 48 ###### implementation 49 50 config = mkIf cfg.enable { 51 52 users.users.sabnzbd = { 53 uid = config.ids.uids.sabnzbd; 54 group = "sabnzbd"; 55 description = "sabnzbd user"; 56 home = "/var/lib/sabnzbd/"; 57 createHome = true; 58 }; 59 60 users.groups.sabnzbd = { 61 gid = config.ids.gids.sabnzbd; 62 }; 63 64 systemd.services.sabnzbd = { 65 description = "sabnzbd server"; 66 wantedBy = [ "multi-user.target" ]; 67 after = [ "network.target" ]; 68 serviceConfig = { 69 Type = "forking"; 70 GuessMainPID = "no"; 71 User = "${cfg.user}"; 72 Group = "${cfg.group}"; 73 ExecStart = "${lib.getBin cfg.package}/bin/sabnzbd -d -f ${cfg.configFile}"; 74 }; 75 }; 76 }; 77}