2015-02-04 23:36:27 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.sslh;
|
|
|
|
configFile = pkgs.writeText "sslh.conf" ''
|
2017-04-11 17:08:51 +01:00
|
|
|
verbose: ${boolToString cfg.verbose};
|
2015-02-12 12:21:36 +00:00
|
|
|
foreground: true;
|
2015-02-04 23:36:27 +00:00
|
|
|
inetd: false;
|
|
|
|
numeric: false;
|
|
|
|
transparent: false;
|
|
|
|
timeout: "${toString cfg.timeout}";
|
|
|
|
user: "nobody";
|
2015-02-12 12:21:36 +00:00
|
|
|
pidfile: "${cfg.pidfile}";
|
2015-02-04 23:36:27 +00:00
|
|
|
|
|
|
|
listen:
|
|
|
|
(
|
2015-12-23 23:23:51 +00:00
|
|
|
{ host: "${cfg.listenAddress}"; port: "${toString cfg.port}"; }
|
2015-02-04 23:36:27 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
${cfg.appendConfig}
|
|
|
|
'';
|
|
|
|
defaultAppendConfig = ''
|
|
|
|
protocols:
|
|
|
|
(
|
|
|
|
{ name: "ssh"; service: "ssh"; host: "localhost"; port: "22"; probe: "builtin"; },
|
|
|
|
{ name: "openvpn"; host: "localhost"; port: "1194"; probe: "builtin"; },
|
|
|
|
{ name: "xmpp"; host: "localhost"; port: "5222"; probe: "builtin"; },
|
|
|
|
{ name: "http"; host: "localhost"; port: "80"; probe: "builtin"; },
|
|
|
|
{ name: "ssl"; host: "localhost"; port: "443"; probe: "builtin"; },
|
|
|
|
{ name: "anyprot"; host: "localhost"; port: "443"; probe: "builtin"; }
|
|
|
|
);
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.sslh = {
|
|
|
|
enable = mkEnableOption "sslh";
|
|
|
|
|
|
|
|
verbose = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Verbose logs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
timeout = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 2;
|
|
|
|
description = "Timeout in seconds.";
|
|
|
|
};
|
|
|
|
|
2015-02-12 12:21:36 +00:00
|
|
|
pidfile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/run/sslh.pid";
|
|
|
|
description = "PID file path for sslh daemon.";
|
|
|
|
};
|
|
|
|
|
2015-12-23 23:23:51 +00:00
|
|
|
listenAddress = mkOption {
|
2015-02-04 23:36:27 +00:00
|
|
|
type = types.str;
|
|
|
|
default = config.networking.hostName;
|
|
|
|
description = "Listening hostname.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 443;
|
|
|
|
description = "Listening port.";
|
|
|
|
};
|
|
|
|
|
|
|
|
appendConfig = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = defaultAppendConfig;
|
|
|
|
description = "Verbatim configuration file.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.sslh = {
|
|
|
|
description = "Applicative Protocol Multiplexer (e.g. share SSH and HTTPS on the same port)";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2015-04-21 17:28:08 +01:00
|
|
|
serviceConfig.ExecStart = "${pkgs.sslh}/bin/sslh -F${configFile}";
|
2015-02-04 23:36:27 +00:00
|
|
|
serviceConfig.KillMode = "process";
|
2015-02-12 12:21:36 +00:00
|
|
|
serviceConfig.PIDFile = "${cfg.pidfile}";
|
2015-02-04 23:36:27 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|