aboutsummaryrefslogtreecommitdiff
path: root/pusher/default.nix
blob: cb6ee0d0dbe5f96bd89843a89ed2eee7d0c65e4a (plain)
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
workadventuresrc:

{ stdenv
, autoPatchelfHook
, makeWrapper
, lib
, getconf
, fetchzip
, nodejs-14_x
, yarn2nix-moretea
, workadventure
}:

let
  node-abi = "83";

  node-grpc-precompiled = fetchzip {
    name = "node-grpc-precompiled-node-${node-abi}";
    url = "https://node-precompiled-binaries.grpc.io/grpc/v1.24.4/node-v${node-abi}-linux-x64-glibc.tar.gz";
    sha256 = "119rhhk1jpi2vwyim7byq3agacasc4q25c26wyzfmy8vk2ih6ndj";
  };

  node-grpc-patched = stdenv.mkDerivation {
    name = "node-grpc";
    buildInputs = [ stdenv.cc.cc ];
    nativeBuildInputs = [ autoPatchelfHook ];
    dontUnpack = true;
    # spams console
    dontStrip = true;
    installPhase = ''
      install -D -m755 ${node-grpc-precompiled}/grpc_node.node $out/bin/grpc_node.node
    '';
  };

in
yarn2nix-moretea.mkYarnPackage rec {
  pname = "workadventurepusher";
  version = "unstable";

  src = "${workadventuresrc}/pusher";

  # NOTE: this is optional and generated dynamically if omitted
  yarnNix = ./yarn.nix;

  nativeBuildInputs = [ makeWrapper ];

  pkgConfig = {
    grpc = {
      postInstall = ''
        install -D -m755 ${node-grpc-patched}/bin/grpc_node.node src/node/extension_binary/node-v${node-abi}-linux-x64-glibc/grpc_node.node
      '';
    };
  };

  dontStrip = true;

  # workadventureback below is a package name extracted from package.json,
  # intended until upstream fixes that up.
  buildPhase = ''
    mkdir -p $out
    ln -s ${workadventure.messages.outPath}/generated deps/workadventureback/src/Messages/generated
    HOME=$TMPDIR yarn --offline run tsc
    cp -r deps/workadventureback/dist $out/dist
    rm -rf deps/workadventureback/{src,node_modules}
  '';

  postInstall = ''
    # node-abi needs to the abi of the node here
    # getconf is required for detect-libc (used by node-pre-gyp) to properly
    # detect current libc
    makeWrapper '${nodejs-14_x}/bin/node' "$out/bin/${pname}" \
      --set NODE_PATH $out/libexec/workadventureback/node_modules \
      --prefix PATH : ${lib.makeBinPath [ getconf ]} \
      --add-flags "$out/dist/server.js"
  '';
}