2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2011-10-09 23:34:32 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.cntlm;
|
2017-06-15 11:11:48 +01:00
|
|
|
|
|
|
|
configFile = if cfg.configText != "" then
|
|
|
|
pkgs.writeText "cntlm.conf" ''
|
|
|
|
${cfg.configText}
|
|
|
|
''
|
|
|
|
else
|
|
|
|
pkgs.writeText "lighttpd.conf" ''
|
|
|
|
# Cntlm Authentication Proxy Configuration
|
|
|
|
Username ${cfg.username}
|
|
|
|
Domain ${cfg.domain}
|
|
|
|
Password ${cfg.password}
|
|
|
|
${optionalString (cfg.netbios_hostname != "") "Workstation ${cfg.netbios_hostname}"}
|
|
|
|
${concatMapStrings (entry: "Proxy ${entry}\n") cfg.proxy}
|
|
|
|
${optionalString (cfg.noproxy != []) "NoProxy ${concatStringsSep ", " cfg.noproxy}"}
|
|
|
|
|
|
|
|
${concatMapStrings (port: ''
|
|
|
|
Listen ${toString port}
|
|
|
|
'') cfg.port}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
2011-10-09 23:34:32 +01:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
options.services.cntlm = {
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2020-04-20 19:05:26 +01:00
|
|
|
enable = mkEnableOption "cntlm, which starts a local proxy";
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
username = mkOption {
|
2021-01-26 19:29:55 +00:00
|
|
|
type = types.str;
|
2017-06-15 11:11:48 +01:00
|
|
|
description = ''
|
|
|
|
Proxy account name, without the possibility to include domain name ('at' sign is interpreted literally).
|
|
|
|
'';
|
|
|
|
};
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
domain = mkOption {
|
2021-01-26 19:29:55 +00:00
|
|
|
type = types.str;
|
2021-01-24 09:19:10 +00:00
|
|
|
description = "Proxy account domain/workgroup name.";
|
2017-06-15 11:11:48 +01:00
|
|
|
};
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
password = mkOption {
|
|
|
|
default = "/etc/cntlm.password";
|
|
|
|
type = types.str;
|
2021-01-24 09:19:10 +00:00
|
|
|
description = "Proxy account password. Note: use chmod 0600 on /etc/cntlm.password for security.";
|
2017-06-15 11:11:48 +01:00
|
|
|
};
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
netbios_hostname = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
The hostname of your machine.
|
|
|
|
'';
|
|
|
|
};
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
proxy = mkOption {
|
2021-01-26 19:29:55 +00:00
|
|
|
type = types.listOf types.str;
|
2017-06-15 11:11:48 +01:00
|
|
|
description = ''
|
|
|
|
A list of NTLM/NTLMv2 authenticating HTTP proxies.
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
Parent proxy, which requires authentication. The same as proxy on the command-line, can be used more than once to specify unlimited
|
|
|
|
number of proxies. Should one proxy fail, cntlm automatically moves on to the next one. The connect request fails only if the whole
|
|
|
|
list of proxies is scanned and (for each request) and found to be invalid. Command-line takes precedence over the configuration file.
|
|
|
|
'';
|
|
|
|
example = [ "proxy.example.com:81" ];
|
|
|
|
};
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
noproxy = mkOption {
|
|
|
|
description = ''
|
|
|
|
A list of domains where the proxy is skipped.
|
|
|
|
'';
|
|
|
|
default = [];
|
2021-01-26 19:29:55 +00:00
|
|
|
type = types.listOf types.str;
|
2017-06-15 11:11:48 +01:00
|
|
|
example = [ "*.example.com" "example.com" ];
|
|
|
|
};
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
port = mkOption {
|
|
|
|
default = [3128];
|
2021-01-26 19:29:55 +00:00
|
|
|
type = types.listOf types.port;
|
2017-06-15 11:11:48 +01:00
|
|
|
description = "Specifies on which ports the cntlm daemon listens.";
|
|
|
|
};
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Additional config appended to the end of the generated <filename>cntlm.conf</filename>.";
|
|
|
|
};
|
2011-10-09 23:34:32 +01:00
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
configText = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Verbatim contents of <filename>cntlm.conf</filename>.";
|
2011-10-09 23:34:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2017-06-15 11:11:48 +01:00
|
|
|
config = mkIf cfg.enable {
|
2015-11-29 00:30:42 +00:00
|
|
|
systemd.services.cntlm = {
|
|
|
|
description = "CNTLM is an NTLM / NTLM Session Response / NTLMv2 authenticating HTTP proxy";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "cntlm";
|
|
|
|
ExecStart = ''
|
2017-06-15 11:11:48 +01:00
|
|
|
${pkgs.cntlm}/bin/cntlm -U cntlm -c ${configFile} -v -f
|
2015-11-29 00:30:42 +00:00
|
|
|
'';
|
2017-06-15 11:11:48 +01:00
|
|
|
};
|
2015-11-29 00:30:42 +00:00
|
|
|
};
|
2017-06-15 11:11:48 +01:00
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users.cntlm = {
|
2012-06-08 15:29:31 +01:00
|
|
|
name = "cntlm";
|
|
|
|
description = "cntlm system-wide daemon";
|
2017-06-15 11:11:48 +01:00
|
|
|
isSystemUser = true;
|
2011-10-09 23:34:32 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|