Skip to content

Commit 57c8cea

Browse files
committed
signal-desktop-source: build libsignal from source
1 parent d9141ad commit 57c8cea

File tree

2 files changed

+93
-2
lines changed

2 files changed

+93
-2
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
})

pkgs/by-name/si/signal-desktop-source/package.nix

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ let
2929
'';
3030

3131
sqlcipher-signal-extension = callPackage ./sqlcipher-signal-extension.nix { };
32+
libsignal-node = callPackage ./libsignal-node.nix { inherit nodejs; };
3233

3334
ringrtc = stdenv.mkDerivation (finalAttrs: {
3435
pname = "ringrtc-bin";
@@ -71,6 +72,7 @@ let
7172
runHook postInstall
7273
'';
7374
});
75+
7476
in
7577
stdenv.mkDerivation (finalAttrs: {
7678
pname = "signal-desktop-source";
@@ -122,6 +124,9 @@ stdenv.mkDerivation (finalAttrs: {
122124
cp ${sqlcipher-signal-extension}/share/sqlite3.gyp node_modules/@signalapp/better-sqlite3/deps/sqlite3.gyp
123125
124126
cp -r ${ringrtc} node_modules/@signalapp/ringrtc/build
127+
128+
rm -fr node_modules/@signalapp/libsignal-client/prebuilds
129+
cp -r ${libsignal-node}/lib node_modules/@signalapp/libsignal-client/prebuilds
125130
'';
126131

127132
buildPhase = ''
@@ -183,7 +188,7 @@ stdenv.mkDerivation (finalAttrs: {
183188
];
184189

185190
passthru = {
186-
inherit sqlcipher-signal-extension;
191+
inherit sqlcipher-signal-extension libsignal-node;
187192
};
188193

189194
meta = {
@@ -215,7 +220,6 @@ stdenv.mkDerivation (finalAttrs: {
215220
fromSource
216221

217222
# ringrtc
218-
# node_modules/@signalapp/libsignal-client/prebuilds/
219223
binaryNativeCode
220224
];
221225
};

0 commit comments

Comments
 (0)