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