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