feat(nixos/clbot): Add ability to post in multiple channels
Adds the ability to post to multiple channels by simply running multiple instances of clbot. We should probably implement support for this in clbot itself, but right now I can't be bothered to write Go. Change-Id: I5cffd0dc10a7f6cc19c37c5834c5610166b4ae23 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1771 Tested-by: BuildkiteCI Reviewed-by: kanepyork <rikingcoding@gmail.com> Reviewed-by: lukegb <lukegb@tvl.fyi>
This commit is contained in:
parent
1da8ace6a2
commit
a7868e4e17
2 changed files with 41 additions and 13 deletions
|
@ -2,26 +2,59 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (builtins) concatStringsSep attrValues mapAttrs;
|
inherit (builtins) attrValues concatStringsSep mapAttrs readFile;
|
||||||
|
inherit (pkgs) runCommandNoCC;
|
||||||
|
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
|
listToAttrs
|
||||||
mkEnableOption
|
mkEnableOption
|
||||||
mkIf
|
mkIf
|
||||||
mkOption
|
mkOption
|
||||||
|
removeSuffix
|
||||||
types;
|
types;
|
||||||
|
|
||||||
description = "CLBot forwards Gerrit notifications to IRC";
|
description = "Bot to forward CL notifications";
|
||||||
cfg = config.services.depot.clbot;
|
cfg = config.services.depot.clbot;
|
||||||
|
|
||||||
mkFlags = flags:
|
mkFlags = flags:
|
||||||
concatStringsSep " "
|
concatStringsSep " "
|
||||||
(attrValues (mapAttrs (key: value: "-${key} \"${toString value}\"") flags));
|
(attrValues (mapAttrs (key: value: "-${key} \"${toString value}\"") flags));
|
||||||
|
|
||||||
|
# Escapes a unit name for use in systemd
|
||||||
|
systemdEscape = name: removeSuffix "\n" (readFile (runCommandNoCC "unit-name" {} ''
|
||||||
|
${pkgs.systemd}/bin/systemd-escape '${name}' >> $out
|
||||||
|
''));
|
||||||
|
|
||||||
|
mkUnit = flags: channel: {
|
||||||
|
name = "clbot-${systemdEscape channel}";
|
||||||
|
value = {
|
||||||
|
description = "${description} to ${channel}";
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
|
script = "${config.depot.fun.clbot}/bin/clbot ${mkFlags (cfg.flags // {
|
||||||
|
irc_channel = channel;
|
||||||
|
})} -alsologtostderr";
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
User = "clbot";
|
||||||
|
EnvironmentFile = "/etc/secrets/clbot";
|
||||||
|
Restart = "always";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
options.services.depot.clbot = {
|
options.services.depot.clbot = {
|
||||||
enable = mkEnableOption description;
|
enable = mkEnableOption description;
|
||||||
|
|
||||||
flags = mkOption {
|
flags = mkOption {
|
||||||
type = types.attrsOf types.str;
|
type = types.attrsOf types.str;
|
||||||
description = "Key value pairs for command line flags";
|
description = "Key value pairs for command line flags";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
channels = mkOption {
|
||||||
|
type = with types; listOf str;
|
||||||
|
description = "Channels in which to post (generates one unit per channel)";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
@ -37,16 +70,6 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services.clbot = {
|
systemd.services = listToAttrs (map (mkUnit cfg.flags) cfg.channels);
|
||||||
inherit description;
|
|
||||||
script = "${config.depot.fun.clbot}/bin/clbot ${mkFlags cfg.flags} -alsologtostderr";
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
|
|
||||||
serviceConfig = {
|
|
||||||
User = "clbot";
|
|
||||||
EnvironmentFile = "/etc/secrets/clbot";
|
|
||||||
Restart = "always";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,6 +218,11 @@ in lib.fix(self: {
|
||||||
# populated from /etc/secrets/clbot
|
# populated from /etc/secrets/clbot
|
||||||
irc_pass = "$CLBOT_PASS";
|
irc_pass = "$CLBOT_PASS";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
channels = [
|
||||||
|
"##tvl"
|
||||||
|
"##tvl-dev"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
services.depot = {
|
services.depot = {
|
||||||
|
|
Loading…
Reference in a new issue