1 { config, lib, pkgs, ... }:
4 cfg = config.services.cntlm;
6 configFile = if cfg.configText != "" then
7 pkgs.writeText "cntlm.conf" ''
11 pkgs.writeText "lighttpd.conf" ''
12 # Cntlm Authentication Proxy Configuration
13 Username ${cfg.username}
15 Password ${cfg.password}
16 ${lib.optionalString (cfg.netbios_hostname != "") "Workstation ${cfg.netbios_hostname}"}
17 ${lib.concatMapStrings (entry: "Proxy ${entry}\n") cfg.proxy}
18 ${lib.optionalString (cfg.noproxy != []) "NoProxy ${lib.concatStringsSep ", " cfg.noproxy}"}
20 ${lib.concatMapStrings (port: ''
21 Listen ${toString port}
31 options.services.cntlm = {
33 enable = lib.mkEnableOption "cntlm, which starts a local proxy";
35 username = lib.mkOption {
38 Proxy account name, without the possibility to include domain name ('at' sign is interpreted literally).
42 domain = lib.mkOption {
44 description = "Proxy account domain/workgroup name.";
47 password = lib.mkOption {
48 default = "/etc/cntlm.password";
50 description = "Proxy account password. Note: use chmod 0600 on /etc/cntlm.password for security.";
53 netbios_hostname = lib.mkOption {
57 The hostname of your machine.
61 proxy = lib.mkOption {
62 type = lib.types.listOf lib.types.str;
64 A list of NTLM/NTLMv2 authenticating HTTP proxies.
66 Parent proxy, which requires authentication. The same as proxy on the command-line, can be used more than once to specify unlimited
67 number of proxies. Should one proxy fail, cntlm automatically moves on to the next one. The connect request fails only if the whole
68 list of proxies is scanned and (for each request) and found to be invalid. Command-line takes precedence over the configuration file.
70 example = [ "proxy.example.com:81" ];
73 noproxy = lib.mkOption {
75 A list of domains where the proxy is skipped.
78 type = lib.types.listOf lib.types.str;
79 example = [ "*.example.com" "example.com" ];
84 type = lib.types.listOf lib.types.port;
85 description = "Specifies on which ports the cntlm daemon listens.";
88 extraConfig = lib.mkOption {
89 type = lib.types.lines;
91 description = "Additional config appended to the end of the generated {file}`cntlm.conf`.";
94 configText = lib.mkOption {
95 type = lib.types.lines;
97 description = "Verbatim contents of {file}`cntlm.conf`.";
102 ###### implementation
104 config = lib.mkIf cfg.enable {
105 systemd.services.cntlm = {
106 description = "CNTLM is an NTLM / NTLM Session Response / NTLMv2 authenticating HTTP proxy";
107 after = [ "network.target" ];
108 wantedBy = [ "multi-user.target" ];
112 ${pkgs.cntlm}/bin/cntlm -U cntlm -c ${configFile} -v -f
117 users.users.cntlm = {
119 description = "cntlm system-wide daemon";