at 23.11-pre 2.7 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 = mkEnableOption (lib.mdDoc "polipo caching web proxy"); 27 28 proxyAddress = mkOption { 29 type = types.str; 30 default = "127.0.0.1"; 31 description = lib.mdDoc "IP address on which Polipo will listen."; 32 }; 33 34 proxyPort = mkOption { 35 type = types.port; 36 default = 8123; 37 description = lib.mdDoc "TCP port on which Polipo will listen."; 38 }; 39 40 allowedClients = mkOption { 41 type = types.listOf types.str; 42 default = [ "127.0.0.1" "::1" ]; 43 example = [ "127.0.0.1" "::1" "134.157.168.0/24" "2001:660:116::/48" ]; 44 description = lib.mdDoc '' 45 List of IP addresses or network addresses that may connect to Polipo. 46 ''; 47 }; 48 49 parentProxy = mkOption { 50 type = types.str; 51 default = ""; 52 example = "localhost:8124"; 53 description = lib.mdDoc '' 54 Hostname and port number of an HTTP parent proxy; 55 it should have the form host:port. 56 ''; 57 }; 58 59 socksParentProxy = mkOption { 60 type = types.str; 61 default = ""; 62 example = "localhost:9050"; 63 description = lib.mdDoc '' 64 Hostname and port number of an SOCKS parent proxy; 65 it should have the form host:port. 66 ''; 67 }; 68 69 extraConfig = mkOption { 70 type = types.lines; 71 default = ""; 72 description = lib.mdDoc '' 73 Polio configuration. Contents will be added 74 verbatim to the configuration file. 75 ''; 76 }; 77 78 }; 79 80 }; 81 82 config = mkIf cfg.enable { 83 84 users.users.polipo = 85 { uid = config.ids.uids.polipo; 86 description = "Polipo caching proxy user"; 87 home = "/var/cache/polipo"; 88 createHome = true; 89 }; 90 91 users.groups.polipo = 92 { gid = config.ids.gids.polipo; 93 members = [ "polipo" ]; 94 }; 95 96 systemd.services.polipo = { 97 description = "caching web proxy"; 98 after = [ "network.target" "nss-lookup.target" ]; 99 wantedBy = [ "multi-user.target"]; 100 serviceConfig = { 101 ExecStart = "${pkgs.polipo}/bin/polipo -c ${polipoConfig}"; 102 User = "polipo"; 103 }; 104 }; 105 106 }; 107 108}