From e1f7581bde189ddb0d306a743144fa2952905f9d Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Mon, 10 Nov 2025 21:29:01 +0000 Subject: [PATCH] Add asterisk It seems to work - I connected a client to it - but I never successfully made any calls. --- modules/system/asterisk.nix | 97 +++++++++++++++++++++++++++++++++++++ modules/system/default.nix | 1 + roles/nidus-sync.nix | 2 +- 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 modules/system/asterisk.nix diff --git a/modules/system/asterisk.nix b/modules/system/asterisk.nix new file mode 100644 index 0000000..0a6bc67 --- /dev/null +++ b/modules/system/asterisk.nix @@ -0,0 +1,97 @@ +{ pkgs, lib, config, ... }: +with lib; +{ + options.myModules.asterisk.enable = mkEnableOption "custom asterisk configuration"; + + config = mkIf config.myModules.asterisk.enable { + networking.firewall = { + allowedTCPPorts = [ 5060 ]; + allowedUDPPortRanges = [ + { from=1000; to=20000; } + ]; + allowedUDPPorts = [ 4569 5060 ]; + }; + services.asterisk = { + enable = true; + confFiles = { + "extensions.conf" = '' +[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 +''; + "pjsip.conf" = '' +; 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) +''; + "logger.conf" = '' +[general] + +[logfiles] +; Add debug output to log +syslog.local0 => notice,warning,error,debug +''; + }; + }; + }; +} diff --git a/modules/system/default.nix b/modules/system/default.nix index 2d63d1a..1bed128 100644 --- a/modules/system/default.nix +++ b/modules/system/default.nix @@ -1,5 +1,6 @@ { imports = [ + ./asterisk.nix ./authentik.nix ./authentik-backup.nix ./base.nix diff --git a/roles/nidus-sync.nix b/roles/nidus-sync.nix index 5db6970..e259fe6 100644 --- a/roles/nidus-sync.nix +++ b/roles/nidus-sync.nix @@ -55,6 +55,6 @@ in { ]; - + myModules.asterisk.enable = false; myModules.caddy.enable = true; }