privoxy: upstart to systemd conversion, actions file editing

fix missing actions and filters

+44 -32
+44 -32
nixos/modules/services/networking/privoxy.nix
··· 6 7 inherit (pkgs) privoxy; 8 9 - stateDir = "/var/spool/privoxy"; 10 - 11 privoxyUser = "privoxy"; 12 13 - privoxyFlags = "--no-daemon --user ${privoxyUser} ${privoxyCfg}"; 14 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} 22 ''; 23 24 in ··· 32 services.privoxy = { 33 34 enable = mkOption { 35 default = false; 36 description = '' 37 - Whether to run the machine as a HTTP proxy server. 38 ''; 39 }; 40 41 listenAddress = mkOption { 42 default = "127.0.0.1:8118"; 43 description = '' 44 Address the proxy server is listening to. 45 ''; 46 }; 47 48 - logDir = mkOption { 49 - default = "/var/log/privoxy" ; 50 description = '' 51 - Location for privoxy log files. 52 ''; 53 }; 54 55 extraConfig = mkOption { 56 default = "" ; 57 description = '' 58 Extra configuration. Contents will be added verbatim to the configuration file. ··· 62 63 }; 64 65 - 66 ###### implementation 67 68 - config = mkIf config.services.privoxy.enable { 69 70 - environment.systemPackages = [ privoxy ]; 71 - 72 users.extraUsers = singleton 73 { name = privoxyUser; 74 uid = config.ids.uids.privoxy; 75 description = "Privoxy daemon user"; 76 - home = stateDir; 77 }; 78 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 - }; 92 93 }; 94
··· 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 23 in ··· 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. ··· 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