Skip to content

Commit 5ab11bb

Browse files
committed
signal-desktop-source: build sqlcipher with extension from source
1 parent bc0f86a commit 5ab11bb

File tree

3 files changed

+152
-9
lines changed

3 files changed

+152
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
electron_33,
77
python3,
88
makeWrapper,
9+
callPackage,
910
libpulseaudio,
1011
fetchFromGitHub,
1112
runCommand,
12-
fetchurl,
1313
fetchzip,
1414
autoPatchelfHook,
1515
makeDesktopItem,
@@ -28,11 +28,7 @@ let
2828
tar -C $out --strip-components=1 -xvf ${electron.headers}
2929
'';
3030

31-
sqlcipher = fetchurl {
32-
# https://github.com/signalapp/Signal-Sqlcipher-Extension
33-
url = "https://build-artifacts.signal.org/desktop/sqlcipher-v2-4.6.1-signal-patch2--0.2.1-asm2-6253f886c40e49bf892d5cdc92b2eb200b12cd8d80c48ce5b05967cfd01ee8c7.tar.gz";
34-
hash = "sha256-YlP4hsQOSb+JLVzckrLrIAsSzY2AxIzlsFlnz9Ae6Mc=";
35-
};
31+
sqlcipher-signal-extension = callPackage ./sqlcipher-signal-extension.nix { };
3632

