2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ...}:
|
|
|
|
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
|
2024-09-19 14:19:46 +00:00
|
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList (fileName: filePath: ''
|
2020-04-24 23:36:52 +00:00
|
|
|
mkdir -p $out/$(dirname ${fileName})
|
|
|
|
cp ${filePath} $out/${fileName}
|
|
|
|
'') cfg.configDir)}
|
|
|
|
'';
|
|
|
|
configPath = if cfg.enableReload
|
|
|
|
then "/etc/freeswitch"
|
|
|
|
else configDirectory;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.freeswitch = {
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkEnableOption "FreeSWITCH";
|
|
|
|
enableReload = lib.mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2024-09-19 14:19:46 +00:00
|
|
|
type = lib.types.bool;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-21 13:32:41 +00:00
|
|
|
Issue the `reloadxml` command to FreeSWITCH when configuration directory changes (instead of restart).
|
|
|
|
See [FreeSWITCH documentation](https://freeswitch.org/confluence/display/FREESWITCH/Reloading) for more info.
|
|
|
|
The configuration directory is exposed at {file}`/etc/freeswitch`.
|
|
|
|
See also `systemd.services.*.restartIfChanged`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
configTemplate = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "${config.services.freeswitch.package}/share/freeswitch/conf/vanilla";
|
2024-09-19 14:19:46 +00:00
|
|
|
defaultText = lib.literalExpression ''"''${config.services.freeswitch.package}/share/freeswitch/conf/vanilla"'';
|
|
|
|
example = lib.literalExpression ''"''${config.services.freeswitch.package}/share/freeswitch/conf/minimal"'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Configuration template to use.
|
2022-08-12 12:06:08 +00:00
|
|
|
See available templates in [FreeSWITCH repository](https://github.com/signalwire/freeswitch/tree/master/conf).
|
2020-04-24 23:36:52 +00:00
|
|
|
You can also set your own configuration directory.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
configDir = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf path;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = { };
|
2024-09-19 14:19:46 +00:00
|
|
|
example = lib.literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
"freeswitch.xml" = ./freeswitch.xml;
|
|
|
|
"dialplan/default.xml" = pkgs.writeText "dialplan-default.xml" '''
|
|
|
|
[xml lines]
|
|
|
|
''';
|
|
|
|
}
|
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +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-08-12 12:06:08 +00: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-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
package = lib.mkPackageOption pkgs "freeswitch" { };
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
environment.etc.freeswitch = lib.mkIf cfg.enableReload {
|
2020-04-24 23:36:52 +00:00
|
|
|
source = configDirectory;
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
systemd.services.freeswitch-config-reload = lib.mkIf cfg.enableReload {
|
2020-04-24 23:36:52 +00:00
|
|
|
before = [ "freeswitch.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
restartTriggers = [ configDirectory ];
|
|
|
|
serviceConfig = {
|
2020-05-29 06:06:01 +00:00
|
|
|
ExecStart = "/run/current-system/systemd/bin/systemctl try-reload-or-restart freeswitch.service";
|
2020-04-24 23:36:52 +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-18 07:06:33 +00:00
|
|
|
Restart = "on-failure";
|
2020-04-24 23:36:52 +00:00
|
|
|
RestartSec = "5s";
|
2020-06-18 07:06:33 +00:00
|
|
|
CPUSchedulingPolicy = "fifo";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
2020-06-18 07:06:33 +00:00
|
|
|
environment.systemPackages = [ pkg ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|