1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.cntlm;
8
9 configFile = if cfg.configText != "" then
10 pkgs.writeText "cntlm.conf" ''
11 ${cfg.configText}
12 ''
13 else
14 pkgs.writeText "lighttpd.conf" ''
15 # Cntlm Authentication Proxy Configuration
16 Username ${cfg.username}
17 Domain ${cfg.domain}
18 Password ${cfg.password}
19 ${optionalString (cfg.netbios_hostname != "") "Workstation ${cfg.netbios_hostname}"}
20 ${concatMapStrings (entry: "Proxy ${entry}\n") cfg.proxy}
21 ${optionalString (cfg.noproxy != []) "NoProxy ${concatStringsSep ", " cfg.noproxy}"}
22
23 ${concatMapStrings (port: ''
24 Listen ${toString port}
25 '') cfg.port}
26
27 ${cfg.extraConfig}
28 '';
29
30in
31
32{
33
34 options.services.cntlm = {
35
36 enable = mkEnableOption (lib.mdDoc "cntlm, which starts a local proxy");
37
38 username = mkOption {
39 type = types.str;
40 description = lib.mdDoc ''
41 Proxy account name, without the possibility to include domain name ('at' sign is interpreted literally).
42 '';
43 };
44
45 domain = mkOption {
46 type = types.str;
47 description = lib.mdDoc "Proxy account domain/workgroup name.";
48 };
49
50 password = mkOption {
51 default = "/etc/cntlm.password";
52 type = types.str;
53 description = lib.mdDoc "Proxy account password. Note: use chmod 0600 on /etc/cntlm.password for security.";
54 };
55
56 netbios_hostname = mkOption {
57 type = types.str;
58 default = "";
59 description = lib.mdDoc ''
60 The hostname of your machine.
61 '';
62 };
63
64 proxy = mkOption {
65 type = types.listOf types.str;
66 description = lib.mdDoc ''
67 A list of NTLM/NTLMv2 authenticating HTTP proxies.
68
69 Parent proxy, which requires authentication. The same as proxy on the command-line, can be used more than once to specify unlimited
70 number of proxies. Should one proxy fail, cntlm automatically moves on to the next one. The connect request fails only if the whole
71 list of proxies is scanned and (for each request) and found to be invalid. Command-line takes precedence over the configuration file.
72 '';
73 example = [ "proxy.example.com:81" ];
74 };
75
76 noproxy = mkOption {
77 description = lib.mdDoc ''
78 A list of domains where the proxy is skipped.
79 '';
80 default = [];
81 type = types.listOf types.str;
82 example = [ "*.example.com" "example.com" ];
83 };
84
85 port = mkOption {
86 default = [3128];
87 type = types.listOf types.port;
88 description = lib.mdDoc "Specifies on which ports the cntlm daemon listens.";
89 };
90
91 extraConfig = mkOption {
92 type = types.lines;
93 default = "";
94 description = lib.mdDoc "Additional config appended to the end of the generated {file}`cntlm.conf`.";
95 };
96
97 configText = mkOption {
98 type = types.lines;
99 default = "";
100 description = lib.mdDoc "Verbatim contents of {file}`cntlm.conf`.";
101 };
102
103 };
104
105 ###### implementation
106
107 config = mkIf cfg.enable {
108 systemd.services.cntlm = {
109 description = "CNTLM is an NTLM / NTLM Session Response / NTLMv2 authenticating HTTP proxy";
110 after = [ "network.target" ];
111 wantedBy = [ "multi-user.target" ];
112 serviceConfig = {
113 User = "cntlm";
114 ExecStart = ''
115 ${pkgs.cntlm}/bin/cntlm -U cntlm -c ${configFile} -v -f
116 '';
117 };
118 };
119
120 users.users.cntlm = {
121 name = "cntlm";
122 description = "cntlm system-wide daemon";
123 isSystemUser = true;
124 };
125 };
126}