forked from mirrors/nixpkgs
2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
111 lines
2.6 KiB
Nix
111 lines
2.6 KiB
Nix
{ 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 = lib.mdDoc ''
|
|
TCP port to accept mtproto connections on.
|
|
'';
|
|
};
|
|
|
|
users = mkOption {
|
|
type = types.attrsOf types.str;
|
|
example = {
|
|
tg = "00000000000000000000000000000000";
|
|
tg2 = "0123456789abcdef0123456789abcdef";
|
|
};
|
|
description = lib.mdDoc ''
|
|
Allowed users and their secrets. A secret is a 32 characters long hex string.
|
|
'';
|
|
};
|
|
|
|
secureOnly = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
description = lib.mdDoc ''
|
|
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 = lib.mdDoc ''
|
|
Tag for advertising that can be obtained from @MTProxybot.
|
|
'';
|
|
};
|
|
|
|
extraConfig = mkOption {
|
|
type = types.attrs;
|
|
default = {};
|
|
example = {
|
|
STATS_PRINT_PERIOD = 600;
|
|
};
|
|
description = lib.mdDoc ''
|
|
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;
|
|
};
|
|
};
|
|
|
|
};
|
|
|
|
}
|