1 { config, lib, pkgs, ... }:
5 let cfg = config.services.networking.websockify; in {
7 services.networking.websockify = {
9 description = "Whether to enable websockify to forward websocket connections to TCP connections.";
17 description = "Path to the SSL certificate.";
22 description = "Path to the SSL key.";
23 default = cfg.sslCert;
24 defaultText = literalExpression "config.services.networking.websockify.sslCert";
29 description = "Ports to map by default.";
31 type = types.attrsOf types.int;
36 config = mkIf cfg.enable {
37 systemd.services."websockify@" = {
38 description = "Service to forward websocket connections to TCP connections (from port:to port %I)";
40 IFS=':' read -a array <<< "$1"
41 ${pkgs.python3Packages.websockify}/bin/websockify --ssl-only \
42 --cert=${cfg.sslCert} --key=${cfg.sslKey} 0.0.0.0:''${array[0]} 0.0.0.0:''${array[1]}
47 systemd.targets.default-websockify = {
48 description = "Target to start all default websockify@ services";
49 unitConfig.X-StopOnReconfiguration = true;
50 wants = mapAttrsToList (name: value: "websockify@${name}:${toString value}.service") cfg.portMap;
51 wantedBy = [ "multi-user.target" ];