Need help building (possibly complex) nodejs package

Overleaf is an online service for LaTeX typesettings which you can host yourself and I want to package this for Nix. The software is made from multiple modules and I started with the web module:

$ git clone --depth 1 https://github.com/overleaf/web
$ cd web

The project is written in nodejs, so I used node2nix to generate the derivation:

$ node2nix --nodejs-10 -l package-lock.json --supplement-input <(echo '[ "node-gyp-build" ]')

The project requires nodejs version 10 and at least the web module requires compiling native code for which I need node-gyp-build. To build it I again have to specify nodejs 10 explicitly because nixpkgs unstable defaults to nodejs 12 which the native code doesn’t compile on. However, the build fails with an obscure ENOTCACHED error:

$ nix-build -E 'with import <nixpkgs> { }; callPackage ./default.nix { nodejs = pkgs."nodejs-10_x"; }'
[...]
npm ERR! code ENOTCACHED5minstall loadAllDepsIntoIdealTree[KK
npm ERR! request to https://registry.npmjs.org/safe-buffer failed: cache mode is 'only-if-cached' but no cached response available.

npm ERR! A complete log of this run can be found in:
npm ERR!     /build/.npm/_logs/2020-07-06T06_54_40_784Z-debug.log

builder for '/nix/store/i3hd7w7q89i7yq8fm159djvndr9svb01-node-dependencies-web-overleaf-0.1.4.drv' failed with exit code 1
cannot build derivation '/nix/store/h2m80p846l3vc3h9kx35jqcb41qcdnvy-node-shell-web-overleaf-0.1.4.drv': 1 dependencies couldn't be built
error: build of '/nix/store/h2m80p846l3vc3h9kx35jqcb41qcdnvy-node-shell-web-overleaf-0.1.4.drv', '/nix/store/sxqnf6a25sjmljg2cy2lijbik6j1xal7-node_web-overleaf-0.1.4.drv' failed

I’m not a nodejs programmer so I don’t actually know how to build these things outside of Nix and have no clue how to work around this problem. There are a couple of issues tagged with ENOTCACHED on the node2nix repo but none of them seems to apply to my situation. Before opening an issue over there and wasting the dev’s time with my incompetence I wanted to ask here whether there is something obvious that I’m doing wrong.

3 Likes