aboutsummaryrefslogtreecommitdiff
path: root/pusher/default.nix
diff options
context:
space:
mode:
authorstuebinm2021-02-26 21:25:38 +0100
committerstuebinm2021-02-26 21:27:40 +0100
commitc530245617f9e224b205f6f0efd9fb7f90c0183a (patch)
tree84bace679217d873ec076a1507be0371caf7b638 /pusher/default.nix
parentfe9853c5f4e5b029e88c73ed76ea1aaea107cc55 (diff)
parent210a4860ef16f3f00cd5265d238c2a7372a0daa5 (diff)
Move nix files for workadventure into this repo instead of importing them
Since I change things frequently rn and often only very specific commits of both repositories will work together at all, it doesn't seem logical to have them in separate repos any more.
Diffstat (limited to '')
-rw-r--r--pusher/default.nix84
1 files changed, 84 insertions, 0 deletions
diff --git a/pusher/default.nix b/pusher/default.nix
new file mode 100644
index 0000000..7501504
--- /dev/null
+++ b/pusher/default.nix
@@ -0,0 +1,84 @@
+{ stdenv
+, autoPatchelfHook
+, makeWrapper
+, lib
+, getconf
+
+, fetchzip
+, fetchFromGitHub
+
+, 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 = fetchFromGitHub
+ {
+ owner = "thecodingmachine";
+ repo = "workadventure";
+ rev = "6e9c71598004dc9cbab9418efb3c0ac892da7ca2";
+ sha256 = "0rvra0dy631al4aylacyqldkyd6biawz2shsikgcy30nv5lzc78c";
+ } + "/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"
+ '';
+}