Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

nixos/freeswitch: init (#76821)

nixos/freeswitch: init

authored by

Silvan Mosberger and committed by
GitHub
2118cddc b5da8e87

+138
+1
nixos/modules/module-list.nix
··· 428 428 ./services/misc/exhibitor.nix 429 429 ./services/misc/felix.nix 430 430 ./services/misc/folding-at-home.nix 431 + ./services/misc/freeswitch.nix 431 432 ./services/misc/fstrim.nix 432 433 ./services/misc/gammu-smsd.nix 433 434 ./services/misc/geoip-updater.nix
+103
nixos/modules/services/misc/freeswitch.nix
··· 1 + { config, lib, pkgs, ...}: 2 + with lib; 3 + let 4 + cfg = config.services.freeswitch; 5 + pkg = cfg.package; 6 + configDirectory = pkgs.runCommand "freeswitch-config-d" { } '' 7 + mkdir -p $out 8 + cp -rT ${cfg.configTemplate} $out 9 + chmod -R +w $out 10 + ${concatStringsSep "\n" (mapAttrsToList (fileName: filePath: '' 11 + mkdir -p $out/$(dirname ${fileName}) 12 + cp ${filePath} $out/${fileName} 13 + '') cfg.configDir)} 14 + ''; 15 + configPath = if cfg.enableReload 16 + then "/etc/freeswitch" 17 + else configDirectory; 18 + in { 19 + options = { 20 + services.freeswitch = { 21 + enable = mkEnableOption "FreeSWITCH"; 22 + enableReload = mkOption { 23 + default = false; 24 + type = types.bool; 25 + description = '' 26 + Issue the <literal>reloadxml</literal> command to FreeSWITCH when configuration directory changes (instead of restart). 27 + See <link xlink:href="https://freeswitch.org/confluence/display/FREESWITCH/Reloading">FreeSWITCH documentation</link> for more info. 28 + The configuration directory is exposed at <filename>/etc/freeswitch</filename>. 29 + See also <literal>systemd.services.*.restartIfChanged</literal>. 30 + ''; 31 + }; 32 + configTemplate = mkOption { 33 + type = types.path; 34 + default = "${config.services.freeswitch.package}/share/freeswitch/conf/vanilla"; 35 + defaultText = literalExample "\${config.services.freeswitch.package}/share/freeswitch/conf/vanilla"; 36 + example = literalExample "\${config.services.freeswitch.package}/share/freeswitch/conf/minimal"; 37 + description = '' 38 + Configuration template to use. 39 + See available templates in <link xlink:href="https://github.com/signalwire/freeswitch/tree/master/conf">FreeSWITCH repository</link>. 40 + You can also set your own configuration directory. 41 + ''; 42 + }; 43 + configDir = mkOption { 44 + type = with types; attrsOf path; 45 + default = { }; 46 + example = literalExample '' 47 + { 48 + "freeswitch.xml" = ./freeswitch.xml; 49 + "dialplan/default.xml" = pkgs.writeText "dialplan-default.xml" ''' 50 + [xml lines] 51 + '''; 52 + } 53 + ''; 54 + description = '' 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 <link xlink:href="https://freeswitch.org/confluence/display/FREESWITCH/Default+Configuration">FreeSWITCH documentation</link> for more info. 58 + Also check available templates in <link xlink:href="https://github.com/signalwire/freeswitch/tree/master/conf">FreeSWITCH repository</link>. 59 + ''; 60 + }; 61 + package = mkOption { 62 + type = types.package; 63 + default = pkgs.freeswitch; 64 + defaultText = literalExample "pkgs.freeswitch"; 65 + example = literalExample "pkgs.freeswitch"; 66 + description = '' 67 + FreeSWITCH package. 68 + ''; 69 + }; 70 + }; 71 + }; 72 + config = mkIf cfg.enable { 73 + environment.etc.freeswitch = mkIf cfg.enableReload { 74 + source = configDirectory; 75 + }; 76 + systemd.services.freeswitch-config-reload = mkIf cfg.enableReload { 77 + before = [ "freeswitch.service" ]; 78 + wantedBy = [ "multi-user.target" ]; 79 + restartTriggers = [ configDirectory ]; 80 + serviceConfig = { 81 + ExecStart = "${pkgs.systemd}/bin/systemctl try-reload-or-restart freeswitch.service"; 82 + RemainAfterExit = true; 83 + Type = "oneshot"; 84 + }; 85 + }; 86 + systemd.services.freeswitch = { 87 + description = "Free and open-source application server for real-time communication"; 88 + after = [ "network.target" ]; 89 + wantedBy = [ "multi-user.target" ]; 90 + serviceConfig = { 91 + DynamicUser = true; 92 + StateDirectory = "freeswitch"; 93 + ExecStart = "${pkg}/bin/freeswitch -nf \\ 94 + -mod ${pkg}/lib/freeswitch/mod \\ 95 + -conf ${configPath} \\ 96 + -base /var/lib/freeswitch"; 97 + ExecReload = "${pkg}/bin/fs_cli -x reloadxml"; 98 + Restart = "always"; 99 + RestartSec = "5s"; 100 + }; 101 + }; 102 + }; 103 + }
+1
nixos/tests/all-tests.nix
··· 94 94 flannel = handleTestOn ["x86_64-linux"] ./flannel.nix {}; 95 95 fluentd = handleTest ./fluentd.nix {}; 96 96 fontconfig-default-fonts = handleTest ./fontconfig-default-fonts.nix {}; 97 + freeswitch = handleTest ./freeswitch.nix {}; 97 98 fsck = handleTest ./fsck.nix {}; 98 99 gotify-server = handleTest ./gotify-server.nix {}; 99 100 gitea = handleTest ./gitea.nix {};
+29
nixos/tests/freeswitch.nix
··· 1 + import ./make-test-python.nix ({ pkgs, ...} : { 2 + name = "freeswitch"; 3 + meta = with pkgs.stdenv.lib.maintainers; { 4 + maintainers = [ misuzu ]; 5 + }; 6 + nodes = { 7 + node0 = { config, lib, ... }: { 8 + networking.useDHCP = false; 9 + networking.interfaces.eth1 = { 10 + ipv4.addresses = [ 11 + { 12 + address = "192.168.0.1"; 13 + prefixLength = 24; 14 + } 15 + ]; 16 + }; 17 + services.freeswitch = { 18 + enable = true; 19 + enableReload = true; 20 + configTemplate = "${config.services.freeswitch.package}/share/freeswitch/conf/minimal"; 21 + }; 22 + }; 23 + }; 24 + testScript = '' 25 + node0.wait_for_unit("freeswitch.service") 26 + # Wait for SIP port to be open 27 + node0.wait_for_open_port("5060") 28 + ''; 29 + })
+4
pkgs/servers/sip/freeswitch/default.nix
··· 111 111 ++ lib.unique (lib.concatMap (mod: mod.inputs) enabledModules) 112 112 ++ lib.optionals stdenv.isDarwin [ SystemConfiguration ]; 113 113 114 + enableParallelBuilding = true; 115 + 114 116 NIX_CFLAGS_COMPILE = "-Wno-error"; 115 117 116 118 hardeningDisable = [ "format" ]; ··· 123 125 postInstall = '' 124 126 # helper for compiling modules... not generally useful; also pulls in perl dependency 125 127 rm "$out"/bin/fsxs 128 + # include configuration templates 129 + cp -r conf $out/share/freeswitch/ 126 130 ''; 127 131 128 132 meta = {