···
cfg = config.services.supybot;
+
isStateDirHome = hasPrefix "/home/" cfg.stateDir;
+
isStateDirVar = cfg.stateDir == "/var/lib/supybot";
+
pyEnv = pkgs.python3.withPackages (p: [ p.limnoria ] ++ (cfg.extraPackages p));
+
description = "Enable Supybot, an IRC bot (also known as Limnoria).";
+
default = if versionAtLeast config.system.stateVersion "20.09"
+
then "/var/lib/supybot"
+
defaultText = "/var/lib/supybot";
description = "The root directory, logs and plugins are stored here";
+
Path to initial supybot config file. This can be generated by
Note: all paths should include the full path to the stateDir
···
+
type = types.attrsOf types.path;
+
Attribute set of additional plugins that will be symlinked to the
+
<filename>plugin</filename> subdirectory.
+
Please note that you still need to add the plugins to the config
+
file (or with <literal>!load</literal>) using their attribute name.
+
example = literalExample ''
+
plugins = pkgs.fetchzip {
+
url = "https://github.com/ProgVal/Supybot-plugins/archive/57c2450c.zip";
+
sha256 = "077snf84ibnva3sbpzdfpfma6hcdw7dflwnhg6pw7mgnf0nd84qd";
+
Wikipedia = "''${plugins}/Wikipedia";
+
Decide = ./supy-decide;
+
extraPackages = mkOption {
+
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.
+
example = literalExample ''p: [ p.lxml p.requests ]'';
config = mkIf cfg.enable {
+
environment.systemPackages = [ pkgs.python3Packages.limnoria ];
uid = config.ids.uids.supybot;
description = "Supybot IRC bot user";
···
systemd.services.supybot = {
description = "Supybot, an IRC bot";
+
documentation = [ "https://limnoria.readthedocs.io/" ];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
# This needs to be created afresh every time
+
rm -f '${cfg.stateDir}/supybot.cfg.bak'
+
ExecStart = "${pyEnv}/bin/supybot ${cfg.stateDir}/supybot.cfg";
PIDFile = "/run/supybot.pid";
···
StartLimitInterval = "5m";
+
NoNewPrivileges = true;
+
ProtectControlGroups = true;
+
ProtectKernelModules = true;
+
ProtectKernelTunables = true;
+
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
+
RestrictSUIDSGID = true;
+
SystemCallArchitectures = "native";
+
RestrictNamespaces = true;
+
RestrictRealtime = true;
+
LockPersonality = true;
+
MemoryDenyWriteExecute = true;
+
ProtectHostname = true;
+
CapabilityBoundingSet = "";
+
ProtectSystem = "full";
+
// optionalAttrs isStateDirVar {
+
StateDirectory = "supybot";
+
ProtectSystem = "strict";
+
// optionalAttrs (!isStateDirHome) {
+
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}"
+
++ (flip mapAttrsToList cfg.plugins (name: dest:
+
"L+ '${cfg.stateDir}/plugins/${name}' - - - - ${dest}"