git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/tedicross: add module
commitd3423dd5c2259f0307e45abee7fad1b68c9f0393 authorpacien <pacien.trangirard@pacien.net> dateTue 23 Apr 2019, 22:52 (8 years ago) parentdf04850
2 files changed+101
nixos/modules/module-list.nix+1 nixos/modules/services/networking/tedicross.nix+100
nixos/modules/module-list.nix+1
@@ -672,6 +672,7 @@
672672 ./services/networking/syncthing-relay.nix
673673 ./services/networking/tcpcrypt.nix
674674 ./services/networking/teamspeak3.nix
675+ ./services/networking/tedicross.nix
675676 ./services/networking/tinc.nix
676677 ./services/networking/tinydns.nix
677678 ./services/networking/tftpd.nix
nixos/modules/services/networking/tedicross.nixnew file+100
@@ -0,0 +1,100 @@
1+{ config, pkgs, lib, ... }:
2+
3+with lib;
4+
5+let
6+ dataDir = "/var/lib/tedicross";
7+ cfg = config.services.tedicross;
8+ configJSON = pkgs.writeText "tedicross-settings.json" (builtins.toJSON cfg.config);
9+ configYAML = pkgs.runCommand "tedicross-settings.yaml" { preferLocalBuild = true; } ''
10+ ${pkgs.remarshal}/bin/json2yaml -i ${configJSON} -o $out
11+ '';
12+
13+in {
14+ options = {
15+ services.tedicross = {
16+ enable = mkEnableOption "the TediCross Telegram-Discord bridge service";
17+
18+ config = mkOption {
19+ type = types.attrs;
20+ # from https://github.com/TediCross/TediCross/blob/master/example.settings.yaml
21+ example = literalExample ''
22+ {
23+ telegram = {
24+ useFirstNameInsteadOfUsername = false;
25+ colonAfterSenderName = false;
26+ skipOldMessages = true;
27+ sendEmojiWithStickers = true;
28+ };
29+ discord = {
30+ useNickname = false;
31+ skipOldMessages = true;
32+ displayTelegramReplies = "embed";
33+ replyLength = 100;
34+ };
35+ bridges = [
36+ {
37+ name = "Default bridge";
38+ direction = "both";
39+ telegram = {
40+ chatId = -123456789;
41+ relayJoinMessages = true;
42+ relayLeaveMessages = true;
43+ sendUsernames = true;
44+ ignoreCommands = true;
45+ };
46+ discord = {
47+ serverId = "DISCORD_SERVER_ID";
48+ channelId = "DISCORD_CHANNEL_ID";
49+ relayJoinMessages = true;
50+ relayLeaveMessages = true;
51+ sendUsernames = true;
52+ crossDeleteOnTelegram = true;
53+ };
54+ }
55+ ];
56+
57+ debug = false;
58+ }
59+ '';
60+ description = ''
61+ <filename>settings.yaml</filename> configuration as a Nix attribute set.
62+ Secret tokens should be specified using <option>environmentFile</option>
63+ instead of this world-readable file.
64+ '';
65+ };
66+
67+ environmentFile = mkOption {
68+ type = types.nullOr types.path;
69+ default = null;
70+ description = ''
71+ File containing environment variables to be passed to the TediCross service,
72+ in which secret tokens can be specified securely using the
73+ <literal>TELEGRAM_BOT_TOKEN</literal> and <literal>DISCORD_BOT_TOKEN</literal>
74+ keys.
75+ '';
76+ };
77+ };
78+ };
79+
80+ config = mkIf cfg.enable {
81+ # from https://github.com/TediCross/TediCross/blob/master/guides/autostart/Linux.md
82+ systemd.services.tedicross = {
83+ description = "TediCross Telegram-Discord bridge service";
84+ wantedBy = [ "multi-user.target" ];
85+ wants = [ "network-online.target" ];
86+ after = [ "network-online.target" ];
87+ serviceConfig = {
88+ Type = "simple";
89+ ExecStart = "${pkgs.nodePackages.tedicross}/bin/tedicross --config='${configYAML}' --data-dir='${dataDir}'";
90+ Restart = "always";
91+ DynamicUser = true;
92+ StateDirectory = baseNameOf dataDir;
93+ EnvironmentFile = cfg.environmentFile;
94+ };
95+ };
96+ };
97+
98+ meta.maintainers = with maintainers; [ pacien ];
99+}
100+