mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
Merge pull request #62885 from abbradar/mtproxy
mtprotoproxy: init package and service
This commit is contained in:
commit
1d7d5d9be6
4 changed files with 142 additions and 0 deletions
|
@ -610,6 +610,7 @@
|
|||
./services/networking/morty.nix
|
||||
./services/networking/miredo.nix
|
||||
./services/networking/mstpd.nix
|
||||
./services/networking/mtprotoproxy.nix
|
||||
./services/networking/murmur.nix
|
||||
./services/networking/mxisd.nix
|
||||
./services/networking/namecoind.nix
|
||||
|
|
110
nixos/modules/services/networking/mtprotoproxy.nix
Normal file
110
nixos/modules/services/networking/mtprotoproxy.nix
Normal file
|
@ -0,0 +1,110 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
|
||||
cfg = config.services.mtprotoproxy;
|
||||
|
||||
configOpts = {
|
||||
PORT = cfg.port;
|
||||
USERS = cfg.users;
|
||||
SECURE_ONLY = cfg.secureOnly;
|
||||
} // lib.optionalAttrs (cfg.adTag != null) { AD_TAG = cfg.adTag; }
|
||||
// cfg.extraConfig;
|
||||
|
||||
convertOption = opt:
|
||||
if isString opt || isInt opt then
|
||||
builtins.toJSON opt
|
||||
else if isBool opt then
|
||||
if opt then "True" else "False"
|
||||
else if isList opt then
|
||||
"[" + concatMapStringsSep "," convertOption opt + "]"
|
||||
else if isAttrs opt then
|
||||
"{" + concatStringsSep "," (mapAttrsToList (name: opt: "${builtins.toJSON name}: ${convertOption opt}") opt) + "}"
|
||||
else
|
||||
throw "Invalid option type";
|
||||
|
||||
configFile = pkgs.writeText "config.py" (concatStringsSep "\n" (mapAttrsToList (name: opt: "${name} = ${convertOption opt}") configOpts));
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
|
||||
###### interface
|
||||
|
||||
options = {
|
||||
|
||||
services.mtprotoproxy = {
|
||||
|
||||
enable = mkEnableOption "mtprotoproxy";
|
||||
|
||||
port = mkOption {
|
||||
type = types.int;
|
||||
default = 3256;
|
||||
description = ''
|
||||
TCP port to accept mtproto connections on.
|
||||
'';
|
||||
};
|
||||
|
||||
users = mkOption {
|
||||
type = types.attrsOf types.str;
|
||||
example = {
|
||||
"tg" = "00000000000000000000000000000000";
|
||||
"tg2" = "0123456789abcdef0123456789abcdef";
|
||||
};
|
||||
description = ''
|
||||
Allowed users and their secrets. A secret is a 32 characters long hex string.
|
||||
'';
|
||||
};
|
||||
|
||||
secureOnly = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Don't allow users to connect in non-secure mode (without random padding).
|
||||
'';
|
||||
};
|
||||
|
||||
adTag = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
# Taken from mtproxyproto's repo.
|
||||
example = "3c09c680b76ee91a4c25ad51f742267d";
|
||||
description = ''
|
||||
Tag for advertising that can be obtained from @MTProxybot.
|
||||
'';
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
example = {
|
||||
"STATS_PRINT_PERIOD" = 600;
|
||||
};
|
||||
description = ''
|
||||
Extra configuration options for mtprotoproxy.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
###### implementation
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
||||
systemd.services.mtprotoproxy = {
|
||||
description = "MTProto Proxy Daemon";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
ExecStart = "${pkgs.mtprotoproxy}/bin/mtprotoproxy ${configFile}";
|
||||
DynamicUser = true;
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
29
pkgs/servers/mtprotoproxy/default.nix
Normal file
29
pkgs/servers/mtprotoproxy/default.nix
Normal file
|
@ -0,0 +1,29 @@
|
|||
{ stdenv, fetchFromGitHub, python, pyaes, pycrypto, wrapPython }:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "mtprotoproxy";
|
||||
version = "1.0.5";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "alexbers";
|
||||
repo = "mtprotoproxy";
|
||||
rev = "v${version}";
|
||||
sha256 = "11jaz01cagmqadyxkks7dx41ggg6pp2l1ia9npqyrl2xhcxm5b0x";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [ wrapPython ];
|
||||
pythonPath = [ pyaes pycrypto ];
|
||||
|
||||
installPhase = ''
|
||||
install -Dm755 mtprotoproxy.py $out/bin/mtprotoproxy
|
||||
wrapPythonPrograms
|
||||
'';
|
||||
|
||||
meta = with stdenv.lib; {
|
||||
description = "Async MTProto proxy for Telegram";
|
||||
license = licenses.mit;
|
||||
homepage = https://github.com/alexbers/mtprotoproxy;
|
||||
platforms = python.meta.platforms;
|
||||
maintainers = with maintainers; [ abbradar ];
|
||||
};
|
||||
}
|
|
@ -14326,6 +14326,8 @@ in
|
|||
|
||||
mpdscribble = callPackage ../tools/misc/mpdscribble { };
|
||||
|
||||
mtprotoproxy = python3.pkgs.callPackage ../servers/mtprotoproxy { };
|
||||
|
||||
micro-httpd = callPackage ../servers/http/micro-httpd { };
|
||||
|
||||
miniHttpd = callPackage ../servers/http/mini-httpd {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue