1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 inherit (pkgs) privoxy; 8 9 privoxyUser = "privoxy"; 10 11 cfg = config.services.privoxy; 12 13 confFile = pkgs.writeText "privoxy.conf" '' 14 user-manual ${privoxy}/share/doc/privoxy/user-manual 15 confdir ${privoxy}/etc/ 16 listen-address ${cfg.listenAddress} 17 enable-edit-actions ${if (cfg.enableEditActions == true) then "1" else "0"} 18 ${concatMapStrings (f: "actionsfile ${f}\n") cfg.actionsFiles} 19 ${concatMapStrings (f: "filterfile ${f}\n") cfg.filterFiles} 20 ${cfg.extraConfig} 21 ''; 22 23in 24 25{ 26 27 ###### interface 28 29 options = { 30 31 services.privoxy = { 32 33 enable = mkOption { 34 type = types.bool; 35 default = false; 36 description = '' 37 Whether to enable the Privoxy non-caching filtering proxy. 38 ''; 39 }; 40 41 listenAddress = mkOption { 42 type = types.str; 43 default = "127.0.0.1:8118"; 44 description = '' 45 Address the proxy server is listening to. 46 ''; 47 }; 48 49 actionsFiles = mkOption { 50 type = types.listOf types.str; 51 example = [ "match-all.action" "default.action" "/etc/privoxy/user.action" ]; 52 default = [ "match-all.action" "default.action" ]; 53 description = '' 54 List of paths to Privoxy action files. 55 These paths may either be absolute or relative to the privoxy configuration directory. 56 ''; 57 }; 58 59 filterFiles = mkOption { 60 type = types.listOf types.str; 61 example = [ "default.filter" "/etc/privoxy/user.filter" ]; 62 default = [ "default.filter" ]; 63 description = '' 64 List of paths to Privoxy filter files. 65 These paths may either be absolute or relative to the privoxy configuration directory. 66 ''; 67 }; 68 69 enableEditActions = mkOption { 70 type = types.bool; 71 default = false; 72 description = '' 73 Whether or not the web-based actions file editor may be used. 74 ''; 75 }; 76 77 extraConfig = mkOption { 78 type = types.lines; 79 default = "" ; 80 description = '' 81 Extra configuration. Contents will be added verbatim to the configuration file. 82 ''; 83 }; 84 }; 85 86 }; 87 88 ###### implementation 89 90 config = mkIf cfg.enable { 91 92 users.extraUsers = singleton 93 { name = privoxyUser; 94 uid = config.ids.uids.privoxy; 95 description = "Privoxy daemon user"; 96 }; 97 98 systemd.services.privoxy = { 99 description = "Filtering web proxy"; 100 after = [ "network.target" "nss-lookup.target" ]; 101 wantedBy = [ "multi-user.target" ]; 102 serviceConfig.ExecStart = "${privoxy}/sbin/privoxy --no-daemon --user ${privoxyUser} ${confFile}"; 103 }; 104 105 }; 106 107}