at 21.11-pre 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.str; 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.str; 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.str; 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.users.polipo = 89 { uid = config.ids.uids.polipo; 90 description = "Polipo caching proxy user"; 91 home = "/var/cache/polipo"; 92 createHome = true; 93 }; 94 95 users.groups.polipo = 96 { gid = config.ids.gids.polipo; 97 members = [ "polipo" ]; 98 }; 99 100 systemd.services.polipo = { 101 description = "caching web proxy"; 102 after = [ "network.target" "nss-lookup.target" ]; 103 wantedBy = [ "multi-user.target"]; 104 serviceConfig = { 105 ExecStart = "${pkgs.polipo}/bin/polipo -c ${polipoConfig}"; 106 User = "polipo"; 107 }; 108 }; 109 110 }; 111 112}