nixpkgs/nixos/modules/programs/proxychains.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

189 lines
4.8 KiB
Nix
Raw Permalink Normal View History

2020-04-28 18:32:22 +02:00
{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.proxychains;
configFile = ''
${cfg.chain.type}_chain
${lib.optionalString (
cfg.chain.type == "random"
2020-04-28 18:32:22 +02:00
) "chain_len = ${builtins.toString cfg.chain.length}"}
${lib.optionalString cfg.proxyDNS "proxy_dns"}
${lib.optionalString cfg.quietMode "quiet_mode"}
2020-04-28 18:32:22 +02:00
remote_dns_subnet ${builtins.toString cfg.remoteDNSSubnet}
tcp_read_time_out ${builtins.toString cfg.tcpReadTimeOut}
tcp_connect_time_out ${builtins.toString cfg.tcpConnectTimeOut}
localnet ${cfg.localnet}
[ProxyList]
${builtins.concatStringsSep "\n" (
lib.mapAttrsToList (k: v: "${v.type} ${v.host} ${builtins.toString v.port}") (
lib.filterAttrs (k: v: v.enable) cfg.proxies
)
2020-04-28 18:32:22 +02:00
)}
'';
proxyOptions = {
options = {
enable = lib.mkEnableOption "this proxy";
2020-04-28 18:32:22 +02:00
type = lib.mkOption {
type = lib.types.enum [
"http"
"socks4"
"socks5"
];
description = "Proxy type.";
2020-04-28 18:32:22 +02:00
};
host = lib.mkOption {
type = lib.types.str;
description = "Proxy host or IP address.";
2020-04-28 18:32:22 +02:00
};
port = lib.mkOption {
type = lib.types.port;
description = "Proxy port";
2020-04-28 18:32:22 +02:00
};
};
};
in
{
###### interface
options = {
programs.proxychains = {
enable = lib.mkEnableOption "proxychains configuration";
2020-04-28 18:32:22 +02:00
package = lib.mkPackageOption pkgs "proxychains" {
example = "proxychains-ng";
2023-03-24 02:55:11 +08:00
};
2020-04-28 18:32:22 +02:00
chain = {
type = lib.mkOption {
type = lib.types.enum [
"dynamic"
"strict"
"random"
];
2020-04-28 18:32:22 +02:00
default = "strict";
description = ''
`dynamic` - Each connection will be done via chained proxies
2020-04-28 18:32:22 +02:00
all proxies chained in the order as they appear in the list
at least one proxy must be online to play in chain
(dead proxies are skipped)
otherwise `EINTR` is returned to the app.
2020-04-28 18:32:22 +02:00
`strict` - Each connection will be done via chained proxies
2020-04-28 18:32:22 +02:00
all proxies chained in the order as they appear in the list
all proxies must be online to play in chain
otherwise `EINTR` is returned to the app.
2020-04-28 18:32:22 +02:00
`random` - Each connection will be done via random proxy
(or proxy chain, see {option}`programs.proxychains.chain.length`) from the list.
2020-04-28 18:32:22 +02:00
'';
};
length = lib.mkOption {
type = lib.types.nullOr lib.types.int;
2020-04-28 18:32:22 +02:00
default = null;
description = ''
2020-04-28 18:32:22 +02:00
Chain length for random chain.
'';
};
};
proxyDNS = lib.mkOption {
type = lib.types.bool;
2020-04-28 18:32:22 +02:00
default = true;
description = "Proxy DNS requests - no leak for DNS data.";
2020-04-28 18:32:22 +02:00
};
quietMode = lib.mkEnableOption "Quiet mode (no output from the library)";
2020-04-28 18:32:22 +02:00
remoteDNSSubnet = lib.mkOption {
type = lib.types.enum [
10
127
224
];
2020-04-28 18:32:22 +02:00
default = 224;
description = ''
2020-04-28 18:32:22 +02:00
Set the class A subnet number to use for the internal remote DNS mapping, uses the reserved 224.x.x.x range by default.
'';
};
tcpReadTimeOut = lib.mkOption {
type = lib.types.int;
2020-04-28 18:32:22 +02:00
default = 15000;
description = "Connection read time-out in milliseconds.";
2020-04-28 18:32:22 +02:00
};
tcpConnectTimeOut = lib.mkOption {
type = lib.types.int;
2020-04-28 18:32:22 +02:00
default = 8000;
description = "Connection time-out in milliseconds.";
2020-04-28 18:32:22 +02:00
};
localnet = lib.mkOption {
type = lib.types.str;
2020-04-28 18:32:22 +02:00
default = "127.0.0.0/255.0.0.0";
description = "By default enable localnet for loopback address ranges.";
2020-04-28 18:32:22 +02:00
};
proxies = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule proxyOptions);
description = ''
2020-04-28 18:32:22 +02:00
Proxies to be used by proxychains.
'';
example = lib.literalExpression ''
2020-04-28 18:32:22 +02:00
{ myproxy =
{ type = "socks4";
host = "127.0.0.1";
port = 1337;
};
}
'';
};
};
};
###### implementation
meta.maintainers = with lib.maintainers; [ sorki ];
2020-04-28 18:32:22 +02:00
config = lib.mkIf cfg.enable {
2020-04-28 18:32:22 +02:00
assertions = lib.singleton {
2020-04-28 18:32:22 +02:00
assertion = cfg.chain.type != "random" && cfg.chain.length == null;
message = ''
Option `programs.proxychains.chain.length`
only makes sense with `programs.proxychains.chain.type` = "random".
'';
};
programs.proxychains.proxies = lib.mkIf config.services.tor.client.enable {
torproxy = lib.mkDefault {
2020-04-28 18:32:22 +02:00
enable = true;
type = "socks4";
host = "127.0.0.1";
port = 9050;
};
};
2020-04-28 18:32:22 +02:00
environment.etc."proxychains.conf".text = configFile;
2023-03-24 02:55:11 +08:00
environment.systemPackages = [ cfg.package ];
2020-04-28 18:32:22 +02:00
};
}