|
| 1 | +{ |
| 2 | + stdenv, |
| 3 | + rustPlatform, |
| 4 | + fetchNpmDeps, |
| 5 | + npmHooks, |
| 6 | + protobuf, |
| 7 | + clang, |
| 8 | + gitMinimal, |
| 9 | + cmake, |
| 10 | + boringssl, |
| 11 | + runCommand, |
| 12 | + fetchFromGitHub, |
| 13 | + python3, |
| 14 | + nodejs, |
| 15 | + |
| 16 | +}: |
| 17 | +let |
| 18 | + # boring-sys expects the static libraries in build/ instead of lib/ |
| 19 | + boringssl-wrapper = runCommand "boringssl-wrapper" { } '' |
| 20 | + mkdir $out |
| 21 | + cd $out |
| 22 | + ln -s ${boringssl.out}/lib build |
| 23 | + ln -s ${boringssl.dev}/include include |
| 24 | + ''; |
| 25 | +in |
| 26 | +rustPlatform.buildRustPackage (finalAttrs: { |
| 27 | + pname = "libsignal-node"; |
| 28 | + version = "0.67.0"; |
| 29 | + |
| 30 | + src = fetchFromGitHub { |
| 31 | + owner = "signalapp"; |
| 32 | + repo = "libsignal"; |
| 33 | + tag = "v${finalAttrs.version}"; |
| 34 | + hash = "sha256-Cwra5o9g2+M3dboQUuBikRWyaydL/CGwOfJbImsFRoI="; |
| 35 | + }; |
| 36 | + useFetchCargoVendor = true; |
| 37 | + cargoHash = "sha256-KVt4ESHaHDtD+pcaMMG/DMMznYGpWleEf7uTZB45Ud0="; |
| 38 | + |
| 39 | + npmRoot = "node"; |
| 40 | + npmDeps = fetchNpmDeps { |
| 41 | + name = "${finalAttrs.pname}-npm-deps"; |
| 42 | + inherit (finalAttrs) version src; |
| 43 | + sourceRoot = "${finalAttrs.src.name}/${finalAttrs.npmRoot}"; |
| 44 | + hash = "sha256-TXRZFfdl86PLJ1FWOkTcXjbx8aZV7gEvs22Pu8b5uFU="; |
| 45 | + }; |
| 46 | + |
| 47 | + nativeBuildInputs = [ |
| 48 | + python3 |
| 49 | + protobuf |
| 50 | + nodejs |
| 51 | + clang |
| 52 | + gitMinimal |
| 53 | + cmake |
| 54 | + npmHooks.npmConfigHook |
| 55 | + rustPlatform.bindgenHook |
| 56 | + ]; |
| 57 | + env.BORING_BSSL_PATH = "${boringssl-wrapper}"; |
| 58 | + env.NIX_LDFLAGS = if stdenv.hostPlatform.isDarwin then "-lc++" else "-lstdc++"; |
| 59 | + |
| 60 | + patchPhase = '' |
| 61 | + runHook prePatch |
| 62 | +
|
| 63 | + substituteInPlace node/binding.gyp \ |
| 64 | + --replace-fail "'--out-dir', '<(PRODUCT_DIR)/'," \ |
| 65 | + "'--out-dir', '$out/lib/<(NODE_OS_NAME)-<(target_arch)/'," \ |
| 66 | + --replace-fail "'target_name': 'libsignal_client_<(NODE_OS_NAME)_<(target_arch).node'," \ |
| 67 | + "'target_name': '@signalapp+libsignal-client'," |
| 68 | +
|
| 69 | + substituteInPlace node/build_node_bridge.py \ |
| 70 | + --replace-fail "dst_base = 'libsignal_client_%s_%s' % (node_os_name, node_arch)" \ |
| 71 | + "dst_base = '@signalapp+libsignal-client'" |
| 72 | +
|
| 73 | + runHook postPatch |
| 74 | + ''; |
| 75 | + |
| 76 | + buildPhase = '' |
| 77 | + runHook preBuild |
| 78 | +
|
| 79 | + pushd node |
| 80 | + npx node-gyp rebuild |
| 81 | + popd |
| 82 | +
|
| 83 | + runHook postBuild |
| 84 | + ''; |
| 85 | + |
| 86 | + dontCargoInstall = true; |
| 87 | +}) |
0 commit comments