Skip to content

Commit

Permalink
Merge pull request #92 from carlosdagos/privoxy-service
Browse files Browse the repository at this point in the history
Add a privoxy service
  • Loading branch information
LnL7 authored Aug 3, 2018
2 parents 91de10c + 41a6a40 commit 6418523
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ let
./modules/services/nix-gc
./modules/services/ofborg
./modules/services/postgresql
./modules/services/privoxy
./modules/services/redis
./modules/services/skhd
./modules/programs/bash
Expand Down
66 changes: 66 additions & 0 deletions modules/services/privoxy/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{ config, lib, pkgs, ... }:

with lib;

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

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

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

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

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

services.privoxy.confdir = mkOption {
type = types.nullOr types.path;
default = null;
description = "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;
};
};
}
1 change: 1 addition & 0 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ let
tests.services-ofborg = makeTest ./tests/services-ofborg.nix;
tests.services-offlineimap = makeTest ./tests/services-offlineimap.nix;
tests.services-skhd = makeTest ./tests/services-skhd.nix;
tests.services-privoxy = makeTest ./tests/services-privoxy.nix;
tests.system-defaults-write = makeTest ./tests/system-defaults-write.nix;
tests.system-keyboard-mapping = makeTest ./tests/system-keyboard-mapping.nix;
tests.system-packages = makeTest ./tests/system-packages.nix;
Expand Down
23 changes: 23 additions & 0 deletions tests/services-privoxy.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ config, lib, pkgs, ... }:

with lib;

let
privoxy = pkgs.runCommand "privoxy-0.0.0" {} "mkdir $out";
in

{
services.privoxy.enable = true;
services.privoxy.package = privoxy;
services.privoxy.config = "forward / .";

test = ''
echo >&2 "checking privoxy service in ~/Library/LaunchAgents"
grep "org.nixos.privoxy" ${config.out}/user/Library/LaunchAgents/org.nixos.privoxy.plist
echo grep "${privoxy}/bin/privoxy" ${config.out}/user/Library/LaunchAgents/org.nixos.privoxy.plist
grep "${privoxy}/bin/privoxy" ${config.out}/user/Library/LaunchAgents/org.nixos.privoxy.plist
echo >&2 "checking config in /etc/privoxy-config"
grep "forward / ." ${config.out}/etc/privoxy-config
'';
}

0 comments on commit 6418523

Please sign in to comment.