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");
56 type = types.enum [ "dynamic" "strict" "random" ];
58 description = lib.mdDoc ''
59 `dynamic` - Each connection will be done via chained proxies
60 all proxies chained in the order as they appear in the list
61 at least one proxy must be online to play in chain
62 (dead proxies are skipped)
63 otherwise `EINTR` is returned to the app.
65 `strict` - Each connection will be done via chained proxies
66 all proxies chained in the order as they appear in the list
67 all proxies must be online to play in chain
68 otherwise `EINTR` is returned to the app.
70 `random` - Each connection will be done via random proxy
71 (or proxy chain, see {option}`programs.proxychains.chain.length`) from the list.
75 type = types.nullOr types.int;
77 description = lib.mdDoc ''
78 Chain length for random chain.
86 description = lib.mdDoc "Proxy DNS requests - no leak for DNS data.";
89 quietMode = mkEnableOption (lib.mdDoc "Quiet mode (no output from the library).");
91 remoteDNSSubnet = mkOption {
92 type = types.enum [ 10 127 224 ];
94 description = lib.mdDoc ''
95 Set the class A subnet number to use for the internal remote DNS mapping, uses the reserved 224.x.x.x range by default.
99 tcpReadTimeOut = mkOption {
102 description = lib.mdDoc "Connection read time-out in milliseconds.";
105 tcpConnectTimeOut = mkOption {
108 description = lib.mdDoc "Connection time-out in milliseconds.";
111 localnet = mkOption {
113 default = "127.0.0.0/255.0.0.0";
114 description = lib.mdDoc "By default enable localnet for loopback address ranges.";
118 type = types.attrsOf (types.submodule proxyOptions);
119 description = lib.mdDoc ''
120 Proxies to be used by proxychains.
123 example = literalExpression ''
137 ###### implementation
139 meta.maintainers = with maintainers; [ sorki ];
141 config = mkIf cfg.enable {
143 assertions = singleton {
144 assertion = cfg.chain.type != "random" && cfg.chain.length == null;
146 Option `programs.proxychains.chain.length`
147 only makes sense with `programs.proxychains.chain.type` = "random".
151 programs.proxychains.proxies = mkIf config.services.tor.client.enable
153 torproxy = mkDefault {
161 environment.etc."proxychains.conf".text = configFile;
162 environment.systemPackages = [ pkgs.proxychains ];