1 { config, lib, pkgs, ... }:
5 cfg = config.programs.proxychains;
8 ${cfg.chain.type}_chain
9 ${optionalString (cfg.chain.type == "random")
10 "chain_len = ${builtins.toString cfg.chain.length}"}
11 ${optionalString cfg.proxyDNS "proxy_dns"}
12 ${optionalString cfg.quietMode "quiet_mode"}
13 remote_dns_subnet ${builtins.toString cfg.remoteDNSSubnet}
14 tcp_read_time_out ${builtins.toString cfg.tcpReadTimeOut}
15 tcp_connect_time_out ${builtins.toString cfg.tcpConnectTimeOut}
16 localnet ${cfg.localnet}
18 ${builtins.concatStringsSep "\n"
19 (lib.mapAttrsToList (k: v: "${v.type} ${v.host} ${builtins.toString v.port}")
20 (lib.filterAttrs (k: v: v.enable) cfg.proxies))}
25 enable = mkEnableOption (lib.mdDoc "this proxy");
28 type = types.enum [ "http" "socks4" "socks5" ];
29 description = lib.mdDoc "Proxy type.";
34 description = lib.mdDoc "Proxy host or IP address.";
39 description = lib.mdDoc "Proxy port";
50 programs.proxychains = {
52 enable = mkEnableOption (lib.mdDoc "installing proxychains configuration");
54 package = mkPackageOptionMD pkgs "proxychains" {
55 example = "pkgs.proxychains-ng";
60 type = types.enum [ "dynamic" "strict" "random" ];
62 description = lib.mdDoc ''
63 `dynamic` - Each connection will be done via chained proxies
64 all proxies chained in the order as they appear in the list
65 at least one proxy must be online to play in chain
66 (dead proxies are skipped)
67 otherwise `EINTR` is returned to the app.
69 `strict` - Each connection will be done via chained proxies
70 all proxies chained in the order as they appear in the list
71 all proxies must be online to play in chain
72 otherwise `EINTR` is returned to the app.
74 `random` - Each connection will be done via random proxy
75 (or proxy chain, see {option}`programs.proxychains.chain.length`) from the list.
79 type = types.nullOr types.int;
81 description = lib.mdDoc ''
82 Chain length for random chain.
90 description = lib.mdDoc "Proxy DNS requests - no leak for DNS data.";
93 quietMode = mkEnableOption (lib.mdDoc "Quiet mode (no output from the library)");
95 remoteDNSSubnet = mkOption {
96 type = types.enum [ 10 127 224 ];
98 description = lib.mdDoc ''
99 Set the class A subnet number to use for the internal remote DNS mapping, uses the reserved 224.x.x.x range by default.
103 tcpReadTimeOut = mkOption {
106 description = lib.mdDoc "Connection read time-out in milliseconds.";
109 tcpConnectTimeOut = mkOption {
112 description = lib.mdDoc "Connection time-out in milliseconds.";
115 localnet = mkOption {
117 default = "127.0.0.0/255.0.0.0";
118 description = lib.mdDoc "By default enable localnet for loopback address ranges.";
122 type = types.attrsOf (types.submodule proxyOptions);
123 description = lib.mdDoc ''
124 Proxies to be used by proxychains.
127 example = literalExpression ''
141 ###### implementation
143 meta.maintainers = with maintainers; [ sorki ];
145 config = mkIf cfg.enable {
147 assertions = singleton {
148 assertion = cfg.chain.type != "random" && cfg.chain.length == null;
150 Option `programs.proxychains.chain.length`
151 only makes sense with `programs.proxychains.chain.type` = "random".
155 programs.proxychains.proxies = mkIf config.services.tor.client.enable
157 torproxy = mkDefault {
165 environment.etc."proxychains.conf".text = configFile;
166 environment.systemPackages = [ cfg.package ];