summaryrefslogtreecommitdiff
path: root/modules/services/privoxy/default.nix
blob: 5f7780c370a574dd704ae39440aa23a19c1dc7c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.privoxy;
in
{
  options = {
    services.privoxy.enable = mkOption {
      type = types.bool;
      default = false;
      description = lib.mdDoc "Whether to enable the privoxy proxy service.";
    };

    services.privoxy.listenAddress = mkOption {
      type = types.str;
      default = "127.0.0.1:8118";
      description = lib.mdDoc "The address and TCP port on which privoxy will listen.";
    };

    services.privoxy.package = mkOption {
      type = types.package;
      default = pkgs.privoxy;
      example = literalExpression "pkgs.privoxy";
      description = lib.mdDoc "This option specifies the privoxy package to use.";
    };

    services.privoxy.config = mkOption {
      type = types.lines;
      default = "";
      example = "forward / upstream.proxy:8080";
      description = lib.mdDoc "Config to use for privoxy";
    };

    services.privoxy.templdir = mkOption {
      type = types.path;
      default = "${pkgs.privoxy}/etc/templates";
      defaultText = "\${pkgs.privoxy}/etc/templates";
      description = lib.mdDoc "Directory for privoxy template files.";
    };

    services.privoxy.confdir = mkOption {
      type = types.nullOr types.path;
      default = null;
      description = lib.mdDoc "Directory for privoxy files such as .action and .filter.";
    };
  };

  config = mkIf cfg.enable {
    environment.etc."privoxy-config".text = ''
      ${optionalString (cfg.confdir != null) "confdir ${cfg.confdir}"}
      templdir ${cfg.templdir}
      listen-address ${cfg.listenAddress}
      ${cfg.config}
    '';

    launchd.user.agents.privoxy = {
      path = [ config.environment.systemPath ];
      command = ''
      ${cfg.package}/bin/privoxy /etc/privoxy-config
      '';
      serviceConfig.KeepAlive = true;
    };
  };
}