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