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 systemd.services.cntlm = { 77 description = "CNTLM is an NTLM / NTLM Session Response / NTLMv2 authenticating HTTP proxy"; 78 after = [ "network.target" ]; 79 wantedBy = [ "multi-user.target" ]; 80 serviceConfig = { 81 Type = "forking"; 82 User = "cntlm"; 83 ExecStart = '' 84 ${pkgs.cntlm}/bin/cntlm -U cntlm \ 85 -c ${pkgs.writeText "cntlm_config" cfg.extraConfig} 86 ''; 87 }; 88 }; 89 90 services.cntlm.netbios_hostname = mkDefault config.networking.hostName; 91 92 users.extraUsers.cntlm = { 93 name = "cntlm"; 94 description = "cntlm system-wide daemon"; 95 home = "/var/empty"; 96 }; 97 98 services.cntlm.extraConfig = 99 '' 100 # Cntlm Authentication Proxy Configuration 101 Username ${cfg.username} 102 Domain ${cfg.domain} 103 Password ${cfg.password} 104 Workstation ${cfg.netbios_hostname} 105 ${concatMapStrings (entry: "Proxy ${entry}\n") cfg.proxy} 106 107 ${concatMapStrings (port: '' 108 Listen ${toString port} 109 '') cfg.port} 110 ''; 111 }; 112 113}