2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
105 lines
4.0 KiB
Nix
105 lines
4.0 KiB
Nix
{ 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";
|
|
defaultText = literalExpression ''"''${config.services.freeswitch.package}/share/freeswitch/conf/vanilla"'';
|
|
example = literalExpression ''"''${config.services.freeswitch.package}/share/freeswitch/conf/minimal"'';
|
|
description = lib.mdDoc ''
|
|
Configuration template to use.
|
|
See available templates in [FreeSWITCH repository](https://github.com/signalwire/freeswitch/tree/master/conf).
|
|
You can also set your own configuration directory.
|
|
'';
|
|
};
|
|
configDir = mkOption {
|
|
type = with types; attrsOf path;
|
|
default = { };
|
|
example = literalExpression ''
|
|
{
|
|
"freeswitch.xml" = ./freeswitch.xml;
|
|
"dialplan/default.xml" = pkgs.writeText "dialplan-default.xml" '''
|
|
[xml lines]
|
|
''';
|
|
}
|
|
'';
|
|
description = lib.mdDoc ''
|
|
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.
|
|
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).
|
|
'';
|
|
};
|
|
package = mkOption {
|
|
type = types.package;
|
|
default = pkgs.freeswitch;
|
|
defaultText = literalExpression "pkgs.freeswitch";
|
|
description = lib.mdDoc ''
|
|
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 = {
|
|
ExecStart = "/run/current-system/systemd/bin/systemctl try-reload-or-restart freeswitch.service";
|
|
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";
|
|
Restart = "on-failure";
|
|
RestartSec = "5s";
|
|
CPUSchedulingPolicy = "fifo";
|
|
};
|
|
};
|
|
environment.systemPackages = [ pkg ];
|
|
};
|
|
}
|