2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-12-06 05:19:17 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2010-10-01 04:41:43 +01:00
|
|
|
|
2014-12-06 05:19:17 +00:00
|
|
|
let
|
|
|
|
cfg = config.services.tor.torsocks;
|
|
|
|
optionalNullStr = b: v: optionalString (b != null) v;
|
2010-10-01 04:41:43 +01:00
|
|
|
|
2014-12-19 04:59:30 +00:00
|
|
|
configFile = server: ''
|
|
|
|
TorAddress ${toString (head (splitString ":" server))}
|
|
|
|
TorPort ${toString (tail (splitString ":" server))}
|
2013-01-15 06:59:02 +00:00
|
|
|
|
2014-12-06 05:19:17 +00:00
|
|
|
OnionAddrRange ${cfg.onionAddrRange}
|
2013-01-15 06:59:02 +00:00
|
|
|
|
2014-12-06 05:19:17 +00:00
|
|
|
${optionalNullStr cfg.socks5Username
|
|
|
|
"SOCKS5Username ${cfg.socks5Username}"}
|
|
|
|
${optionalNullStr cfg.socks5Password
|
|
|
|
"SOCKS5Password ${cfg.socks5Password}"}
|
2010-10-01 04:41:43 +01:00
|
|
|
|
2014-12-06 05:19:17 +00:00
|
|
|
AllowInbound ${if cfg.allowInbound then "1" else "0"}
|
|
|
|
'';
|
2014-12-19 04:59:30 +00:00
|
|
|
|
|
|
|
wrapTorsocks = name: server: pkgs.writeTextFile {
|
|
|
|
name = name;
|
|
|
|
text = ''
|
2018-03-01 19:38:53 +00:00
|
|
|
#!${pkgs.runtimeShell}
|
2014-12-19 04:59:30 +00:00
|
|
|
TORSOCKS_CONF_FILE=${pkgs.writeText "torsocks.conf" (configFile server)} ${pkgs.torsocks}/bin/torsocks "$@"
|
|
|
|
'';
|
|
|
|
executable = true;
|
|
|
|
destination = "/bin/${name}";
|
|
|
|
};
|
|
|
|
|
2010-10-01 04:41:43 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.tor.torsocks = {
|
|
|
|
enable = mkOption {
|
2014-12-06 05:19:17 +00:00
|
|
|
type = types.bool;
|
2014-12-19 03:58:03 +00:00
|
|
|
default = config.services.tor.enable && config.services.tor.client.enable;
|
2021-11-26 00:16:05 +00:00
|
|
|
defaultText = literalExpression "config.services.tor.enable && config.services.tor.client.enable";
|
2010-10-01 04:41:43 +01:00
|
|
|
description = ''
|
2014-12-06 05:19:17 +00:00
|
|
|
Whether to build <literal>/etc/tor/torsocks.conf</literal>
|
|
|
|
containing the specified global torsocks configuration.
|
2010-10-01 04:41:43 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
server = mkOption {
|
2014-12-06 05:19:17 +00:00
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1:9050";
|
|
|
|
example = "192.168.0.20:1234";
|
2010-10-01 04:41:43 +01:00
|
|
|
description = ''
|
2014-12-06 05:19:17 +00:00
|
|
|
IP/Port of the Tor SOCKS server. Currently, hostnames are
|
|
|
|
NOT supported by torsocks.
|
2010-10-01 04:41:43 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-12-19 04:59:30 +00:00
|
|
|
fasterServer = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1:9063";
|
|
|
|
example = "192.168.0.20:1234";
|
|
|
|
description = ''
|
|
|
|
IP/Port of the Tor SOCKS server for torsocks-faster wrapper suitable for HTTP.
|
|
|
|
Currently, hostnames are NOT supported by torsocks.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-12-06 05:19:17 +00:00
|
|
|
onionAddrRange = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.42.42.0/24";
|
2013-01-15 06:59:02 +00:00
|
|
|
description = ''
|
2014-12-06 05:19:17 +00:00
|
|
|
Tor hidden sites do not have real IP addresses. This
|
|
|
|
specifies what range of IP addresses will be handed to the
|
|
|
|
application as "cookies" for .onion names. Of course, you
|
|
|
|
should pick a block of addresses which you aren't going to
|
|
|
|
ever need to actually connect to. This is similar to the
|
|
|
|
MapAddress feature of the main tor daemon.
|
2013-01-15 06:59:02 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-12-06 05:19:17 +00:00
|
|
|
socks5Username = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "bob";
|
2010-10-01 04:41:43 +01:00
|
|
|
description = ''
|
2014-12-06 05:19:17 +00:00
|
|
|
SOCKS5 username. The <literal>TORSOCKS_USERNAME</literal>
|
|
|
|
environment variable overrides this option if it is set.
|
2010-10-01 04:41:43 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-12-06 05:19:17 +00:00
|
|
|
socks5Password = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "sekret";
|
|
|
|
description = ''
|
|
|
|
SOCKS5 password. The <literal>TORSOCKS_PASSWORD</literal>
|
|
|
|
environment variable overrides this option if it is set.
|
|
|
|
'';
|
|
|
|
};
|
2010-10-01 04:41:43 +01:00
|
|
|
|
2014-12-06 05:19:17 +00:00
|
|
|
allowInbound = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Set Torsocks to accept inbound connections. If set to
|
|
|
|
<literal>true</literal>, listen() and accept() will be
|
|
|
|
allowed to be used with non localhost address.
|
|
|
|
'';
|
|
|
|
};
|
2010-10-01 04:41:43 +01:00
|
|
|
|
2014-12-06 05:19:17 +00:00
|
|
|
};
|
|
|
|
};
|
2010-10-01 04:41:43 +01:00
|
|
|
|
2014-12-06 05:19:17 +00:00
|
|
|
config = mkIf cfg.enable {
|
2014-12-19 04:59:30 +00:00
|
|
|
environment.systemPackages = [ pkgs.torsocks (wrapTorsocks "torsocks-faster" cfg.fasterServer) ];
|
2010-10-01 04:41:43 +01:00
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
environment.etc."tor/torsocks.conf" =
|
|
|
|
{
|
|
|
|
source = pkgs.writeText "torsocks.conf" (configFile cfg.server);
|
|
|
|
};
|
2010-10-01 04:41:43 +01:00
|
|
|
};
|
|
|
|
}
|