2014-12-16 17:27:58 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.tor;
|
|
|
|
|
|
|
|
torify = pkgs.writeTextFile {
|
2014-12-19 04:07:52 +00:00
|
|
|
name = "tsocks";
|
2014-12-16 17:27:58 +00:00
|
|
|
text = ''
|
|
|
|
#!${pkgs.stdenv.shell}
|
2014-12-19 04:07:52 +00:00
|
|
|
TSOCKS_CONF_FILE=${pkgs.writeText "tsocks.conf" cfg.tsocks.config} LD_PRELOAD="${pkgs.tsocks}/lib/libtsocks.so $LD_PRELOAD" "$@"
|
2014-12-16 17:27:58 +00:00
|
|
|
'';
|
|
|
|
executable = true;
|
2014-12-19 04:07:52 +00:00
|
|
|
destination = "/bin/tsocks";
|
2014-12-16 17:27:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2014-12-19 04:07:52 +00:00
|
|
|
services.tor.tsocks = {
|
2014-12-16 17:27:58 +00:00
|
|
|
|
|
|
|
enable = mkOption {
|
2014-12-19 04:07:52 +00:00
|
|
|
default = cfg.enable && cfg.client.enable;
|
2014-12-16 17:27:58 +00:00
|
|
|
description = ''
|
2014-12-19 04:07:52 +00:00
|
|
|
Whether to build tsocks wrapper script to relay application traffic via TOR.
|
2014-12-16 17:27:58 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
server = mkOption {
|
|
|
|
default = "localhost:9050";
|
|
|
|
example = "192.168.0.20";
|
|
|
|
description = ''
|
|
|
|
IP address of TOR client to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra configuration. Contents will be added verbatim to TSocks
|
|
|
|
configuration file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2014-12-19 04:07:52 +00:00
|
|
|
config = mkIf cfg.tsocks.enable {
|
2014-12-16 17:27:58 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ torify ]; # expose it to the users
|
|
|
|
|
2014-12-19 04:07:52 +00:00
|
|
|
services.tor.tsocks.config = ''
|
|
|
|
server = ${toString(head (splitString ":" cfg.tsocks.server))}
|
|
|
|
server_port = ${toString(tail (splitString ":" cfg.tsocks.server))}
|
2014-12-16 17:27:58 +00:00
|
|
|
|
|
|
|
local = 127.0.0.0/255.128.0.0
|
|
|
|
local = 127.128.0.0/255.192.0.0
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|