summary refs log tree commit diff
path: root/nixos/modules/services/security
diff options
context:
space:
mode:
authorEvgeny Egorochkin <phreedom@yandex.ru>2014-12-19 06:59:30 +0200
committerEvgeny Egorochkin <phreedom@yandex.ru>2014-12-19 08:05:41 +0200
commit9225af50d031aea9ec7a43453e5958ade6e64545 (patch)
tree73fd255eff6b7b4a26cf348dbdff49779f02987f /nixos/modules/services/security
parenteb0874d5ff53f91ec15d8472173e0f38a3137871 (diff)
downloadnixlib-9225af50d031aea9ec7a43453e5958ade6e64545.tar
nixlib-9225af50d031aea9ec7a43453e5958ade6e64545.tar.gz
nixlib-9225af50d031aea9ec7a43453e5958ade6e64545.tar.bz2
nixlib-9225af50d031aea9ec7a43453e5958ade6e64545.tar.lz
nixlib-9225af50d031aea9ec7a43453e5958ade6e64545.tar.xz
nixlib-9225af50d031aea9ec7a43453e5958ade6e64545.tar.zst
nixlib-9225af50d031aea9ec7a43453e5958ade6e64545.zip
resurrect torsocks-faster
Diffstat (limited to 'nixos/modules/services/security')
-rw-r--r--nixos/modules/services/security/torsocks.nix31
1 files changed, 26 insertions, 5 deletions
diff --git a/nixos/modules/services/security/torsocks.nix b/nixos/modules/services/security/torsocks.nix
index 093a105bc313..1b5a05b21e77 100644
--- a/nixos/modules/services/security/torsocks.nix
+++ b/nixos/modules/services/security/torsocks.nix
@@ -6,9 +6,9 @@ let
   cfg = config.services.tor.torsocks;
   optionalNullStr = b: v: optionalString (b != null) v;
 
-  configFile = ''
-    TorAddress ${toString (head (splitString ":" cfg.server))}
-    TorPort    ${toString (tail (splitString ":" cfg.server))}
+  configFile = server: ''
+    TorAddress ${toString (head (splitString ":" server))}
+    TorPort    ${toString (tail (splitString ":" server))}
 
     OnionAddrRange ${cfg.onionAddrRange}
 
@@ -19,6 +19,17 @@ let
 
     AllowInbound ${if cfg.allowInbound then "1" else "0"}
   '';
+
+  wrapTorsocks = name: server: pkgs.writeTextFile {
+    name = name;
+    text = ''
+        #!${pkgs.stdenv.shell}
+        TORSOCKS_CONF_FILE=${pkgs.writeText "torsocks.conf" (configFile server)} ${pkgs.torsocks}/bin/torsocks "$@"
+    '';
+    executable = true;
+    destination = "/bin/${name}";
+  };
+
 in
 {
   options = {
@@ -42,6 +53,16 @@ in
         '';
       };
 
+      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.
+        '';
+      };
+
       onionAddrRange = mkOption {
         type    = types.str;
         default = "127.42.42.0/24";
@@ -89,10 +110,10 @@ in
   };
 
   config = mkIf cfg.enable {
-    environment.systemPackages = [ pkgs.torsocks ];
+    environment.systemPackages = [ pkgs.torsocks (wrapTorsocks "torsocks-faster" cfg.fasterServer) ];
 
     environment.etc =
-      [ { source = pkgs.writeText "torsocks.conf" configFile;
+      [ { source = pkgs.writeText "torsocks.conf" (configFile cfg.server);
           target = "tor/torsocks.conf";
         }
       ];