Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 stdenv,
3 lib,
4 fetchurl,
5 fetchsvn,
6 fetchFromGitHub,
7 jansson,
8 libedit,
9 libxml2,
10 libxslt,
11 ncurses,
12 openssl,
13 sqlite,
14 util-linux,
15 dmidecode,
16 libuuid,
17 newt,
18 lua,
19 speex,
20 libopus,
21 opusfile,
22 libogg,
23 srtp,
24 wget,
25 curl,
26 iksemel,
27 pkg-config,
28 autoconf,
29 libtool,
30 automake,
31 python3,
32 writeScript,
33 withOpus ? true,
34 ldapSupport ? false,
35 openldap,
36}:
37
38let
39 common =
40 {
41 version,
42 sha256,
43 externals,
44 pjsip_patches ? [ ],
45 }:
46 stdenv.mkDerivation {
47 inherit version;
48 pname = "asterisk" + lib.optionalString ldapSupport "-ldap";
49
50 buildInputs = [
51 jansson
52 libedit
53 libxml2
54 libxslt
55 ncurses
56 openssl
57 sqlite
58 dmidecode
59 libuuid
60 newt
61 lua
62 speex
63 srtp
64 wget
65 curl
66 iksemel
67 ]
68 ++ lib.optionals withOpus [
69 libopus
70 opusfile
71 libogg
72 ]
73 ++ lib.optionals ldapSupport [ openldap ];
74 nativeBuildInputs = [
75 util-linux
76 pkg-config
77 autoconf
78 libtool
79 automake
80 ];
81
82 patches = [
83 # We want the Makefile to install the default /var skeleton
84 # under ${out}/var but we also want to use /var at runtime.
85 # This patch changes the runtime behavior to look for state
86 # directories in /var rather than ${out}/var.
87 ./runtime-vardirs.patch
88 ]
89 ++ lib.optional withOpus "${asterisk-opus}/asterisk.patch";
90
91 postPatch = ''
92 echo "PJPROJECT_CONFIG_OPTS += --prefix=$out" >> third-party/pjproject/Makefile.rules
93 '';
94
95 src = fetchurl {
96 url = "https://downloads.asterisk.org/pub/telephony/asterisk/old-releases/asterisk-${version}.tar.gz";
97 inherit sha256;
98 };
99
100 # The default libdir is $PREFIX/usr/lib, which causes problems when paths
101 # compiled into Asterisk expect ${out}/usr/lib rather than ${out}/lib.
102
103 # Copy in externals to avoid them being downloaded;
104 # they have to be copied, because the modification date is checked.
105 # If you are getting a permission denied error on this dir,
106 # you're likely missing an automatically downloaded dependency
107 preConfigure = ''
108 mkdir externals_cache
109
110 ${lib.concatStringsSep "\n" (
111 lib.mapAttrsToList (dst: src: "cp -r --no-preserve=mode ${src} ${dst}") externals
112 )}
113
114 ${lib.optionalString (externals ? "addons/mp3") "bash contrib/scripts/get_mp3_source.sh || true"}
115
116 chmod -w externals_cache
117 ${lib.optionalString withOpus ''
118 cp ${asterisk-opus}/include/asterisk/* ./include/asterisk
119 cp ${asterisk-opus}/codecs/* ./codecs
120 cp ${asterisk-opus}/formats/* ./formats
121 ''}
122 ${lib.concatMapStringsSep "\n" (patch: ''
123 cp ${patch} ./third-party/pjproject/patches/${patch.name}
124 '') pjsip_patches}
125 ./bootstrap.sh
126 '';
127
128 configureFlags = [
129 "--libdir=\${out}/lib"
130 "--with-lua=${lua}/lib"
131 "--with-pjproject-bundled"
132 "--with-externals-cache=$(PWD)/externals_cache"
133 ];
134
135 preBuild = ''
136 cat third-party/pjproject/source/pjlib-util/src/pjlib-util/scanner.c
137 make menuselect.makeopts
138 ${lib.optionalString (externals ? "addons/mp3") ''
139 substituteInPlace menuselect.makeopts --replace 'format_mp3 ' ""
140 ''}
141 ${lib.optionalString withOpus ''
142 substituteInPlace menuselect.makeopts --replace 'codec_opus_open_source ' ""
143 substituteInPlace menuselect.makeopts --replace 'format_ogg_opus_open_source ' ""
144 ''}
145 '';
146
147 postInstall = ''
148 # Install sample configuration files for this version of Asterisk
149 make samples
150 ${lib.optionalString (lib.versionAtLeast version "17.0.0") "make install-headers"}
151 '';
152
153 meta = with lib; {
154 description = "Software implementation of a telephone private branch exchange (PBX)";
155 homepage = "https://www.asterisk.org/";
156 license = licenses.gpl2Only;
157 mainProgram = "asterisk";
158 maintainers = with maintainers; [
159 auntie
160 DerTim1
161 yorickvp
162 ];
163 };
164 };
165
166 pjproject_2_14_1 =
167 fetchurl {
168 url = "https://raw.githubusercontent.com/asterisk/third-party/master/pjproject/2.14.1/pjproject-2.14.1.tar.bz2";
169 hash = "sha256-MtsK8bOc0fT/H/pUydqK/ahMIVg8yiRDt3TSM1uhUFQ=";
170 }
171 // {
172 pjsip_patches = [ ];
173 };
174
175 mp3-202 = fetchsvn {
176 url = "http://svn.digium.com/svn/thirdparty/mp3/trunk";
177 rev = "202";
178 sha256 = "1s9idx2miwk178sa731ig9r4fzx4gy1q8xazfqyd7q4lfd70s1cy";
179 };
180
181 asterisk-opus = fetchFromGitHub {
182 owner = "traud";
183 repo = "asterisk-opus";
184 # No releases, points to master as of 2022-04-06
185 rev = "a959f072d3f364be983dd27e6e250b038aaef747";
186 sha256 = "sha256-CASlTvTahOg9D5jccF/IN10LP/U8rRy9BFCSaHGQfCw=";
187 };
188
189 # auto-generated by update.py
190 versions = lib.mapAttrs (
191 _:
192 { version, sha256 }:
193 let
194 pjsip = pjproject_2_14_1;
195 in
196 common {
197 inherit version sha256;
198 inherit (pjsip) pjsip_patches;
199 externals = {
200 "externals_cache/${pjsip.name}" = pjsip;
201 "addons/mp3" = mp3-202;
202 };
203 }
204 ) (lib.importJSON ./versions.json);
205
206 updateScript_python = python3.withPackages (
207 p: with p; [
208 packaging
209 beautifulsoup4
210 requests
211 ]
212 );
213 updateScript = writeScript "asterisk-update" ''
214 #!/usr/bin/env bash
215 exec ${updateScript_python}/bin/python ${toString ./update.py}
216 '';
217
218in
219{
220 # Supported releases (as of 2023-04-19).
221 # v16 and v19 have been dropped because they go EOL before the NixOS 23.11 release.
222 # Source: https://wiki.asterisk.org/wiki/display/AST/Asterisk+Versions
223 # Exact version can be found at https://www.asterisk.org/downloads/asterisk/all-asterisk-versions/
224 #
225 # Series Type Rel. Date Sec. Fixes EOL
226 # 16.x LTS 2018-10-09 2022-10-09 2023-10-09 (dropped)
227 # 18.x LTS 2020-10-20 2024-10-20 2025-10-20
228 # 19.x Standard 2021-11-02 2022-11-02 2023-11-02 (dropped)
229 # 20.x LTS 2022-11-02 2026-10-19 2027-10-19
230 # 21.x Standard 2023-10-18 2025-10-18 2026-10-18 (unreleased)
231 asterisk-lts = versions.asterisk_18;
232 asterisk-stable = versions.asterisk_20;
233 asterisk = versions.asterisk_20.overrideAttrs (o: {
234 passthru = (o.passthru or { }) // {
235 inherit updateScript;
236 };
237 });
238
239}
240// versions