2020-01-07 14:53:34 +00:00
|
|
|
{ config, lib, pkgs, ...}:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.freeswitch;
|
|
|
|
pkg = cfg.package;
|
|
|
|
configDirectory = pkgs.runCommand "freeswitch-config-d" { } ''
|
|
|
|
mkdir -p $out
|
|
|
|
cp -rT ${cfg.configTemplate} $out
|
|
|
|
chmod -R +w $out
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList (fileName: filePath: ''
|
|
|
|
mkdir -p $out/$(dirname ${fileName})
|
|
|
|
cp ${filePath} $out/${fileName}
|
|
|
|
'') cfg.configDir)}
|
|
|
|
'';
|
|
|
|
configPath = if cfg.enableReload
|
|
|
|
then "/etc/freeswitch"
|
|
|
|
else configDirectory;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.freeswitch = {
|
|
|
|
enable = mkEnableOption "FreeSWITCH";
|
|
|
|
enableReload = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Issue the <literal>reloadxml</literal> command to FreeSWITCH when configuration directory changes (instead of restart).
|
|
|
|
See <link xlink:href="https://freeswitch.org/confluence/display/FREESWITCH/Reloading">FreeSWITCH documentation</link> for more info.
|
|
|
|
The configuration directory is exposed at <filename>/etc/freeswitch</filename>.
|
|
|
|
See also <literal>systemd.services.*.restartIfChanged</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
configTemplate = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "${config.services.freeswitch.package}/share/freeswitch/conf/vanilla";
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression ''"''${config.services.freeswitch.package}/share/freeswitch/conf/vanilla"'';
|
|
|
|
example = literalExpression ''"''${config.services.freeswitch.package}/share/freeswitch/conf/minimal"'';
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2020-01-07 14:53:34 +00:00
|
|
|
Configuration template to use.
|
2022-07-28 22:19:15 +01:00
|
|
|
See available templates in [FreeSWITCH repository](https://github.com/signalwire/freeswitch/tree/master/conf).
|
2020-01-07 14:53:34 +00:00
|
|
|
You can also set your own configuration directory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
configDir = mkOption {
|
|
|
|
type = with types; attrsOf path;
|
|
|
|
default = { };
|
2021-10-03 17:06:03 +01:00
|
|
|
example = literalExpression ''
|
2020-01-07 14:53:34 +00:00
|
|
|
{
|
|
|
|
"freeswitch.xml" = ./freeswitch.xml;
|
|
|
|
"dialplan/default.xml" = pkgs.writeText "dialplan-default.xml" '''
|
|
|
|
[xml lines]
|
|
|
|
''';
|
|
|
|
}
|
|
|
|
'';
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2020-01-07 14:53:34 +00:00
|
|
|
Override file in FreeSWITCH config template directory.
|
|
|
|
Each top-level attribute denotes a file path in the configuration directory, its value is the file path.
|
2022-07-28 22:19:15 +01:00
|
|
|
See [FreeSWITCH documentation](https://freeswitch.org/confluence/display/FREESWITCH/Default+Configuration) for more info.
|
|
|
|
Also check available templates in [FreeSWITCH repository](https://github.com/signalwire/freeswitch/tree/master/conf).
|
2020-01-07 14:53:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.freeswitch;
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression "pkgs.freeswitch";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2020-01-07 14:53:34 +00:00
|
|
|
FreeSWITCH package.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.etc.freeswitch = mkIf cfg.enableReload {
|
|
|
|
source = configDirectory;
|
|
|
|
};
|
|
|
|
systemd.services.freeswitch-config-reload = mkIf cfg.enableReload {
|
|
|
|
before = [ "freeswitch.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
restartTriggers = [ configDirectory ];
|
|
|
|
serviceConfig = {
|
2020-05-21 09:29:52 +01:00
|
|
|
ExecStart = "/run/current-system/systemd/bin/systemctl try-reload-or-restart freeswitch.service";
|
2020-01-07 14:53:34 +00:00
|
|
|
RemainAfterExit = true;
|
|
|
|
Type = "oneshot";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services.freeswitch = {
|
|
|
|
description = "Free and open-source application server for real-time communication";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
StateDirectory = "freeswitch";
|
|
|
|
ExecStart = "${pkg}/bin/freeswitch -nf \\
|
|
|
|
-mod ${pkg}/lib/freeswitch/mod \\
|
|
|
|
-conf ${configPath} \\
|
|
|
|
-base /var/lib/freeswitch";
|
|
|
|
ExecReload = "${pkg}/bin/fs_cli -x reloadxml";
|
2020-06-05 19:07:29 +01:00
|
|
|
Restart = "on-failure";
|
2020-01-07 14:53:34 +00:00
|
|
|
RestartSec = "5s";
|
2020-06-05 19:07:29 +01:00
|
|
|
CPUSchedulingPolicy = "fifo";
|
2020-01-07 14:53:34 +00:00
|
|
|
};
|
|
|
|
};
|
2020-06-05 19:07:29 +01:00
|
|
|
environment.systemPackages = [ pkg ];
|
2020-01-07 14:53:34 +00:00
|
|
|
};
|
|
|
|
}
|