1{ version, hash, outputHashes, cargoLock, patches }:
2
3{ lib, stdenv, fetchFromGitHub
4, cargo, rustPlatform, rustc, napi-rs-cli, nodejs, libiconv
5}:
6
7stdenv.mkDerivation rec {
8 pname = "matrix-sdk-crypto-nodejs";
9 inherit version patches;
10
11 src = fetchFromGitHub {
12 owner = "matrix-org";
13 repo = "matrix-rust-sdk";
14 rev = "${pname}-v${version}";
15 inherit hash;
16 };
17
18
19 cargoDeps = rustPlatform.importCargoLock {
20 lockFile = cargoLock;
21 inherit outputHashes;
22 };
23
24 nativeBuildInputs = [
25 rustPlatform.cargoSetupHook
26 cargo
27 rustc
28 napi-rs-cli
29 nodejs
30 ];
31
32 buildInputs = lib.optionals stdenv.isDarwin [ libiconv ];
33
34 buildPhase = ''
35 runHook preBuild
36
37 cd bindings/${pname}
38 npm run release-build --offline
39
40 runHook postBuild
41 '';
42
43 installPhase = ''
44 runHook preInstall
45
46 local -r outPath="$out/lib/node_modules/@matrix-org/${pname}"
47 mkdir -p "$outPath"
48 cp package.json index.js index.d.ts matrix-sdk-crypto.*.node "$outPath"
49
50 runHook postInstall
51 '';
52
53 meta = with lib; {
54 description = "A no-network-IO implementation of a state machine that handles E2EE for Matrix clients";
55 homepage = "https://github.com/matrix-org/matrix-rust-sdk/tree/${src.rev}/bindings/matrix-sdk-crypto-nodejs";
56 license = licenses.asl20;
57 maintainers = with maintainers; [ winter ];
58 inherit (nodejs.meta) platforms;
59 };
60}