at 17.09-beta 2.8 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.polipo; 8 9 polipoConfig = pkgs.writeText "polipo.conf" '' 10 proxyAddress = ${cfg.proxyAddress} 11 proxyPort = ${toString cfg.proxyPort} 12 allowedClients = ${concatStringsSep ", " cfg.allowedClients} 13 ${optionalString (cfg.parentProxy != "") "parentProxy = ${cfg.parentProxy}" } 14 ${optionalString (cfg.socksParentProxy != "") "socksParentProxy = ${cfg.socksParentProxy}" } 15 ${config.services.polipo.extraConfig} 16 ''; 17 18in 19 20{ 21 22 options = { 23 24 services.polipo = { 25 26 enable = mkOption { 27 type = types.bool; 28 default = false; 29 description = "Whether to run the polipo caching web proxy."; 30 }; 31 32 proxyAddress = mkOption { 33 type = types.string; 34 default = "127.0.0.1"; 35 description = "IP address on which Polipo will listen."; 36 }; 37 38 proxyPort = mkOption { 39 type = types.int; 40 default = 8123; 41 description = "TCP port on which Polipo will listen."; 42 }; 43 44 allowedClients = mkOption { 45 type = types.listOf types.str; 46 default = [ "127.0.0.1" "::1" ]; 47 example = [ "127.0.0.1" "::1" "134.157.168.0/24" "2001:660:116::/48" ]; 48 description = '' 49 List of IP addresses or network addresses that may connect to Polipo. 50 ''; 51 }; 52 53 parentProxy = mkOption { 54 type = types.string; 55 default = ""; 56 example = "localhost:8124"; 57 description = '' 58 Hostname and port number of an HTTP parent proxy; 59 it should have the form host:port. 60 ''; 61 }; 62 63 socksParentProxy = mkOption { 64 type = types.string; 65 default = ""; 66 example = "localhost:9050"; 67 description = '' 68 Hostname and port number of an SOCKS parent proxy; 69 it should have the form host:port. 70 ''; 71 }; 72 73 extraConfig = mkOption { 74 type = types.lines; 75 default = ""; 76 description = '' 77 Polio configuration. Contents will be added 78 verbatim to the configuration file. 79 ''; 80 }; 81 82 }; 83 84 }; 85 86 config = mkIf cfg.enable { 87 88 users.extraUsers = singleton 89 { name = "polipo"; 90 uid = config.ids.uids.polipo; 91 description = "Polipo caching proxy user"; 92 home = "/var/cache/polipo"; 93 createHome = true; 94 }; 95 96 users.extraGroups = singleton 97 { name = "polipo"; 98 gid = config.ids.gids.polipo; 99 members = [ "polipo" ]; 100 }; 101 102 systemd.services.polipo = { 103 description = "caching web proxy"; 104 after = [ "network.target" "nss-lookup.target" ]; 105 wantedBy = [ "multi-user.target"]; 106 serviceConfig = { 107 ExecStart = "${pkgs.polipo}/bin/polipo -c ${polipoConfig}"; 108 User = "polipo"; 109 }; 110 }; 111 112 }; 113 114}