Building an impure npm package

Hi!
I’m trying to build Directus, whiched seemed very simple to package as it only has npm dependencies.

However, there is an impure npm package that tries to download a precompiled binary of libvips during its installation: sharp-0.31.2.
I saw in its source it can use a local version if found somewhere.

Also sharp seems packaged in nixpkgs, although it’s an anterior version, so it may be possible to correctly package it.

How is it possible to override a specific npm dependency?
Or how can I put the precompiled binary somewhere before sharp install runs, so it will be “locally found”?

Any help much appreciated!

Files:
package.json:

{
  "name": "directus",
  "version": "1.0.0",
  "description": "",
  "scripts": {},
  "keywords": [],
  "author": "ppom",
  "license": "GPL-3",
  "dependencies": {
    "@directus/sdk": "^10.3.0",
    "directus": "^9.21.2",
    "sqlite3": "^5.1.2"
  }
}

default.nix:

{ lib, buildNpmPackage, linkFarm, fetchurl }:

buildNpmPackage {
  pname = "directus";
  version = "9.21.2";

  src = linkFarm "directus-source" [
    { name = "package.json"; path = ./package.json; }
    { name = "package-lock.json"; path = ./package-lock.json; }
  ];

  npmDepsHash = "sha256-4qIbxMxX6AaYWJTfqWrl4geaLBCsED5vOeDsUFAa5Fw=";
  npmFlags = [ "-loglevel silent" ];
  makeCacheWritable = true;

  meta = with lib; {
    description = "The Modern Data Stack rabbit — Directus is an instant REST+GraphQL API and intuitive no-code data collaboration app for any SQL database";
    homepage = "https://directus.io";
    license = licenses.gpl3Only;
    maintainers = with maintainers; [ ppom ];
  };
}

package-lock.json was generated from a manual npm i.

I solved this issue by providing nixpkgs’s version of the librairy, following the doc.

Here’s the new default.nix:

{ lib, buildNpmPackage, linkFarm, vips, pkg-config, python3, jq }:

buildNpmPackage {
  pname = "directus";
  version = "9.21.2";

  src = linkFarm "directus-source" [
    { name = "package.json"; path = ./package.json; }
    { name = "package-lock.json"; path = ./package-lock.json; }
  ];

  # Required for sharp dependency
  nativeBuildInputs = [
    python3
    pkg-config
    vips
  ];

  buildInputs = [
    vips
  ];

  # Workaround buildNpmPackage.installHook assuming this directory exists
  # https://github.com/NixOS/nixpkgs/blob/716cab14032dde128e5ef08c3ba31066d7802e51/pkgs/build-support/node/build-npm-package/hooks/npm-install-hook.sh#L27
  preInstall = ''
    mkdir -p $out/lib/node_modules/$(${jq}/bin/jq --raw-output '.name' package.json)
  '';

  postInstall = ''
    mkdir $out/bin
    ln -s $out/lib/node_modules/directus/node_modules/.bin/directus $out/bin/directus 
  '';

  npmDepsHash = "sha256-4qIbxMxX6AaYWJTfqWrl4geaLBCsED5vOeDsUFAa5Fw=";

  dontNpmBuild = true;

  meta = with lib; {
    description = "The Modern Data Stack rabbit — Directus is an instant REST+GraphQL API and intuitive no-code data collaboration app for any SQL database";
    homepage = "https://directus.io";
    license = licenses.gpl3Only;
    maintainers = with maintainers; [ ppom ];
  };
}