3733
ringrtc = stdenv.mkDerivation (finalAttrs: {
3834
pname = "ringrtc-bin";
@@ -123,8 +119,7 @@ stdenv.mkDerivation (finalAttrs: {
123119
};
124120

125121
preBuild = ''
126-
substituteInPlace node_modules/@signalapp/better-sqlite3/deps/download.js \
127-
--replace-fail "path.join(__dirname, 'sqlcipher.tar.gz')" "'${sqlcipher}'"
122+
cp ${sqlcipher-signal-extension}/share/sqlite3.gyp node_modules/@signalapp/better-sqlite3/deps/sqlite3.gyp
128123
129124
cp -r ${ringrtc} node_modules/@signalapp/ringrtc/build
130125
'';
@@ -187,6 +182,10 @@ stdenv.mkDerivation (finalAttrs: {
187182
})
188183
];
189184

185+
passthru = {
186+
inherit sqlcipher-signal-extension;
187+
};
188+
190189
meta = {
191190
description = "Private, simple, and secure messenger (nixpkgs build)";
192191
longDescription = ''
@@ -215,7 +214,6 @@ stdenv.mkDerivation (finalAttrs: {
215214
sourceProvenance = with lib.sourceTypes; [
216215
fromSource
217216

218-
# sqlcipher
219217
# ringrtc
220218
# node_modules/@signalapp/libsignal-client/prebuilds/
221219
binaryNativeCode
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
rustPlatform,
3+
lib,
4+
fetchFromGitHub,
5+
sqlcipher,
6+
fetchpatch,
7+
stdenv,
8+
openssl,
9+
tcl,
10+
buildEnv,
11+
rust-cbindgen,
12+
}:
13+
let
14+
signal-sqlcipher-extension = rustPlatform.buildRustPackage (finalAttrs: {
15+
pname = "signal-sqlcipher-extension";
16+
version = "0.2.1";
17+
18+
src = fetchFromGitHub {
19+
owner = "signalapp";
20+
repo = "Signal-Sqlcipher-Extension";
21+
tag = "v${finalAttrs.version}";
22+
hash = "sha256-INSkm7ZuetPASuIqezzzG/bXoEHClUb9XpxWbxLVXRc=";
23+
};
24+
useFetchCargoVendor = true;
25+
cargoHash = "sha256-qT4HM/FRL8qugKKNlMYM/0zgUsC6cDOa9fgd1d4VIrc=";
26+
27+
meta = {
28+
description = "SQLite extension used by Signal Desktop";
29+
homepage = "https://github.com/signalapp/Signal-Sqlcipher-Extension";
30+
license = lib.licenses.agpl3Only;
31+
maintainers = with lib.maintainers; [ marcin-serwin ];
32+
platforms = lib.platforms.all;
33+
};
34+
});
35+
36+
sqlcipher-amalgamation = stdenv.mkDerivation {
37+
pname = "sqlcipher-with-signal-extension";
38+
39+
inherit (sqlcipher) version src meta;
40+
41+
patches = [
42+
(fetchpatch {
43+
# https://github.com/sqlcipher/sqlcipher/pull/529
44+
name = "custom-crypto-provider.patch";
45+
url = "https://github.com/sqlcipher/sqlcipher/commit/0e3b20c155df8a2943b62a9f3cc0f4d3dba9e152.patch";
46+
hash = "sha256-OKh6qCGHBQWZyzXfyEveAs71wrNwlWLuG9jNqDeKNG4=";
47+
})
48+
];
49+
50+
nativeBuildInputs = [ tcl ];
51+
52+
buildInputs = [ openssl ];
53+
54+
CFLAGS = [ "-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1" ];
55+
56+
makeFlags = [ "sqlite3.c" ];
57+
58+
installPhase = ''
59+
install -Dm644 sqlite3.c $out/src/sqlite3.c
60+
install -Dm644 sqlite3.h $out/include/sqlite3.h
61+
install -Dm644 sqlite3ext.h $out/include/sqlite3ext.h
62+
'';
63+
};
64+
65+
signal-tokenizer-headers = rustPlatform.buildRustPackage (finalAttrs: {
66+
pname = "Signal-FTS5-Extension";
67+
version = "0.2.1";
68+
69+
src = fetchFromGitHub {
70+
owner = "signalapp";
71+
repo = "Signal-FTS5-Extension";
72+
tag = "v${finalAttrs.version}";
73+
hash = "sha256-MzgdRuRsfL3yhlVU0RAAUtAaOukMpqSSa42nRYhpmh0=";
74+
};
75+
useFetchCargoVendor = true;
76+
cargoHash = "sha256-0DDX3ciXk5/3MqsHzxV8s4qEhqYmrwGg7cSbrkFRZbw=";
77+
78+
nativeBuildInputs = [ rust-cbindgen ];
79+
80+
buildPhase = ''
81+
cbindgen --profile release . -o signal-tokenizer.h
82+
'';
83+
installPhase = ''
84+
install -Dm644 signal-tokenizer.h $out/include/signal-tokenizer.h
85+
'';
86+
doCheck = false;
87+
});
88+
89+
in
90+
buildEnv {
91+
name = "sqlcipher-signal";
92+
93+
paths = [
94+
sqlcipher-amalgamation
95+
signal-tokenizer-headers
96+
signal-sqlcipher-extension
97+
];
98+
99+
postBuild = ''
100+
install -Dm644 ${./sqlite3.gyp} $out/share/sqlite3.gyp
101+
substituteInPlace $out/share/sqlite3.gyp \
102+
--replace-fail "@extension@" "$out" \
103+
--replace-fail "@static_lib_ext@" "${stdenv.hostPlatform.extensions.staticLibrary}"
104+
'';
105+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
'includes': ['common.gypi'],
3+
'targets': [
4+
{
5+
'target_name': 'locate_sqlite3',
6+
'type': 'none',
7+
'copies': [{
8+
'files': [
9+
'@extension@/src/sqlite3.c',
10+
],
11+
'destination': '<(SHARED_INTERMEDIATE_DIR)/sqlite3',
12+
}],
13+
},
14+
{
15+
'target_name': 'sqlite3',
16+
'type': 'static_library',
17+
'dependencies': ['locate_sqlite3'],
18+
'sources': ['<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.c'],
19+
'include_dirs': [
20+
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/',
21+
],
22+
'direct_dependent_settings': {
23+
'include_dirs': [
24+
'@extension@/include',
25+
],
26+
},
27+
'cflags': ['-std=c99', '-w'],
28+
'xcode_settings': {
29+
'OTHER_CFLAGS': ['-std=c99'],
30+
'WARNING_CFLAGS': ['-w'],
31+
},
32+
'includes': ['defines.gypi'],
33+
'link_settings': {
34+
'libraries': [
35+
'@extension@/lib/libsignal_sqlcipher_extension@static_lib_ext@',
36+
]
37+
}
38+
},
39+
],
40+
}

0 commit comments

Comments
 (0)