diff --git a/modules/nixos/services/asterisk-phony/default.nix b/modules/nixos/services/asterisk-phony/default.nix new file mode 100644 index 0000000..4eb7d2a --- /dev/null +++ b/modules/nixos/services/asterisk-phony/default.nix @@ -0,0 +1,31 @@ +{ inputs, config, lib, pkgs, ... }: +let + cfg = config.services.asterisk-phony; +in +{ + imports = [ + ]; + + options.services.asterisk-phony = { + enable = lib.mkOption { + type = with lib.types; uniq bool; + default = false; + description = "Enable Asterisk Communication"; + }; + }; + + config = lib.mkIf cfg.enable { + services.asterisk = { + # See Configuration Options: https://search.nixos.org/options?channel=unstable&type=options&query=asterisk + enable = true; + confFiles = { + "pjsip.conf" = builtins.readFile ./pjsip.conf; + "extensions.conf" = builtins.readFile ./extensions.conf; + }; + }; + + # Firewall + networking.firewall.allowedTCPPorts = [ 8088 8089 ]; + # networking.firewall.allowedUDPPorts = [ ... ]; + }; +} diff --git a/modules/nixos/services/asterisk-phony/extensions.conf b/modules/nixos/services/asterisk-phony/extensions.conf new file mode 100644 index 0000000..d5a6a00 --- /dev/null +++ b/modules/nixos/services/asterisk-phony/extensions.conf @@ -0,0 +1,17 @@ +[from-internal] +; dial the lecture rooms & backoffice +; the syntax is NUMBER,SEQUENCE,FUNCTION +; to call someone do Dial(MODULE/account, timeout) +exten => 1001,1,Dial(PJSIP/saal1,20) +exten => 1002,1,Dial(PJSIP/saal2,20) +exten => 1600,1,Dial(PJSIP/backoffice,20) + +; Dial 100 for "hello, world" +; this is useful when configuring/debugging clients (snoms) +exten => 100,1,Answer() +same => n,Wait(1) +same => n,Playback(hello-world) +same => n,Hangup() +; note: "n" is a keyword meaning "the last line's value, plus 1" +; "same" is a keyword referring to the last-defined extension + diff --git a/modules/nixos/services/asterisk-phony/pjsip.conf b/modules/nixos/services/asterisk-phony/pjsip.conf new file mode 100644 index 0000000..f532bfa --- /dev/null +++ b/modules/nixos/services/asterisk-phony/pjsip.conf @@ -0,0 +1,51 @@ +; we use UDP for transport +[transport-udp] +type=transport +protocol=udp +bind=0.0.0.0 + +; Note: this defines a macro, to shorten the config further down +[endpoint_internal](!) +type=endpoint +context=from-internal +disallow=all +allow=ulaw + +[auth_userpass](!) +type=auth +auth_type=userpass + +[aor_dynamic](!) +type=aor +max_contacts=1 + + +; here come the definitions for our phones, using the macros from above + +; lecture hall 1 +[saal1](endpoint_internal) +auth=saal1 +aors=saal1 +[saal1](auth_userpass) +; well, maybe set a better password than this +password=saal1 +username=saal1 +[saal1](aor_dynamic) + +; lecture hall 2 +[saal2](endpoint_internal) +auth=saal2 +aors=saal2 +[saal2](auth_userpass) +password=saal2 +username=saal2 +[saal2](aor_dynamic) + +[backoffice](endpoint_internal) +auth=backoffice +aors=backoffice +[backoffice](auth_userpass) +password=backoffice +username=backoffice +[backoffice](aor_dynamic) + diff --git a/systems/x86_64-linux/mow0m/default.nix b/systems/x86_64-linux/mow0m/default.nix index 05bdde7..52b5e9c 100644 --- a/systems/x86_64-linux/mow0m/default.nix +++ b/systems/x86_64-linux/mow0m/default.nix @@ -56,6 +56,7 @@ }; programs.mosh.enable = true; + services.asterisk-phony.enable = true; # Firewall # networking.firewall.allowedTCPPorts = [ ... ];