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