13 , pythonSupport ? true
16 stdenv.mkDerivation (finalAttrs: {
20 src = fetchFromGitHub {
21 owner = finalAttrs.pname;
23 rev = "refs/tags/${finalAttrs.version}";
24 hash = "sha256-LDA3o1QMrAxcGuOi/YRoMzXmw/wFkfDs2wweZuIJ2RY=";
32 lib.optionals pythonSupport [ swig python3 ];
34 buildInputs = [ openssl libsamplerate ]
35 ++ lib.optional stdenv.isLinux alsa-lib
36 ++ lib.optionals stdenv.isDarwin [ AppKit CoreFoundation Security ];
38 env = lib.optionalAttrs stdenv.cc.isClang {
39 CXXFLAGS = "-std=c++11";
40 } // lib.optionalAttrs stdenv.isDarwin {
41 NIX_CFLAGS_LINK = "-headerpad_max_install_names";
48 postBuild = lib.optionalString pythonSupport ''
49 make -C pjsip-apps/src/swig/python
52 configureFlags = [ "--enable-shared" ];
55 ++ lib.optional pythonSupport "py";
59 cp pjsip-apps/bin/pjsua-* $out/bin/pjsua
60 mkdir -p $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
61 cp pjsip-apps/bin/samples/*/* $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
62 '' + lib.optionalString pythonSupport ''
63 (cd pjsip-apps/src/swig/python && \
64 python setup.py install --prefix=$py
66 '' + lib.optionalString stdenv.isDarwin ''
67 # On MacOS relative paths are used to refer to libraries. All libraries use
68 # a relative path like ../lib/*.dylib or ../../lib/*.dylib. We need to
69 # rewrite these to use absolute ones.
71 # First, find all libraries (and their symlinks) in our outputs to define
72 # the install_name_tool -change arguments we should pass.
73 readarray -t libraries < <(
74 for outputName in $(getAllOutputNames); do
75 find "''${!outputName}" \( -name '*.dylib*' -o -name '*.so*' \)
79 # Determine the install_name_tool -change arguments that are going to be
80 # applied to all libraries.
82 for lib in "''${libraries[@]}"; do
83 lib_name="$(basename $lib)"
84 change_args+=(-change ../lib/$lib_name $lib)
85 change_args+=(-change ../../lib/$lib_name $lib)
88 # Rewrite id and library refences for all non-symlinked libraries.
89 for lib in "''${libraries[@]}"; do
90 if [ -f "$lib" ]; then
91 install_name_tool -id $lib "''${change_args[@]}" $lib
95 # Rewrite library references for all executables.
96 find "$out" -executable -type f | while read executable; do
97 install_name_tool "''${change_args[@]}" "$executable"
101 # We need the libgcc_s.so.1 loadable (for pthread_cancel to work)
104 passthru.tests.version = testers.testVersion {
105 package = finalAttrs.finalPackage;
106 command = "pjsua --version";
109 passthru.tests.pkg-config = testers.hasPkgConfigModules {
110 package = finalAttrs.finalPackage;
113 passthru.tests.python-pjsua2 = runCommand "python-pjsua2" { } ''
114 ${(python3.withPackages (pkgs: [ pkgs.pjsua2 ])).interpreter} -c "import pjsua2" > $out
118 description = "A multimedia communication library written in C, implementing standard based protocols such as SIP, SDP, RTP, STUN, TURN, and ICE";
119 homepage = "https://pjsip.org/";
120 license = licenses.gpl2Plus;
121 maintainers = with maintainers; [ olynch ];
122 mainProgram = "pjsua";
123 platforms = platforms.linux ++ platforms.darwin;