1{ lib, stdenv, jq }: { src, nodejs, sha256 }:
2
3# Only npm >= 5.4.2 is deterministic, see:
4# https://github.com/npm/npm/issues/17979#issuecomment-332701215
5assert lib.versionAtLeast nodejs.version "8.9.0";
6
7stdenv.mkDerivation {
8 name = "node_modules";
9
10 outputHashAlgo = "sha256";
11 outputHash = sha256;
12 outputHashMode = "recursive";
13
14 nativeBuildInputs = [ jq nodejs ];
15
16 buildCommand = ''
17 cp -r ${src}/* .
18 HOME=. npm install --force --ignore-scripts --only=production
19 for f in $(find node_modules -name package.json); do
20 # https://github.com/npm/npm/issues/10393
21 jq -S 'delpaths(keys | map(select(startswith("_")) | [.]))' $f > $f.tmp
22 mv $f.tmp $f
23 done
24 mv node_modules $out
25 '';
26}