at 15.09-beta 2.9 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.cntlm; 8 uid = config.ids.uids.cntlm; 9 10in 11 12{ 13 14 options = { 15 16 services.cntlm = { 17 18 enable = mkOption { 19 default = false; 20 description = '' 21 Whether to enable the cntlm, which start a local proxy. 22 ''; 23 }; 24 25 username = mkOption { 26 description = '' 27 Proxy account name, without the possibility to include domain name ('at' sign is interpreted literally). 28 ''; 29 }; 30 31 domain = mkOption { 32 description = ''Proxy account domain/workgroup name.''; 33 }; 34 35 password = mkOption { 36 default = "/etc/cntlm.password"; 37 type = types.str; 38 description = ''Proxy account password. Note: use chmod 0600 on /etc/cntlm.password for security.''; 39 }; 40 41 netbios_hostname = mkOption { 42 type = types.str; 43 description = '' 44 The hostname of your machine. 45 ''; 46 }; 47 48 proxy = mkOption { 49 description = '' 50 A list of NTLM/NTLMv2 authenticating HTTP proxies. 51 52 Parent proxy, which requires authentication. The same as proxy on the command-line, can be used more than once to specify unlimited 53 number of proxies. Should one proxy fail, cntlm automatically moves on to the next one. The connect request fails only if the whole 54 list of proxies is scanned and (for each request) and found to be invalid. Command-line takes precedence over the configuration file. 55 ''; 56 }; 57 58 port = mkOption { 59 default = [3128]; 60 description = "Specifies on which ports the cntlm daemon listens."; 61 }; 62 63 extraConfig = mkOption { 64 default = ""; 65 description = "Verbatim contents of <filename>cntlm.conf</filename>."; 66 }; 67 68 }; 69 70 }; 71 72 73 ###### implementation 74 75 config = mkIf config.services.cntlm.enable { 76 77 services.cntlm.netbios_hostname = mkDefault config.networking.hostName; 78 79 users.extraUsers = singleton { 80 name = "cntlm"; 81 description = "cntlm system-wide daemon"; 82 home = "/var/empty"; 83 }; 84 85 jobs.cntlm = 86 { description = "CNTLM is an NTLM / NTLM Session Response / NTLMv2 authenticating HTTP proxy"; 87 88 startOn = "started network-interfaces"; 89 90 daemonType = "fork"; 91 92 exec = 93 '' 94 ${pkgs.cntlm}/bin/cntlm -U cntlm \ 95 -c ${pkgs.writeText "cntlm_config" cfg.extraConfig} 96 ''; 97 }; 98 99 services.cntlm.extraConfig = 100 '' 101 # Cntlm Authentication Proxy Configuration 102 Username ${cfg.username} 103 Domain ${cfg.domain} 104 Password ${cfg.password} 105 Workstation ${cfg.netbios_hostname} 106 ${concatMapStrings (entry: "Proxy ${entry}\n") cfg.proxy} 107 108 ${concatMapStrings (port: '' 109 Listen ${toString port} 110 '') cfg.port} 111 ''; 112 113 }; 114 115}