2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-07-31 23:36:15 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2013-07-31 23:36:15 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.supybot;
|
2020-02-11 16:55:03 +00:00
|
|
|
isStateDirHome = hasPrefix "/home/" cfg.stateDir;
|
|
|
|
isStateDirVar = cfg.stateDir == "/var/lib/supybot";
|
2020-02-11 16:56:03 +00:00
|
|
|
pyEnv = pkgs.python3.withPackages (p: [ p.limnoria ] ++ (cfg.extraPackages p));
|
2013-07-31 23:36:15 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.supybot = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2020-02-11 16:56:03 +00:00
|
|
|
type = types.bool;
|
2013-07-31 23:36:15 +01:00
|
|
|
default = false;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Enable Supybot, an IRC bot (also known as Limnoria).";
|
2013-07-31 23:36:15 +01:00
|
|
|
};
|
|
|
|
|
2013-08-03 23:18:44 +01:00
|
|
|
stateDir = mkOption {
|
2020-02-11 16:52:48 +00:00
|
|
|
type = types.path;
|
|
|
|
default = if versionAtLeast config.system.stateVersion "20.09"
|
|
|
|
then "/var/lib/supybot"
|
|
|
|
else "/home/supybot";
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression "/var/lib/supybot";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The root directory, logs and plugins are stored here";
|
2013-07-31 23:36:15 +01:00
|
|
|
};
|
|
|
|
|
2013-08-03 23:18:44 +01:00
|
|
|
configFile = mkOption {
|
|
|
|
type = types.path;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2020-02-11 16:52:48 +00:00
|
|
|
Path to initial supybot config file. This can be generated by
|
2013-08-04 02:56:01 +01:00
|
|
|
running supybot-wizard.
|
2013-07-31 23:36:15 +01:00
|
|
|
|
2013-08-04 02:56:01 +01:00
|
|
|
Note: all paths should include the full path to the stateDir
|
|
|
|
directory (backup conf data logs logs/plugins plugins tmp web).
|
|
|
|
'';
|
2013-07-31 23:36:15 +01:00
|
|
|
};
|
|
|
|
|
2020-02-11 16:56:03 +00:00
|
|
|
plugins = mkOption {
|
|
|
|
type = types.attrsOf types.path;
|
|
|
|
default = {};
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2020-02-11 16:56:03 +00:00
|
|
|
Attribute set of additional plugins that will be symlinked to the
|
2022-07-28 22:19:15 +01:00
|
|
|
{file}`plugin` subdirectory.
|
2020-02-11 16:56:03 +00:00
|
|
|
|
|
|
|
Please note that you still need to add the plugins to the config
|
2022-07-28 22:19:15 +01:00
|
|
|
file (or with `!load`) using their attribute name.
|
2020-02-11 16:56:03 +00:00
|
|
|
'';
|
2021-10-03 17:06:03 +01:00
|
|
|
example = literalExpression ''
|
2020-02-11 16:56:03 +00:00
|
|
|
let
|
|
|
|
plugins = pkgs.fetchzip {
|
|
|
|
url = "https://github.com/ProgVal/Supybot-plugins/archive/57c2450c.zip";
|
|
|
|
sha256 = "077snf84ibnva3sbpzdfpfma6hcdw7dflwnhg6pw7mgnf0nd84qd";
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
Wikipedia = "''${plugins}/Wikipedia";
|
|
|
|
Decide = ./supy-decide;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPackages = mkOption {
|
2018-08-07 17:53:56 +01:00
|
|
|
type = types.functionTo (types.listOf types.package);
|
2020-02-11 16:56:03 +00:00
|
|
|
default = p: [];
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression "p: []";
|
2020-02-11 16:56:03 +00:00
|
|
|
description = ''
|
|
|
|
Extra Python packages available to supybot plugins. The
|
|
|
|
value must be a function which receives the attrset defined
|
|
|
|
in <varname>python3Packages</varname> as the sole argument.
|
|
|
|
'';
|
2021-10-03 17:06:03 +01:00
|
|
|
example = literalExpression "p: [ p.lxml p.requests ]";
|
2020-02-11 16:56:03 +00:00
|
|
|
};
|
|
|
|
|
2013-07-31 23:36:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2013-08-03 23:18:44 +01:00
|
|
|
|
2020-02-11 16:56:03 +00:00
|
|
|
environment.systemPackages = [ pkgs.python3Packages.limnoria ];
|
2013-07-31 23:36:15 +01:00
|
|
|
|
2020-02-10 16:56:51 +00:00
|
|
|
users.users.supybot = {
|
2013-08-04 02:56:01 +01:00
|
|
|
uid = config.ids.uids.supybot;
|
|
|
|
group = "supybot";
|
|
|
|
description = "Supybot IRC bot user";
|
|
|
|
home = cfg.stateDir;
|
2020-02-11 16:52:48 +00:00
|
|
|
isSystemUser = true;
|
2013-08-04 02:56:01 +01:00
|
|
|
};
|
2013-07-31 23:36:15 +01:00
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.groups.supybot = {
|
2013-08-04 02:56:01 +01:00
|
|
|
gid = config.ids.gids.supybot;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.supybot = {
|
|
|
|
description = "Supybot, an IRC bot";
|
2020-02-11 16:56:03 +00:00
|
|
|
documentation = [ "https://limnoria.readthedocs.io/" ];
|
2013-08-04 02:56:01 +01:00
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
preStart = ''
|
|
|
|
# This needs to be created afresh every time
|
2020-02-11 16:52:48 +00:00
|
|
|
rm -f '${cfg.stateDir}/supybot.cfg.bak'
|
2013-08-04 02:56:01 +01:00
|
|
|
'';
|
|
|
|
|
2020-09-09 08:31:27 +01:00
|
|
|
startLimitIntervalSec = 5 * 60; # 5 min
|
|
|
|
startLimitBurst = 1;
|
2013-08-04 02:56:01 +01:00
|
|
|
serviceConfig = {
|
2020-02-11 16:56:03 +00:00
|
|
|
ExecStart = "${pyEnv}/bin/supybot ${cfg.stateDir}/supybot.cfg";
|
2013-08-04 02:56:01 +01:00
|
|
|
PIDFile = "/run/supybot.pid";
|
|
|
|
User = "supybot";
|
|
|
|
Group = "supybot";
|
|
|
|
UMask = "0007";
|
|
|
|
Restart = "on-abort";
|
2020-02-11 16:55:03 +00:00
|
|
|
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
RemoveIPC = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
ProtectSystem = "full";
|
|
|
|
}
|
|
|
|
// optionalAttrs isStateDirVar {
|
|
|
|
StateDirectory = "supybot";
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
}
|
|
|
|
// optionalAttrs (!isStateDirHome) {
|
|
|
|
ProtectHome = true;
|
2013-07-31 23:36:15 +01:00
|
|
|
};
|
2013-08-04 02:56:01 +01:00
|
|
|
};
|
2013-07-31 23:36:15 +01:00
|
|
|
|
2020-02-11 16:52:48 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.stateDir}' 0700 supybot supybot - -"
|
|
|
|
"d '${cfg.stateDir}/backup' 0750 supybot supybot - -"
|
|
|
|
"d '${cfg.stateDir}/conf' 0750 supybot supybot - -"
|
|
|
|
"d '${cfg.stateDir}/data' 0750 supybot supybot - -"
|
|
|
|
"d '${cfg.stateDir}/plugins' 0750 supybot supybot - -"
|
|
|
|
"d '${cfg.stateDir}/logs' 0750 supybot supybot - -"
|
|
|
|
"d '${cfg.stateDir}/logs/plugins' 0750 supybot supybot - -"
|
|
|
|
"d '${cfg.stateDir}/tmp' 0750 supybot supybot - -"
|
|
|
|
"d '${cfg.stateDir}/web' 0750 supybot supybot - -"
|
|
|
|
"L '${cfg.stateDir}/supybot.cfg' - - - - ${cfg.configFile}"
|
2020-02-11 16:56:03 +00:00
|
|
|
]
|
|
|
|
++ (flip mapAttrsToList cfg.plugins (name: dest:
|
|
|
|
"L+ '${cfg.stateDir}/plugins/${name}' - - - - ${dest}"
|
|
|
|
));
|
2020-02-11 16:52:48 +00:00
|
|
|
|
2013-07-31 23:36:15 +01:00
|
|
|
};
|
|
|
|
}
|