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