1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 fetchurl,
6 fetchpatch,
7 cython,
8 setuptools,
9 alsa-lib,
10 ffmpeg,
11 libopus,
12 libuuid,
13 libv4l,
14 libvpx,
15 opencore-amr,
16 openssl,
17 pkg-config,
18 sqlite,
19 x264,
20 python3-application,
21}:
22
23let
24 extDeps = {
25 pjsip = rec {
26 # Hardcoded in get_dependencies.sh, checked at buildtime
27 # need tarball specifically for buildscript to detect it
28 version = "2.10";
29 src = fetchurl {
30 url = "https://github.com/pjsip/pjproject/archive/${version}.tar.gz";
31 hash = "sha256-k2pMW5hgG1IyVGOjl93xGrQQbGp7BPjcfN03fvu1l94=";
32 };
33 patches = [
34 # Backported https://github.com/pjsip/pjproject/commit/4a8d180529d6ffb0760838b1f8cadc4cb5f7ac03
35 ./pjsip-0001-NEON.patch
36
37 # Backported https://github.com/pjsip/pjproject/commit/f56fd48e23982c47f38574a3fd93ebf248ef3762
38 ./pjsip-0002-RISC-V.patch
39
40 # Backported https://github.com/pjsip/pjproject/commit/f94b18ef6e0c0b5d34eb274f85ac0a3b2cf9107a
41 ./pjsip-0003-LoongArch64.patch
42 ];
43 };
44 zrtpcpp = rec {
45 # Hardcoded in get_dependencies.sh, NOT checked at buildtime
46 rev = "6b3cd8e6783642292bad0c21e3e5e5ce45ff3e03";
47 src = fetchFromGitHub {
48 owner = "wernerd";
49 repo = "ZRTPCPP";
50 inherit rev;
51 hash = "sha256-kJlGPVA+yfn7fuRjXU0p234VcZBAf1MU4gRKuPotfog=";
52 };
53 };
54 };
55
56 applyPatchesWhenAvailable =
57 extDep: dir:
58 lib.optionalString (extDep ? patches) (
59 lib.strings.concatMapStringsSep "\n" (patch: ''
60 echo "Applying patch ${patch}"
61 patch -p1 -d ${dir} < ${patch}
62 '') extDep.patches
63 );
64in
65buildPythonPackage rec {
66 pname = "python3-sipsimple";
67 version = "5.3.3.2";
68 pyproject = true;
69
70 src = fetchFromGitHub {
71 owner = "AGProjects";
72 repo = "python3-sipsimple";
73 tag = "${version}-mac";
74 hash = "sha256-kDXVzLmgfXxm8phKrV7DvPuZ9O2iNFo1s6Lc0jcc/dM=";
75 };
76
77 patches = [
78 # Remove when version > 5.3.3.2-mac
79 (fetchpatch {
80 name = "0001-python3-sipsimple-port-to-cython-3.patch";
81 url = "https://github.com/AGProjects/python3-sipsimple/commit/ccbbbb0225b2417bdf6ae07da96bffe367e242be.patch";
82 hash = "sha256-MBiM9/yS5yX9QoZT7p76PI2rbBr22fZw6TAT4tw9iZk=";
83 })
84 ];
85
86 postPatch = ''
87 substituteInPlace get_dependencies.sh \
88 --replace-fail 'sudo apt' 'echo Skipping sudo apt'
89 '';
90
91 strictDeps = true;
92
93 nativeBuildInputs = [
94 pkg-config
95 ];
96
97 build-system = [
98 cython
99 setuptools
100 ];
101
102 buildInputs = [
103 alsa-lib
104 ffmpeg
105 libopus
106 libuuid
107 libv4l
108 libvpx
109 opencore-amr
110 openssl
111 sqlite
112 x264
113 ];
114
115 dependencies = [
116 python3-application
117 ];
118
119 preConfigure = ''
120 ln -s ${passthru.extDeps.pjsip.src} deps/${passthru.extDeps.pjsip.version}.tar.gz
121 cp -r --no-preserve=all ${passthru.extDeps.zrtpcpp.src} deps/ZRTPCPP
122
123 bash ./get_dependencies.sh
124 ''
125 + applyPatchesWhenAvailable extDeps.pjsip "deps/pjsip"
126 + applyPatchesWhenAvailable extDeps.zrtpcpp "deps/ZRTPCPP"
127 + ''
128 # Fails to link some static libs due to missing -lc DSO. Just use the compiler frontend instead of raw ld.
129 substituteInPlace deps/pjsip/build/rules.mak \
130 --replace-fail '$(LD)' "$CC"
131
132 # Incompatible pointers (not const)
133 substituteInPlace deps/pjsip/pjmedia/src/pjmedia-codec/ffmpeg_vid_codecs.c \
134 --replace-fail '&payload,' '(const pj_uint8_t **)&payload,'
135 '';
136
137 # no upstream tests exist
138 doCheck = false;
139
140 pythonImportsCheck = [ "sipsimple" ];
141
142 passthru = {
143 inherit extDeps;
144 };
145
146 meta = {
147 description = "SIP SIMPLE SDK written in Python";
148 homepage = "https://sipsimpleclient.org/";
149 downloadPage = "https://github.com/AGProjects/python3-sipsimple";
150 license = lib.licenses.gpl3Plus;
151 teams = [ lib.teams.ngi ];
152 maintainers = [ lib.maintainers.ethancedwards8 ];
153 };
154}