Can't get vips as a dependency in node

I’m trying to do this:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  };

  outputs = {nixpkgs, ...}: let
    genSystems = nixpkgs.lib.genAttrs ["aarch64-darwin"];
    pkgsFor = nixpkgs.legacyPackages;
  in {
    devShells = genSystems (system: {
      default = pkgsFor.${system}.mkShell {
        packages = with pkgsFor.${system}; [
          nodejs_18
          python39
          vips
          yarn
        ];
      };
    });
  };
}

On yarn install I get:

gyp info using node-gyp@5.0.7
gyp info using node@18.17.1 | darwin | arm64
gyp info find Python using Python version 3.9.18 found at "/nix/store/1gp87virgabwfxdmr9ckh7lbhylfl4sc-python3-3.9.18/bin/python"
(node:28697) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
(Use `node --trace-deprecation ...` to show where the warning was created)
gyp info spawn /nix/store/1gp87virgabwfxdmr9ckh7lbhylfl4sc-python3-3.9.18/bin/python
gyp info spawn args [
gyp info spawn args   '/Users/alper/Code/choco-js/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/alper/Code/choco-js/applications/imageProcessor/node_modules/sharp/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/alper/Code/choco-js/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/alper/Library/Caches/node-gyp/18.17.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/alper/Library/Caches/node-gyp/18.17.1',
gyp info spawn args   '-Dnode_gyp_dir=/Users/alper/Code/choco-js/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/alper/Library/Caches/node-gyp/18.17.1/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/alper/Code/choco-js/applications/imageProcessor/node_modules/sharp',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/Users/alper/Code/choco-js/applications/imageProcessor/node_modules/sharp/build'
  CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
  LIBTOOL-STATIC Release/nothing.a
warning: /Library/Developer/CommandLineTools/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols)
  TOUCH Release/obj.target/libvips-cpp.stamp
  CXX(target) Release/obj.target/sharp/src/common.o
In file included from ../src/common.cc:24:
/nix/store/3n38d2i67lqcqswk2a0czrx3qhf0abhq-vips-8.14.4-dev/include/vips/vips8:35:10: fatal error: 'glib-object.h' file not found
#include <glib-object.h>
         ^~~~~~~~~~~~~~~

Adding glibc does not work on my architecture so no clue how this is supposed to go.

Ruby people seem to use a package, but no such thing for node is there: Can't get ruby-vips to work in nix-shell on macOs

glib-object.h comes from GLib not glibc. But it should already have been propagated by the Nix vips package so it sounds like the package you are building is looking for it improperly. Ideally, it would use pkg-config to discover the proper flags to pass the compiler but then I would expect an error about not being able to find pkg-config. But you can still try to add it to nativeBuildInputs.

Edit: Looks like it does indeed use pkg-config: https://github.com/lovell/sharp/blob/9c217ab580123ee14ad65d5043d74d8ea7c245e5/binding.gyp#L108

Yeah, I think the node-gyp is fully broken (as it always is).

I tried using yarn2nix and having all the packages in package.json be installed by Nix but that couldn’t deal with a private NPM repository. There does not seem to be a pnpm2nix that’s maintained and I can’t figure out anything about dream2nix.

Anyway, I think this is an optional dependency and can be ignored.

Does adding pkg-config to nativeBuildInputs not work then?