12 cfg = config.services.mtprotoproxy;
18 SECURE_ONLY = cfg.secureOnly;
20 // lib.optionalAttrs (cfg.adTag != null) { AD_TAG = cfg.adTag; }
25 if isString opt || isInt opt then
27 else if isBool opt then
28 if opt then "True" else "False"
29 else if isList opt then
30 "[" + concatMapStringsSep "," convertOption opt + "]"
31 else if isAttrs opt then
33 + concatStringsSep "," (
34 mapAttrsToList (name: opt: "${builtins.toJSON name}: ${convertOption opt}") opt
38 throw "Invalid option type";
40 configFile = pkgs.writeText "config.py" (
41 concatStringsSep "\n" (mapAttrsToList (name: opt: "${name} = ${convertOption opt}") configOpts)
52 services.mtprotoproxy = {
54 enable = mkEnableOption "mtprotoproxy";
60 TCP port to accept mtproto connections on.
65 type = types.attrsOf types.str;
67 tg = "00000000000000000000000000000000";
68 tg2 = "0123456789abcdef0123456789abcdef";
71 Allowed users and their secrets. A secret is a 32 characters long hex string.
75 secureOnly = mkOption {
79 Don't allow users to connect in non-secure mode (without random padding).
84 type = types.nullOr types.str;
86 # Taken from mtproxyproto's repo.
87 example = "3c09c680b76ee91a4c25ad51f742267d";
89 Tag for advertising that can be obtained from @MTProxybot.
93 extraConfig = mkOption {
97 STATS_PRINT_PERIOD = 600;
100 Extra configuration options for mtprotoproxy.
108 ###### implementation
110 config = mkIf cfg.enable {
112 systemd.services.mtprotoproxy = {
113 description = "MTProto Proxy Daemon";
114 wantedBy = [ "multi-user.target" ];
116 ExecStart = "${pkgs.mtprotoproxy}/bin/mtprotoproxy ${configFile}";