git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/tor: add tor hidden service options (#28081)

* nixos/tor: add hiddenServices option This change allows to configure hidden services more conveniently. * nixos/tor: fix default/example mixup * nixos/tor: use docbook in documentation Also use more elegant optionalString for optional strings. * tor: seperate hidden service port by newline * tor: better example for hidden service path a path below /var/lib/tor is usually used for hidden services

commitb4d2cd6f6a8f004c1ea4ec7f84d9f7f6a93418ce authorPhil <philipp.B.610@googlemail.com> dateFri 11 Aug 2017, 23:59 (9 years ago) parent7f139a2
1 file changed+92−12
nixos/modules/services/security/tor.nix+92−12
nixos/modules/services/security/tor.nix+92−12
@@ -46,8 +46,20 @@ let
4646 ServerTransportPlugin obfs2,obfs3 exec ${pkgs.pythonPackages.obfsproxy}/bin/obfsproxy managed
4747 ''}
4848 ''
49+ + hiddenServices
4950 + cfg.extraConfig;
5051
52+ hiddenServices = concatStrings (mapAttrsToList (hiddenServiceDir: hs:
53+ let
54+ hsports = concatStringsSep "\n" (map mkHiddenServicePort hs.hiddenServicePorts);
55+ in
56+ "HiddenServiceDir ${hiddenServiceDir}\n${hsports}\n${hs.extraConfig}\n"
57+ ) cfg.hiddenServices);
58+
59+ mkHiddenServicePort = hsport: let
60+ trgt = optionalString (hsport.target != null) (" " + hsport.target);
61+ in "HiddenServicePort ${toString hsport.virtualPort}${trgt}";
62+
5163 torRcFile = pkgs.writeText "torrc" torRc;
5264in
5365{
@@ -229,11 +241,11 @@ in
229241 default = null;
230242 example = "450 GBytes";
231243 description = ''
232− Specify maximum bandwidth allowed during an accounting
233− period. This allows you to limit overall tor bandwidth
234− over some time period. See the
235− <literal>AccountingMax</literal> option by looking at the
236− tor manual (<literal>man tor</literal>) for more.
244+ Specify maximum bandwidth allowed during an accounting period. This
245+ allows you to limit overall tor bandwidth over some time period.
246+ See the <literal>AccountingMax</literal> option by looking at the
247+ tor manual <citerefentry><refentrytitle>tor</refentrytitle>
248+ <manvolnum>1</manvolnum></citerefentry> for more.
237249
238250 Note this limit applies individually to upload and
239251 download; if you specify <literal>"500 GBytes"</literal>
@@ -247,10 +259,11 @@ in
247259 default = null;
248260 example = "month 1 1:00";
249261 description = ''
250− Specify length of an accounting period. This allows you to
251− limit overall tor bandwidth over some time period. See the
252− <literal>AccountingStart</literal> option by looking at
253− the tor manual (<literal>man tor</literal>) for more.
262+ Specify length of an accounting period. This allows you to limit
263+ overall tor bandwidth over some time period. See the
264+ <literal>AccountingStart</literal> option by looking at the tor
265+ manual <citerefentry><refentrytitle>tor</refentrytitle>
266+ <manvolnum>1</manvolnum></citerefentry> for more.
254267 '';
255268 };
256269
@@ -279,9 +292,10 @@ in
279292 type = types.str;
280293 example = "143";
281294 description = ''
282− What port to advertise for Tor connections. This corresponds
283− to the <literal>ORPort</literal> section in the Tor manual; see
284− <literal>man tor</literal> for more details.
295+ What port to advertise for Tor connections. This corresponds to the
296+ <literal>ORPort</literal> section in the Tor manual; see
297+ <citerefentry><refentrytitle>tor</refentrytitle>
298+ <manvolnum>1</manvolnum></citerefentry> for more details.
285299
286300 At a minimum, you should just specify the port for the
287301 relay to listen on; a common one like 143, 22, 80, or 443
@@ -314,6 +328,72 @@ in
314328 '';
315329 };
316330 };
331+
332+ hiddenServices = mkOption {
333+ type = types.attrsOf (types.submodule ({
334+ options = {
335+ hiddenServicePorts = mkOption {
336+ type = types.listOf (types.submodule {
337+ options = {
338+ virtualPort = mkOption {
339+ type = types.int;
340+ example = 80;
341+ description = "Virtual port.";
342+ };
343+ target = mkOption {
344+ type = types.nullOr types.str;
345+ default = null;
346+ example = "127.0.0.1:8080";
347+ description = ''
348+ Target virtual Port shall be mapped to.
349+
350+ You may override the target port, address, or both by
351+ specifying a target of addr, port, addr:port, or
352+ unix:path. (You can specify an IPv6 target as
353+ [addr]:port. Unix paths may be quoted, and may use
354+ standard C escapes.)
355+ '';
356+ };
357+ };
358+ });
359+ example = [ { virtualPort = 80; target = "127.0.0.1:8080"; } { virtualPort = 6667; } ];
360+ description = ''
361+ If target is <literal>null</literal> the virtual port is mapped
362+ to the same port on 127.0.0.1 over TCP. You may use
363+ <literal>target</literal> to overwrite this behaviour (see
364+ description of target).
365+
366+ This corresponds to the <literal>HiddenServicePort VIRTPORT
367+ [TARGET]</literal> option by looking at the tor manual
368+ <citerefentry><refentrytitle>tor</refentrytitle>
369+ <manvolnum>1</manvolnum></citerefentry> for more information.
370+ '';
371+ };
372+ extraConfig = mkOption {
373+ type = types.str;
374+ default = "";
375+ description = ''
376+ Extra configuration. Contents will be added in the current
377+ hidden service context.
378+ '';
379+ };
380+ };
381+ }));
382+ default = {};
383+ example = {
384+ "/var/lib/tor/webserver" = {
385+ hiddenServicePorts = [ { virtualPort = 80; } ];
386+ };
387+ };
388+ description = ''
389+ Configure hidden services.
390+
391+ Please consult the tor manual
392+ <citerefentry><refentrytitle>tor</refentrytitle>
393+ <manvolnum>1</manvolnum></citerefentry> for a more detailed
394+ explanation. (search for 'HIDDEN').
395+ '';
396+ };
317397 };
318398 };
319399