at 17.09-beta 2.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.supybot; 8 9in 10 11{ 12 13 options = { 14 15 services.supybot = { 16 17 enable = mkOption { 18 default = false; 19 description = "Enable Supybot, an IRC bot"; 20 }; 21 22 stateDir = mkOption { 23 # Setting this to /var/lib/supybot caused useradd to fail 24 default = "/home/supybot"; 25 description = "The root directory, logs and plugins are stored here"; 26 }; 27 28 configFile = mkOption { 29 type = types.path; 30 description = '' 31 Path to a supybot config file. This can be generated by 32 running supybot-wizard. 33 34 Note: all paths should include the full path to the stateDir 35 directory (backup conf data logs logs/plugins plugins tmp web). 36 ''; 37 }; 38 39 }; 40 41 }; 42 43 44 config = mkIf cfg.enable { 45 46 environment.systemPackages = [ pkgs.pythonPackages.limnoria ]; 47 48 users.extraUsers = singleton { 49 name = "supybot"; 50 uid = config.ids.uids.supybot; 51 group = "supybot"; 52 description = "Supybot IRC bot user"; 53 home = cfg.stateDir; 54 createHome = true; 55 }; 56 57 users.extraGroups.supybot = { 58 name = "supybot"; 59 gid = config.ids.gids.supybot; 60 }; 61 62 systemd.services.supybot = { 63 description = "Supybot, an IRC bot"; 64 after = [ "network.target" ]; 65 wantedBy = [ "multi-user.target" ]; 66 path = [ pkgs.pythonPackages.limnoria ]; 67 preStart = '' 68 cd ${cfg.stateDir} 69 mkdir -p backup conf data plugins logs/plugins tmp web 70 ln -sf ${cfg.configFile} supybot.cfg 71 # This needs to be created afresh every time 72 rm -f supybot.cfg.bak 73 ''; 74 75 serviceConfig = { 76 ExecStart = "${pkgs.pythonPackages.limnoria}/bin/supybot ${cfg.stateDir}/supybot.cfg"; 77 PIDFile = "/run/supybot.pid"; 78 User = "supybot"; 79 Group = "supybot"; 80 UMask = "0007"; 81 Restart = "on-abort"; 82 StartLimitInterval = "5m"; 83 StartLimitBurst = "1"; 84 }; 85 }; 86 87 }; 88}