57 lines
1.9 KiB
Nix
57 lines
1.9 KiB
Nix
self:
|
|
{ config, lib, pkgs, ... }:
|
|
let
|
|
cfg = config.services.slackerbot;
|
|
in
|
|
{
|
|
options.services.slackerbot = {
|
|
enable = lib.mkEnableOption "slackerbot";
|
|
mode = lib.mkOption {
|
|
type = lib.types.enum [ "master" "slave" ];
|
|
default = "master";
|
|
};
|
|
clusterPort = lib.mkOption {
|
|
type = lib.types.nullOr lib.types.port;
|
|
default = null;
|
|
description = "On the master: open this port for slaves (match cluster.listen).";
|
|
};
|
|
configFile = lib.mkOption {
|
|
type = lib.types.path;
|
|
};
|
|
environmentFile = lib.mkOption {
|
|
type = lib.types.nullOr lib.types.str;
|
|
default = null;
|
|
description = "SLACK_APP_TOKEN, SLACK_BOT_TOKEN, CLUSTER_SECRET and API keys, kept out of the Nix store.";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
systemd.network.enable = true;
|
|
systemd.network.networks."80-container-ve" = {
|
|
matchConfig.Name = "ve-*";
|
|
networkConfig = {
|
|
Address = "0.0.0.0/28";
|
|
LinkLocalAddressing = "yes";
|
|
DHCPServer = true;
|
|
IPMasquerade = "both";
|
|
};
|
|
};
|
|
networking.firewall.trustedInterfaces =
|
|
[ (if config.networking.nftables.enable then "ve-*" else "ve-+") ];
|
|
networking.firewall.allowedTCPPorts = lib.optional (cfg.clusterPort != null) cfg.clusterPort;
|
|
|
|
systemd.services.slackerbot = {
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [ "network-online.target" "systemd-machined.service" ];
|
|
wants = [ "network-online.target" ];
|
|
path = [ pkgs.systemd pkgs.btrfs-progs pkgs.e2fsprogs ];
|
|
serviceConfig = {
|
|
ExecStart = "${self.packages.${pkgs.stdenv.hostPlatform.system}.default}/bin/slackerbot -mode ${cfg.mode} -config ${cfg.configFile}";
|
|
EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
|
|
StateDirectory = "slackerbot";
|
|
Restart = "on-failure";
|
|
};
|
|
};
|
|
};
|
|
}
|