privoxy: upstart to systemd conversion, actions file editing

fix missing actions and filters

+44 -32
+44 -32
nixos/modules/services/networking/privoxy.nix
··· 6 6 7 7 inherit (pkgs) privoxy; 8 8 9 - stateDir = "/var/spool/privoxy"; 10 - 11 9 privoxyUser = "privoxy"; 12 10 13 - privoxyFlags = "--no-daemon --user ${privoxyUser} ${privoxyCfg}"; 11 + cfg = config.services.privoxy; 14 12 15 - privoxyCfg = pkgs.writeText "privoxy.conf" '' 16 - listen-address ${config.services.privoxy.listenAddress} 17 - logdir ${config.services.privoxy.logDir} 18 - confdir ${privoxy}/etc 19 - filterfile default.filter 20 - 21 - ${config.services.privoxy.extraConfig} 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} 22 21 ''; 23 22 24 23 in ··· 32 31 services.privoxy = { 33 32 34 33 enable = mkOption { 34 + type = types.bool; 35 35 default = false; 36 36 description = '' 37 - Whether to run the machine as a HTTP proxy server. 37 + Whether to enable the Privoxy non-caching filtering proxy. 38 38 ''; 39 39 }; 40 40 41 41 listenAddress = mkOption { 42 + type = types.str; 42 43 default = "127.0.0.1:8118"; 43 44 description = '' 44 45 Address the proxy server is listening to. 45 46 ''; 46 47 }; 47 48 48 - logDir = mkOption { 49 - default = "/var/log/privoxy" ; 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" ]; 50 53 description = '' 51 - Location for privoxy log files. 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. 52 74 ''; 53 75 }; 54 76 55 77 extraConfig = mkOption { 78 + type = types.lines; 56 79 default = "" ; 57 80 description = '' 58 81 Extra configuration. Contents will be added verbatim to the configuration file. ··· 62 85 63 86 }; 64 87 65 - 66 88 ###### implementation 67 89 68 - config = mkIf config.services.privoxy.enable { 90 + config = mkIf cfg.enable { 69 91 70 - environment.systemPackages = [ privoxy ]; 71 - 72 92 users.extraUsers = singleton 73 93 { name = privoxyUser; 74 94 uid = config.ids.uids.privoxy; 75 95 description = "Privoxy daemon user"; 76 - home = stateDir; 77 96 }; 78 97 79 - jobs.privoxy = 80 - { name = "privoxy"; 81 - 82 - startOn = "startup"; 83 - 84 - preStart = 85 - '' 86 - mkdir -m 0755 -p ${stateDir} 87 - chown ${privoxyUser} ${stateDir} 88 - ''; 89 - 90 - exec = "${privoxy}/sbin/privoxy ${privoxyFlags}"; 91 - }; 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 + }; 92 104 93 105 }; 94 106