about summary refs log tree commit diff
path: root/nixpkgs/pkgs/servers/matrix-synapse/matrix-hookshot/default.nix
blob: e89e4e1e682b4a9980f4674e6fc87da829ae5254 (plain) (blame)
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
{ lib
, stdenv
, fetchFromGitHub
, fetchYarnDeps
, makeWrapper
, matrix-sdk-crypto-nodejs
, mkYarnPackage
, cargo
, rustPlatform
, rustc
, napi-rs-cli
, pkg-config
, nodejs
, openssl
}:

let
  data = lib.importJSON ./pin.json;
in
mkYarnPackage rec {
  pname = "matrix-hookshot";
  version = data.version;

  src = fetchFromGitHub {
    owner = "matrix-org";
    repo = "matrix-hookshot";
    rev = data.version;
    hash = data.srcHash;
  };

  packageJSON = ./package.json;

  offlineCache = fetchYarnDeps {
    yarnLock = src + "/yarn.lock";
    sha256 = data.yarnHash;
  };

  cargoDeps = rustPlatform.fetchCargoTarball {
    inherit src;
    name = "${pname}-${version}";
    hash = data.cargoHash;
  };

  packageResolutions = {
    "@matrix-org/matrix-sdk-crypto-nodejs" = "${matrix-sdk-crypto-nodejs}/lib/node_modules/@matrix-org/matrix-sdk-crypto-nodejs";
  };

  extraBuildInputs = [ openssl ];

  nativeBuildInputs = [
    rustPlatform.cargoSetupHook
    pkg-config
    cargo
    rustc
    napi-rs-cli
    makeWrapper
  ];

  buildPhase = ''
    runHook preBuild
    cd deps/${pname}
    napi build --target ${stdenv.hostPlatform.rust.rustcTargetSpec} --dts ../src/libRs.d.ts --release ./lib
    yarn run build:app:fix-defs
    yarn run build:app
    yarn run build:web
    cd ../..
    runHook postBuild
  '';

  postInstall = ''
    makeWrapper '${nodejs}/bin/node' "$out/bin/matrix-hookshot" --add-flags \
        "$out/libexec/matrix-hookshot/deps/matrix-hookshot/lib/App/BridgeApp.js"
  '';

  postFixup = ''
    # Scrub reference to rustc
    rm $out/libexec/matrix-hookshot/deps/matrix-hookshot/target/.rustc_info.json
  '';

  doDist = false;

  meta = with lib; {
    description = "A bridge between Matrix and multiple project management services, such as GitHub, GitLab and JIRA";
    mainProgram = "matrix-hookshot";
    maintainers = with maintainers; [ chvp ];
    license = licenses.asl20;
    platforms = platforms.linux;
  };
}