summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/python3-sipsimple/default.nix
blob: 0cb17e89985b6aabd477e694257d6bf22e776171 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
{
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  fetchurl,
  fetchpatch,
  nix-update-script,
  cython,
  setuptools,
  alsa-lib,
  ffmpeg_7,
  libopus,
  libuuid,
  libv4l,
  libvpx,
  opencore-amr,
  openssl,
  pkg-config,
  sqlite,
  x264,
  python3-application,
}:
let
  applyPatchesWhenAvailable =
    extDep: dir:
    lib.optionalString (extDep ? patches) (
      lib.strings.concatMapStringsSep "\n" (patch: ''
        echo "Applying patch ${patch}"
        patch -p1 -d ${dir} < ${patch}
      '') extDep.patches
    );
in
buildPythonPackage (finalAttrs: {
  pname = "python3-sipsimple";
  version = "5.3.3.2";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "AGProjects";
    repo = "python3-sipsimple";
    tag = "${finalAttrs.version}-mac";
    hash = "sha256-kDXVzLmgfXxm8phKrV7DvPuZ9O2iNFo1s6Lc0jcc/dM=";
  };

  patches = [
    # Remove when version > 5.3.3.2-mac
    (fetchpatch {
      name = "0001-python3-sipsimple-port-to-cython-3.patch";
      url = "https://github.com/AGProjects/python3-sipsimple/commit/ccbbbb0225b2417bdf6ae07da96bffe367e242be.patch";
      hash = "sha256-MBiM9/yS5yX9QoZT7p76PI2rbBr22fZw6TAT4tw9iZk=";
    })
  ];

  postPatch = ''
    substituteInPlace get_dependencies.sh \
      --replace-fail 'sudo apt' 'echo Skipping sudo apt'
  '';

  strictDeps = true;

  nativeBuildInputs = [
    pkg-config
  ];

  build-system = [
    cython
    setuptools
  ];

  buildInputs = [
    alsa-lib
    ffmpeg_7
    libopus
    libuuid
    libv4l
    libvpx
    opencore-amr
    openssl
    sqlite
    x264
  ];

  dependencies = [
    python3-application
  ];

  preConfigure = ''
    ln -s ${finalAttrs.passthru.extDeps.pjsip.src} deps/${finalAttrs.passthru.extDeps.pjsip.version}.tar.gz
    cp -r --no-preserve=all ${finalAttrs.passthru.extDeps.zrtpcpp.src} deps/ZRTPCPP

    bash ./get_dependencies.sh
  ''
  + applyPatchesWhenAvailable finalAttrs.passthru.extDeps.pjsip "deps/pjsip"
  + applyPatchesWhenAvailable finalAttrs.passthru.extDeps.zrtpcpp "deps/ZRTPCPP"
  + ''
    # Fails to link some static libs due to missing -lc DSO. Just use the compiler frontend instead of raw ld.
    substituteInPlace deps/pjsip/build/rules.mak \
      --replace-fail '$(LD)' "$CC"

    # Incompatible pointers (not const)
    substituteInPlace deps/pjsip/pjmedia/src/pjmedia-codec/ffmpeg_vid_codecs.c \
      --replace-fail '&payload,' '(const pj_uint8_t **)&payload,'
  '';

  # no upstream tests exist
  doCheck = false;

  pythonImportsCheck = [ "sipsimple" ];

  passthru = {
    updateScript = nix-update-script {
      extraArgs = [
        "--version-regex"
        "^(.*)-mac$"
      ];
    };
    extDeps = {
      pjsip = rec {
        # Hardcoded in get_dependencies.sh, checked at buildtime
        # need tarball specifically for buildscript to detect it
        version = "2.10";
        src = fetchurl {
          url = "https://github.com/pjsip/pjproject/archive/${version}.tar.gz";
          hash = "sha256-k2pMW5hgG1IyVGOjl93xGrQQbGp7BPjcfN03fvu1l94=";
        };
        patches = [
          # Backported https://github.com/pjsip/pjproject/commit/4a8d180529d6ffb0760838b1f8cadc4cb5f7ac03
          ./pjsip-0001-NEON.patch

          # Backported https://github.com/pjsip/pjproject/commit/f56fd48e23982c47f38574a3fd93ebf248ef3762
          ./pjsip-0002-RISC-V.patch

          # Backported https://github.com/pjsip/pjproject/commit/f94b18ef6e0c0b5d34eb274f85ac0a3b2cf9107a
          ./pjsip-0003-LoongArch64.patch
        ];
      };
      zrtpcpp = rec {
        # Hardcoded in get_dependencies.sh, NOT checked at buildtime
        rev = "6b3cd8e6783642292bad0c21e3e5e5ce45ff3e03";
        src = fetchFromGitHub {
          owner = "wernerd";
          repo = "ZRTPCPP";
          inherit rev;
          hash = "sha256-pGng1Y9N51nGBpiZbn2NTx4t2NGg4qkmbghTscJVhIA=";
          postFetch = ''
            # fix build with gcc15
            sed -e '9i #include <cstdint>' -i $out/zrtp/EmojiBase32.cpp
          '';
        };
      };
    };
  };

  meta = {
    description = "SIP SIMPLE SDK written in Python";
    homepage = "https://sipsimpleclient.org/";
    downloadPage = "https://github.com/AGProjects/python3-sipsimple";
    license = lib.licenses.gpl3Plus;
    teams = [ lib.teams.ngi ];
    maintainers = [ lib.maintainers.ethancedwards8 ];
  };
})