2019-04-23 20:52:23 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
dataDir = "/var/lib/tedicross";
|
|
|
|
cfg = config.services.tedicross;
|
|
|
|
configJSON = pkgs.writeText "tedicross-settings.json" (builtins.toJSON cfg.config);
|
|
|
|
configYAML = pkgs.runCommand "tedicross-settings.yaml" { preferLocalBuild = true; } ''
|
|
|
|
${pkgs.remarshal}/bin/json2yaml -i ${configJSON} -o $out
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.tedicross = {
|
2022-08-28 19:18:44 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "the TediCross Telegram-Discord bridge service");
|
2019-04-23 20:52:23 +00:00
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
# from https://github.com/TediCross/TediCross/blob/master/example.settings.yaml
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression ''
|
2019-04-23 20:52:23 +00:00
|
|
|
{
|
|
|
|
telegram = {
|
|
|
|
useFirstNameInsteadOfUsername = false;
|
|
|
|
colonAfterSenderName = false;
|
|
|
|
skipOldMessages = true;
|
|
|
|
sendEmojiWithStickers = true;
|
|
|
|
};
|
|
|
|
discord = {
|
|
|
|
useNickname = false;
|
|
|
|
skipOldMessages = true;
|
|
|
|
displayTelegramReplies = "embed";
|
|
|
|
replyLength = 100;
|
|
|
|
};
|
|
|
|
bridges = [
|
|
|
|
{
|
|
|
|
name = "Default bridge";
|
|
|
|
direction = "both";
|
|
|
|
telegram = {
|
|
|
|
chatId = -123456789;
|
|
|
|
relayJoinMessages = true;
|
|
|
|
relayLeaveMessages = true;
|
|
|
|
sendUsernames = true;
|
|
|
|
ignoreCommands = true;
|
|
|
|
};
|
|
|
|
discord = {
|
|
|
|
serverId = "DISCORD_SERVER_ID";
|
|
|
|
channelId = "DISCORD_CHANNEL_ID";
|
|
|
|
relayJoinMessages = true;
|
|
|
|
relayLeaveMessages = true;
|
|
|
|
sendUsernames = true;
|
|
|
|
crossDeleteOnTelegram = true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
debug = false;
|
|
|
|
}
|
|
|
|
'';
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
{file}`settings.yaml` configuration as a Nix attribute set.
|
|
|
|
Secret tokens should be specified using {option}`environmentFile`
|
2019-04-23 20:52:23 +00:00
|
|
|
instead of this world-readable file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
environmentFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2019-04-23 20:52:23 +00:00
|
|
|
File containing environment variables to be passed to the TediCross service,
|
|
|
|
in which secret tokens can be specified securely using the
|
2022-07-28 21:19:15 +00:00
|
|
|
`TELEGRAM_BOT_TOKEN` and `DISCORD_BOT_TOKEN`
|
2019-04-23 20:52:23 +00:00
|
|
|
keys.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
# from https://github.com/TediCross/TediCross/blob/master/guides/autostart/Linux.md
|
|
|
|
systemd.services.tedicross = {
|
|
|
|
description = "TediCross Telegram-Discord bridge service";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart = "${pkgs.nodePackages.tedicross}/bin/tedicross --config='${configYAML}' --data-dir='${dataDir}'";
|
|
|
|
Restart = "always";
|
|
|
|
DynamicUser = true;
|
|
|
|
StateDirectory = baseNameOf dataDir;
|
|
|
|
EnvironmentFile = cfg.environmentFile;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ pacien ];
|
|
|
|
}
|
|
|
|
|