1 { config, lib, pkgs, ... }:
7 cfg = config.services.mtprotoproxy;
12 SECURE_ONLY = cfg.secureOnly;
13 } // lib.optionalAttrs (cfg.adTag != null) { AD_TAG = cfg.adTag; }
17 if isString opt || isInt opt then
19 else if isBool opt then
20 if opt then "True" else "False"
21 else if isList opt then
22 "[" + concatMapStringsSep "," convertOption opt + "]"
23 else if isAttrs opt then
24 "{" + concatStringsSep "," (mapAttrsToList (name: opt: "${builtins.toJSON name}: ${convertOption opt}") opt) + "}"
26 throw "Invalid option type";
28 configFile = pkgs.writeText "config.py" (concatStringsSep "\n" (mapAttrsToList (name: opt: "${name} = ${convertOption opt}") configOpts));
38 services.mtprotoproxy = {
40 enable = mkEnableOption "mtprotoproxy";
46 TCP port to accept mtproto connections on.
51 type = types.attrsOf types.str;
53 tg = "00000000000000000000000000000000";
54 tg2 = "0123456789abcdef0123456789abcdef";
57 Allowed users and their secrets. A secret is a 32 characters long hex string.
61 secureOnly = mkOption {
65 Don't allow users to connect in non-secure mode (without random padding).
70 type = types.nullOr types.str;
72 # Taken from mtproxyproto's repo.
73 example = "3c09c680b76ee91a4c25ad51f742267d";
75 Tag for advertising that can be obtained from @MTProxybot.
79 extraConfig = mkOption {
83 STATS_PRINT_PERIOD = 600;
86 Extra configuration options for mtprotoproxy.
97 config = mkIf cfg.enable {
99 systemd.services.mtprotoproxy = {
100 description = "MTProto Proxy Daemon";
101 wantedBy = [ "multi-user.target" ];
103 ExecStart = "${pkgs.mtprotoproxy}/bin/mtprotoproxy ${configFile}";