mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-13 16:15:30 +00:00
123 lines
3.6 KiB
Nix
123 lines
3.6 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.services.supybot;
|
|
isStateDirHome = hasPrefix "/home/" cfg.stateDir;
|
|
isStateDirVar = cfg.stateDir == "/var/lib/supybot";
|
|
in
|
|
{
|
|
options = {
|
|
|
|
services.supybot = {
|
|
|
|
enable = mkOption {
|
|
default = false;
|
|
description = "Enable Supybot, an IRC bot";
|
|
};
|
|
|
|
stateDir = mkOption {
|
|
type = types.path;
|
|
default = if versionAtLeast config.system.stateVersion "20.09"
|
|
then "/var/lib/supybot"
|
|
else "/home/supybot";
|
|
defaultText = "/var/lib/supybot";
|
|
description = "The root directory, logs and plugins are stored here";
|
|
};
|
|
|
|
configFile = mkOption {
|
|
type = types.path;
|
|
description = ''
|
|
Path to initial supybot config file. This can be generated by
|
|
running supybot-wizard.
|
|
|
|
Note: all paths should include the full path to the stateDir
|
|
directory (backup conf data logs logs/plugins plugins tmp web).
|
|
'';
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ pkgs.pythonPackages.limnoria ];
|
|
|
|
users.users.supybot = {
|
|
uid = config.ids.uids.supybot;
|
|
group = "supybot";
|
|
description = "Supybot IRC bot user";
|
|
home = cfg.stateDir;
|
|
isSystemUser = true;
|
|
};
|
|
|
|
users.groups.supybot = {
|
|
gid = config.ids.gids.supybot;
|
|
};
|
|
|
|
systemd.services.supybot = {
|
|
description = "Supybot, an IRC bot";
|
|
after = [ "network.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
path = [ pkgs.pythonPackages.limnoria ];
|
|
preStart = ''
|
|
# This needs to be created afresh every time
|
|
rm -f '${cfg.stateDir}/supybot.cfg.bak'
|
|
'';
|
|
|
|
serviceConfig = {
|
|
ExecStart = "${pkgs.pythonPackages.limnoria}/bin/supybot ${cfg.stateDir}/supybot.cfg";
|
|
PIDFile = "/run/supybot.pid";
|
|
User = "supybot";
|
|
Group = "supybot";
|
|
UMask = "0007";
|
|
Restart = "on-abort";
|
|
StartLimitInterval = "5m";
|
|
StartLimitBurst = "1";
|
|
|
|
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;
|
|
};
|
|
};
|
|
|
|
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}"
|
|
];
|
|
|
|
};
|
|
}
|