38 common = { version, sha256, externals, pjsip_patches ? [ ] }: stdenv.mkDerivation {
41 + lib.optionalString ldapSupport "-ldap";
62 ++ lib.optionals withOpus [ libopus opusfile libogg ]
63 ++ lib.optionals ldapSupport [ openldap ];
64 nativeBuildInputs = [ util-linux pkg-config autoconf libtool automake ];
67 # We want the Makefile to install the default /var skeleton
68 # under ${out}/var but we also want to use /var at runtime.
69 # This patch changes the runtime behavior to look for state
70 # directories in /var rather than ${out}/var.
71 ./runtime-vardirs.patch
72 ] ++ lib.optional withOpus "${asterisk-opus}/asterisk.patch";
75 echo "PJPROJECT_CONFIG_OPTS += --prefix=$out" >> third-party/pjproject/Makefile.rules
79 url = "https://downloads.asterisk.org/pub/telephony/asterisk/old-releases/asterisk-${version}.tar.gz";
83 # The default libdir is $PREFIX/usr/lib, which causes problems when paths
84 # compiled into Asterisk expect ${out}/usr/lib rather than ${out}/lib.
86 # Copy in externals to avoid them being downloaded;
87 # they have to be copied, because the modification date is checked.
88 # If you are getting a permission denied error on this dir,
89 # you're likely missing an automatically downloaded dependency
93 ${lib.concatStringsSep "\n"
94 (lib.mapAttrsToList (dst: src: "cp -r --no-preserve=mode ${src} ${dst}") externals)}
96 ${lib.optionalString (externals ? "addons/mp3") "bash contrib/scripts/get_mp3_source.sh || true"}
98 chmod -w externals_cache
99 ${lib.optionalString withOpus ''
100 cp ${asterisk-opus}/include/asterisk/* ./include/asterisk
101 cp ${asterisk-opus}/codecs/* ./codecs
102 cp ${asterisk-opus}/formats/* ./formats
104 ${lib.concatMapStringsSep "\n" (patch: ''
105 cp ${patch} ./third-party/pjproject/patches/${patch.name}
111 "--libdir=\${out}/lib"
112 "--with-lua=${lua}/lib"
113 "--with-pjproject-bundled"
114 "--with-externals-cache=$(PWD)/externals_cache"
118 cat third-party/pjproject/source/pjlib-util/src/pjlib-util/scanner.c
119 make menuselect.makeopts
120 ${lib.optionalString (externals ? "addons/mp3") ''
121 substituteInPlace menuselect.makeopts --replace 'format_mp3 ' ""
123 ${lib.optionalString withOpus ''
124 substituteInPlace menuselect.makeopts --replace 'codec_opus_open_source ' ""
125 substituteInPlace menuselect.makeopts --replace 'format_ogg_opus_open_source ' ""
130 # Install sample configuration files for this version of Asterisk
132 ${lib.optionalString (lib.versionAtLeast version "17.0.0") "make install-headers"}
136 description = "Software implementation of a telephone private branch exchange (PBX)";
137 homepage = "https://www.asterisk.org/";
138 license = licenses.gpl2Only;
139 mainProgram = "asterisk";
140 maintainers = with maintainers; [ auntie DerTim1 yorickvp ];
144 pjproject_2_14_1 = fetchurl
146 url = "https://raw.githubusercontent.com/asterisk/third-party/master/pjproject/2.14.1/pjproject-2.14.1.tar.bz2";
147 hash = "sha256-MtsK8bOc0fT/H/pUydqK/ahMIVg8yiRDt3TSM1uhUFQ=";
153 url = "http://svn.digium.com/svn/thirdparty/mp3/trunk";
155 sha256 = "1s9idx2miwk178sa731ig9r4fzx4gy1q8xazfqyd7q4lfd70s1cy";
158 asterisk-opus = fetchFromGitHub {
160 repo = "asterisk-opus";
161 # No releases, points to master as of 2022-04-06
162 rev = "a959f072d3f364be983dd27e6e250b038aaef747";
163 sha256 = "sha256-CASlTvTahOg9D5jccF/IN10LP/U8rRy9BFCSaHGQfCw=";
166 # auto-generated by update.py
167 versions = lib.mapAttrs
168 (_: { version, sha256 }:
170 pjsip = pjproject_2_14_1;
173 inherit version sha256;
174 inherit (pjsip) pjsip_patches;
176 "externals_cache/${pjsip.name}" = pjsip;
177 "addons/mp3" = mp3-202;
180 (lib.importJSON ./versions.json);
182 updateScript_python = python3.withPackages (p: with p; [ packaging beautifulsoup4 requests ]);
183 updateScript = writeScript "asterisk-update" ''
185 exec ${updateScript_python}/bin/python ${toString ./update.py}
190 # Supported releases (as of 2023-04-19).
191 # v16 and v19 have been dropped because they go EOL before the NixOS 23.11 release.
192 # Source: https://wiki.asterisk.org/wiki/display/AST/Asterisk+Versions
193 # Exact version can be found at https://www.asterisk.org/downloads/asterisk/all-asterisk-versions/
195 # Series Type Rel. Date Sec. Fixes EOL
196 # 16.x LTS 2018-10-09 2022-10-09 2023-10-09 (dropped)
197 # 18.x LTS 2020-10-20 2024-10-20 2025-10-20
198 # 19.x Standard 2021-11-02 2022-11-02 2023-11-02 (dropped)
199 # 20.x LTS 2022-11-02 2026-10-19 2027-10-19
200 # 21.x Standard 2023-10-18 2025-10-18 2026-10-18 (unreleased)
201 asterisk-lts = versions.asterisk_18;
202 asterisk-stable = versions.asterisk_20;
203 asterisk = versions.asterisk_20.overrideAttrs (o: {
204 passthru = (o.passthru or { }) // { inherit updateScript; };