···
cfg = config.services.supybot;
7
+
isStateDirHome = hasPrefix "/home/" cfg.stateDir;
8
+
isStateDirVar = cfg.stateDir == "/var/lib/supybot";
9
+
pyEnv = pkgs.python3.withPackages (p: [ p.limnoria ] ++ (cfg.extraPackages p));
19
-
description = "Enable Supybot, an IRC bot";
19
+
description = "Enable Supybot, an IRC bot (also known as Limnoria).";
23
-
# Setting this to /var/lib/supybot caused useradd to fail
24
-
default = "/home/supybot";
24
+
default = if versionAtLeast config.system.stateVersion "20.09"
25
+
then "/var/lib/supybot"
26
+
else "/home/supybot";
27
+
defaultText = "/var/lib/supybot";
description = "The root directory, logs and plugins are stored here";
31
-
Path to a supybot config file. This can be generated by
34
+
Path to initial supybot config file. This can be generated by
Note: all paths should include the full path to the stateDir
···
42
+
plugins = mkOption {
43
+
type = types.attrsOf types.path;
46
+
Attribute set of additional plugins that will be symlinked to the
47
+
<filename>plugin</filename> subdirectory.
49
+
Please note that you still need to add the plugins to the config
50
+
file (or with <literal>!load</literal>) using their attribute name.
52
+
example = literalExample ''
54
+
plugins = pkgs.fetchzip {
55
+
url = "https://github.com/ProgVal/Supybot-plugins/archive/57c2450c.zip";
56
+
sha256 = "077snf84ibnva3sbpzdfpfma6hcdw7dflwnhg6pw7mgnf0nd84qd";
60
+
Wikipedia = "''${plugins}/Wikipedia";
61
+
Decide = ./supy-decide;
66
+
extraPackages = mkOption {
69
+
Extra Python packages available to supybot plugins. The
70
+
value must be a function which receives the attrset defined
71
+
in <varname>python3Packages</varname> as the sole argument.
73
+
example = literalExample ''p: [ p.lxml p.requests ]'';
config = mkIf cfg.enable {
46
-
environment.systemPackages = [ pkgs.pythonPackages.limnoria ];
82
+
environment.systemPackages = [ pkgs.python3Packages.limnoria ];
uid = config.ids.uids.supybot;
description = "Supybot IRC bot user";
89
+
isSystemUser = true;
···
systemd.services.supybot = {
description = "Supybot, an IRC bot";
98
+
documentation = [ "https://limnoria.readthedocs.io/" ];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
64
-
path = [ pkgs.pythonPackages.limnoria ];
67
-
mkdir -p backup conf data plugins logs/plugins tmp web
68
-
ln -sf ${cfg.configFile} supybot.cfg
# This needs to be created afresh every time
70
-
rm -f supybot.cfg.bak
103
+
rm -f '${cfg.stateDir}/supybot.cfg.bak'
74
-
ExecStart = "${pkgs.pythonPackages.limnoria}/bin/supybot ${cfg.stateDir}/supybot.cfg";
107
+
ExecStart = "${pyEnv}/bin/supybot ${cfg.stateDir}/supybot.cfg";
PIDFile = "/run/supybot.pid";
···
StartLimitInterval = "5m";
116
+
NoNewPrivileges = true;
117
+
PrivateDevices = true;
118
+
PrivateMounts = true;
120
+
ProtectControlGroups = true;
121
+
ProtectKernelModules = true;
122
+
ProtectKernelTunables = true;
123
+
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
124
+
RestrictSUIDSGID = true;
125
+
SystemCallArchitectures = "native";
126
+
RestrictNamespaces = true;
127
+
RestrictRealtime = true;
128
+
LockPersonality = true;
129
+
MemoryDenyWriteExecute = true;
131
+
ProtectHostname = true;
132
+
CapabilityBoundingSet = "";
133
+
ProtectSystem = "full";
135
+
// optionalAttrs isStateDirVar {
136
+
StateDirectory = "supybot";
137
+
ProtectSystem = "strict";
139
+
// optionalAttrs (!isStateDirHome) {
140
+
ProtectHome = true;
144
+
systemd.tmpfiles.rules = [
145
+
"d '${cfg.stateDir}' 0700 supybot supybot - -"
146
+
"d '${cfg.stateDir}/backup' 0750 supybot supybot - -"
147
+
"d '${cfg.stateDir}/conf' 0750 supybot supybot - -"
148
+
"d '${cfg.stateDir}/data' 0750 supybot supybot - -"
149
+
"d '${cfg.stateDir}/plugins' 0750 supybot supybot - -"
150
+
"d '${cfg.stateDir}/logs' 0750 supybot supybot - -"
151
+
"d '${cfg.stateDir}/logs/plugins' 0750 supybot supybot - -"
152
+
"d '${cfg.stateDir}/tmp' 0750 supybot supybot - -"
153
+
"d '${cfg.stateDir}/web' 0750 supybot supybot - -"
154
+
"L '${cfg.stateDir}/supybot.cfg' - - - - ${cfg.configFile}"
156
+
++ (flip mapAttrsToList cfg.plugins (name: dest:
157
+
"L+ '${cfg.stateDir}/plugins/${name}' - - - - ${dest}"