1 { config, lib, pkgs, ...}:
4 cfg = config.services.freeswitch;
6 configDirectory = pkgs.runCommand "freeswitch-config-d" { } ''
8 cp -rT ${cfg.configTemplate} $out
10 ${concatStringsSep "\n" (mapAttrsToList (fileName: filePath: ''
11 mkdir -p $out/$(dirname ${fileName})
12 cp ${filePath} $out/${fileName}
15 configPath = if cfg.enableReload
16 then "/etc/freeswitch"
20 services.freeswitch = {
21 enable = mkEnableOption (lib.mdDoc "FreeSWITCH");
22 enableReload = mkOption {
25 description = lib.mdDoc ''
26 Issue the `reloadxml` command to FreeSWITCH when configuration directory changes (instead of restart).
27 See [FreeSWITCH documentation](https://freeswitch.org/confluence/display/FREESWITCH/Reloading) for more info.
28 The configuration directory is exposed at {file}`/etc/freeswitch`.
29 See also `systemd.services.*.restartIfChanged`.
32 configTemplate = mkOption {
34 default = "${config.services.freeswitch.package}/share/freeswitch/conf/vanilla";
35 defaultText = literalExpression ''"''${config.services.freeswitch.package}/share/freeswitch/conf/vanilla"'';
36 example = literalExpression ''"''${config.services.freeswitch.package}/share/freeswitch/conf/minimal"'';
37 description = lib.mdDoc ''
38 Configuration template to use.
39 See available templates in [FreeSWITCH repository](https://github.com/signalwire/freeswitch/tree/master/conf).
40 You can also set your own configuration directory.
43 configDir = mkOption {
44 type = with types; attrsOf path;
46 example = literalExpression ''
48 "freeswitch.xml" = ./freeswitch.xml;
49 "dialplan/default.xml" = pkgs.writeText "dialplan-default.xml" '''
54 description = lib.mdDoc ''
55 Override file in FreeSWITCH config template directory.
56 Each top-level attribute denotes a file path in the configuration directory, its value is the file path.
57 See [FreeSWITCH documentation](https://freeswitch.org/confluence/display/FREESWITCH/Default+Configuration) for more info.
58 Also check available templates in [FreeSWITCH repository](https://github.com/signalwire/freeswitch/tree/master/conf).
63 default = pkgs.freeswitch;
64 defaultText = literalExpression "pkgs.freeswitch";
65 description = lib.mdDoc ''
71 config = mkIf cfg.enable {
72 environment.etc.freeswitch = mkIf cfg.enableReload {
73 source = configDirectory;
75 systemd.services.freeswitch-config-reload = mkIf cfg.enableReload {
76 before = [ "freeswitch.service" ];
77 wantedBy = [ "multi-user.target" ];
78 restartTriggers = [ configDirectory ];
80 ExecStart = "/run/current-system/systemd/bin/systemctl try-reload-or-restart freeswitch.service";
81 RemainAfterExit = true;
85 systemd.services.freeswitch = {
86 description = "Free and open-source application server for real-time communication";
87 after = [ "network.target" ];
88 wantedBy = [ "multi-user.target" ];
91 StateDirectory = "freeswitch";
92 ExecStart = "${pkg}/bin/freeswitch -nf \\
93 -mod ${pkg}/lib/freeswitch/mod \\
94 -conf ${configPath} \\
95 -base /var/lib/freeswitch";
96 ExecReload = "${pkg}/bin/fs_cli -x reloadxml";
97 Restart = "on-failure";
99 CPUSchedulingPolicy = "fifo";
102 environment.systemPackages = [ pkg ];