2013-07-31 15:36:15 -07:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.supybot;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.supybot = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
2013-08-03 15:18:44 -07:00
|
|
|
description = "Enable Supybot, an IRC bot";
|
2013-07-31 15:36:15 -07:00
|
|
|
};
|
|
|
|
|
2013-08-03 15:18:44 -07:00
|
|
|
stateDir = mkOption {
|
|
|
|
default = "/var/lib/supybot";
|
2013-07-31 15:36:15 -07:00
|
|
|
description = "
|
2013-08-03 15:18:44 -07:00
|
|
|
|
2013-07-31 15:36:15 -07:00
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2013-08-03 15:18:44 -07:00
|
|
|
configFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = /dev/null;
|
2013-07-31 15:36:15 -07:00
|
|
|
description = ''
|
|
|
|
Verbatim contents of the supybot config, this can be
|
|
|
|
generated by supybot-wizard
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = "supybot";
|
|
|
|
description = "User account under which supybot runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = "supybot";
|
|
|
|
description = "Group account under which supybot runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2013-08-03 15:18:44 -07:00
|
|
|
|
2013-07-31 15:36:15 -07:00
|
|
|
environment.systemPackages = [ pkgs.pythonPackages.limnoria ];
|
|
|
|
|
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = cfg.user;
|
|
|
|
uid = config.ids.uids.supybot;
|
|
|
|
group = "supybot";
|
|
|
|
description = "Supybot IRC bot user";
|
2013-08-03 15:18:44 -07:00
|
|
|
home = cfg.stateDir;
|
2013-07-31 15:36:15 -07:00
|
|
|
createHome = true;
|
2013-08-03 15:18:44 -07:00
|
|
|
};
|
2013-07-31 15:36:15 -07:00
|
|
|
|
|
|
|
users.extraGroups.supybot = {};
|
|
|
|
|
|
|
|
systemd.services.supybot =
|
|
|
|
{ description = "Supybot IRC bot";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.pythonPackages.limnoria ];
|
|
|
|
preStart = ''
|
2013-08-03 15:18:44 -07:00
|
|
|
mkdir -m 0755 -p ${cfg.stateDir}
|
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.stateDir}
|
|
|
|
cd ${cfg.stateDir}
|
2013-07-31 15:36:15 -07:00
|
|
|
mkdir -p logs/plugins backup conf data plugins tmp
|
2013-08-03 15:18:44 -07:00
|
|
|
ln -sf ${cfg.configFile} supybot.cfg
|
|
|
|
rm -f supybot.cfg.bak
|
2013-07-31 15:36:15 -07:00
|
|
|
'';
|
|
|
|
serviceConfig =
|
|
|
|
{ ExecStart =
|
2013-08-03 15:18:44 -07:00
|
|
|
"${pkgs.pythonPackages.limnoria}/bin/supybot ${cfg.stateDir}/supybot.cfg";
|
2013-07-31 15:36:15 -07:00
|
|
|
PIDFile = "/run/supybot.pid";
|
2013-08-03 15:18:44 -07:00
|
|
|
User = "${cfg.user}";
|
2013-07-31 15:36:15 -07:00
|
|
|
Group = "${cfg.group}";
|
|
|
|
UMask = "0007";
|
|
|
|
Restart = "on-abort";
|
|
|
|
StartLimitInterval = "5m";
|
|
|
|
StartLimitBurst = "1";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|