From 85d54363f21b803bde042adde51427c6c53d963f Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Sun, 19 Apr 2026 11:04:23 +0200 Subject: [PATCH] feat: add static phonebook --- hosts/telefonmann/default.nix | 5 ++++ modules/voip/default.nix | 7 +++++ modules/voip/options.nix | 23 ++++++++++++++ modules/voip/provisioning/directory.nix | 40 +++++++++++++++++++++++++ 4 files changed, 75 insertions(+) diff --git a/hosts/telefonmann/default.nix b/hosts/telefonmann/default.nix index ea7132a..ed6b015 100644 --- a/hosts/telefonmann/default.nix +++ b/hosts/telefonmann/default.nix @@ -146,6 +146,11 @@ in { # }; }; + phonebook = [ + { name = "Oma"; numbers = { Mobil = "+49151..."; Zuhause = "+494..."; }; } + { name = "Opa"; numbers = { Zuhause = "+494..."; }; } + ]; + extensions = { "*99" = { mode = "page"; displayName = "Durchsage an alle"; }; "*100" = { mode = "all"; displayName = "Alle rufen"; }; diff --git a/modules/voip/default.nix b/modules/voip/default.nix index 5502160..e3e07ae 100644 --- a/modules/voip/default.nix +++ b/modules/voip/default.nix @@ -90,6 +90,13 @@ in { "= /intercom.xml" = { alias = "${directory.intercomFile}"; extraConfig = "default_type text/xml;"; }; "= /contacts.json" = { alias = "${directoryJson}"; extraConfig = ''default_type application/json; add_header Access-Control-Allow-Origin "*";''; }; "= /auth" = { extraConfig = ''default_type text/plain; return 200 "AUTHORIZED";''; }; + } // lib.optionalAttrs (cfg.phonebook != []) ( + { "= /phonebook.xml" = { alias = "${directory.phonebookMenuFile}"; extraConfig = "default_type text/xml;"; }; } + // lib.listToAttrs (lib.imap0 (i: _: { + name = "= /phonebook-${toString i}.xml"; + value = { alias = "${lib.elemAt directory.phonebookDetailFiles i}"; extraConfig = "default_type text/xml;"; }; + }) cfg.phonebook) + ) // { "/" = { root = "${diagram.webRoot}"; extraConfig = lib.optionalString (!hasRuntimeSecrets) "index index.html;"; diff --git a/modules/voip/options.nix b/modules/voip/options.nix index affded6..8fe485e 100644 --- a/modules/voip/options.nix +++ b/modules/voip/options.nix @@ -306,6 +306,29 @@ in { }); }; + phonebook = lib.mkOption { + default = []; + description = '' + External contacts shown in the phone directory. Example: + [ + { name = "Oma"; numbers = { Mobil = "+49151..."; Zuhause = "+494..."; }; } + { name = "Opa"; numbers = { Zuhause = "+494..."; }; } + ] + ''; + type = lib.types.listOf (lib.types.submodule { + options = { + name = lib.mkOption { + type = lib.types.str; + description = "Contact name shown in the directory listing."; + }; + numbers = lib.mkOption { + type = lib.types.attrsOf lib.types.str; + description = ''Labelled phone numbers, e.g. { Mobil = "+49..."; Zuhause = "+49..."; }.''; + }; + }; + }); + }; + voicemailCheckExtension = lib.mkOption { type = lib.types.str; default = "*97"; diff --git a/modules/voip/provisioning/directory.nix b/modules/voip/provisioning/directory.nix index c5d7c4d..baaf656 100644 --- a/modules/voip/provisioning/directory.nix +++ b/modules/voip/provisioning/directory.nix @@ -4,6 +4,7 @@ let baseUrl = "http://${cfg.serverAddress}:${toString cfg.directoryPort}"; hasPageExtensions = lib.any (e: e.mode == "page") (lib.attrValues cfg.extensions); + hasPhonebook = cfg.phonebook != []; # Deduplicated directory entries: one per extension, using the displayName from # allPhones (all phones sharing an extension have the same displayName). @@ -27,6 +28,11 @@ let Intercom / Durchsage ${baseUrl}/intercom.xml + '' + lib.optionalString hasPhonebook '' + + Externes Telefonbuch + ${baseUrl}/phonebook.xml + '' + '' ''; @@ -68,8 +74,42 @@ let ''; + phonebookMenuXml = '' + + + Externes Telefonbuch + Bitte wählen + '' + lib.concatStringsSep "\n" (lib.imap0 (i: contact: '' + + ${contact.name} + ${baseUrl}/phonebook-${toString i}.xml + + '') cfg.phonebook) + + '' + + ''; + + mkContactXml = contact: '' + + + ${contact.name} + Bitte wählen + '' + lib.concatStringsSep "\n" (lib.mapAttrsToList (label: number: '' + + ${label} + ${number} + + '') contact.numbers) + + '' + + ''; + in { menuFile = pkgs.writeText "directory.xml" menuXml; listFile = pkgs.writeText "directory-list.xml" listXml; intercomFile = pkgs.writeText "intercom.xml" intercomXml; + phonebookMenuFile = pkgs.writeText "phonebook.xml" phonebookMenuXml; + phonebookDetailFiles = lib.imap0 (i: contact: + pkgs.writeText "phonebook-${toString i}.xml" (mkContactXml contact) + ) cfg.phonebook; }