summary refs log tree commit diff
path: root/pkgs/applications/networking/instant-messengers/rambox/fetchNodeModules.nix
blob: 047890a932ca00d7566bbdc2212434c325c3c79b (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
{ stdenv, jq }: { src, nodejs, sha256 }:

# Only npm >= 5.4.2 is deterministic, see:
# https://github.com/npm/npm/issues/17979#issuecomment-332701215
assert stdenv.lib.versionAtLeast nodejs.version "8.9.0";

stdenv.mkDerivation {
  name = "node_modules";

  outputHashAlgo = "sha256";
  outputHash = sha256;
  outputHashMode = "recursive";

  nativeBuildInputs = [ jq nodejs ];

  buildCommand = ''
    cp -r ${src}/* .
    HOME=. npm install --force --ignore-scripts --only=production
    for f in $(find node_modules -name package.json); do
      # https://github.com/npm/npm/issues/10393
      jq -S 'delpaths(keys | map(select(startswith("_")) | [.]))' $f > $f.tmp
      mv $f.tmp $f
    done
    mv node_modules $out
  '';
}