Node-gyp fails trying to build an npm package with pkgs.buildNpmPackage

Hello,

I’m trying to package prantlf/jsonlint (especially this fork) for nix using pkgs.buildNpmPackage. This is my recipe:

      prantlf-jsonlint =
        let
          lockfile = ./../../packages/prantlf-jsonlint/package-lock.json;
        in
        pkgs.buildNpmPackage rec {
          pname = "jsonlint";
          version = "16.0.0";

          src = pkgs.fetchFromGitHub {
            owner = "prantlf";
            repo = pname;
            rev = "v${version}";
            hash = "sha256-pXTw9U8E/Xocy4+M9P3hQjZxvUq/iAHhxwnrJA3hLK0=";
          };
          #npmFlags = ["--loglevel=verbose"];
          npmPackFlags = [ "--ignore-scripts" ];
          dontNpmBuild = true;

          buildPhase = "";

          nodejs = pkgs.nodejs_24;

          postPatch = ''
            cp ${lockfile} package-lock.json
          '';

          npmDepsHash = "sha256-rDs4OpSH+qmHQM3kPsuFmCO7o/wgCMe10Ufd7LUMVso=";

          # The prepack script runs the build script, which we'd rather do in the build phase.

          meta = with lib; {
            description = "JSON/CJSON/JSON5 parser, syntax & schema validator and pretty-printer with a command-line client, written in pure JavaScript. ";
            homepage = "https://prantlf.github.io/jsonlint/";
            license = licenses.mit;
          };
        };

I obtained the package-lock.json by

  1. cloning the repo
  2. git checkout v16.0.0
  3. npm i --package-lock-only
  4. copy package-lock.json to appropriate folder

I’m getting this error:

Running phase: unpackPhase
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking source archive /nix/store/4farmd3qxsl3v4gd4pzp0nn59m04cdgn-source
source root is source
Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
Executing npmConfigHook
Configuring npm
Validating consistency between /build/source/package-lock.json and /nix/store/y61n00g3dhq9x87n5zi35jb7607lf0ch-js>Setting npm_config_cache to /nix/store/y61n00g3dhq9x87n5zi35jb7607lf0ch-jsonlint-16.0.0-npm-deps
Installing dependencies
npm warn Unknown env config "nodedir". This will stop working in the next major version of npm.
npm warn Unknown env config "platform". This will stop working in the next major version of npm.
npm warn Unknown env config "arch". This will stop working in the next major version of npm.

added 265 packages, and audited 266 packages in 3s

49 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
patching script interpreter paths in node_modules
node_modules/@biomejs/biome/bin/biome: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2b>node_modules/@unixcompat/cat.js/bin/cat.mjs: interpreter directive changed from "#!/usr/bin/env node" to "/nix/st>node_modules/@unixcompat/mv.js/bin/mv.mjs: interpreter directive changed from "#!/usr/bin/env node" to "/nix/stor>node_modules/c8/bin/c8.js: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4yn1ccasnw6>node_modules/esbuild/bin/esbuild: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4yn1>node_modules/glob/dist/esm/bin.mjs: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4y>node_modules/he/bin/he: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4yn1ccasnw6csc>node_modules/http-server/bin/http-server: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store>node_modules/js-yaml/bin/js-yaml.js: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4>node_modules/mime/cli.js: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4yn1ccasnw6c>node_modules/mime/src/build.js: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4yn1cc>node_modules/opener/bin/opener-bin.js: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2b>node_modules/resolve/bin/resolve: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4yn1>node_modules/semver/bin/semver.js: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4yn>node_modules/tehanu-teru/lib/index.cjs: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2>node_modules/tehanu-teru/lib/index.mjs: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2>node_modules/typescript/bin/tsc: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4yn1c>node_modules/typescript/bin/tsserver: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg>node_modules/url-join/bin/changelog: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4>node_modules/which/bin/node-which: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4yn>node_modules/rollup/dist/bin/rollup: interpreter directive changed from "#!/usr/bin/env node" to "/nix/store/2bg4>npm warn Unknown env config "nodedir". This will stop working in the next major version of npm.
npm warn Unknown env config "platform". This will stop working in the next major version of npm.
npm warn Unknown env config "arch". This will stop working in the next major version of npm.
npm error code 1
npm error path /build/source/node_modules/os-lock
npm error command failed
npm error command sh -c node-gyp rebuild
npm error make: Entering directory '/build/source/node_modules/os-lock/build'
npm error   CC(target) Release/obj.target/addon/lock.o
npm error   CC(target) Release/obj.target/addon/addon.o
npm error make: Leaving directory '/build/source/node_modules/os-lock/build'
npm error gyp info it worked if it ends with ok
npm error gyp info using node-gyp@11.2.0
npm error gyp info using node@24.4.1 | linux | x64
npm error gyp info find Python using Python version 3.13.5 found at "/nix/store/djck7mx6jad1w0yy6zings96dyxanls6->npm error gyp WARN read config.gypi ENOENT: no such file or directory, open '/nix/store/m42x79zlw68sjx4fdg90ahacd>npm error gyp info spawn /nix/store/djck7mx6jad1w0yy6zings96dyxanls6-python3-3.13.5/bin/python3
npm error gyp info spawn args [
npm error gyp info spawn args '/nix/store/2bg4yn1ccasnw6cscqhgqwzfw8j2xq1m-nodejs-24.4.1/lib/node_modules/npm/nod>npm error gyp info spawn args 'binding.gyp',
npm error gyp info spawn args '-f',
npm error gyp info spawn args 'make',
npm error gyp info spawn args '-I',
npm error gyp info spawn args '/build/source/node_modules/os-lock/build/config.gypi',
npm error gyp info spawn args '-I',
npm error gyp info spawn args '/nix/store/2bg4yn1ccasnw6cscqhgqwzfw8j2xq1m-nodejs-24.4.1/lib/node_modules/npm/nod>npm error gyp info spawn args '-I',
npm error gyp info spawn args '/nix/store/m42x79zlw68sjx4fdg90ahacdrnqwxby-nodejs-24.4.1-source/common.gypi',
npm error gyp info spawn args '-Dlibrary=shared_library',
npm error gyp info spawn args '-Dvisibility=default',
npm error gyp info spawn args '-Dnode_root_dir=/nix/store/m42x79zlw68sjx4fdg90ahacdrnqwxby-nodejs-24.4.1-source',
npm error gyp info spawn args '-Dnode_gyp_dir=/nix/store/2bg4yn1ccasnw6cscqhgqwzfw8j2xq1m-nodejs-24.4.1/lib/node_>npm error gyp info spawn args '-Dnode_lib_file=/nix/store/m42x79zlw68sjx4fdg90ahacdrnqwxby-nodejs-24.4.1-source/$>npm error gyp info spawn args '-Dmodule_root_dir=/build/source/node_modules/os-lock',
npm error gyp info spawn args '-Dnode_engine=v8',
npm error gyp info spawn args '--depth=.',
npm error gyp info spawn args '--no-parallel',
npm error gyp info spawn args '--generator-output',
npm error gyp info spawn args 'build',
npm error gyp info spawn args '-Goutput_dir=.'
npm error gyp info spawn args ]
npm error gyp info spawn make
npm error gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm error ../addon.c: In function 'lock_async':
npm error ../addon.c:96:59: error: passing argument 3 of 'napi_get_value_int64' from incompatible pointer type [->npm error    96 |         NAPI_CALL(env, napi_get_value_int64(env, argv[1], &work->start));
npm error       |                                                           ^~~~~~~~~~~~
npm error       |                                                           |
npm error       |                                                           long long int *
npm error ../addon.c:10:39: note: in definition of macro 'NAPI_CALL'
npm error    10 |                 napi_status status = (call);                                    \
npm error       |                                       ^~~~
npm error In file included from /nix/store/m42x79zlw68sjx4fdg90ahacdrnqwxby-nodejs-24.4.1-source/src/node_api.h:1>npm error                  from ../addon.c:2:
npm error /nix/store/m42x79zlw68sjx4fdg90ahacdrnqwxby-nodejs-24.4.1-source/src/js_native_api.h:169:66: note: expe>npm error   169 |                                                         int64_t* result);
npm error       |                                                         ~~~~~~~~~^~~~~~
npm error ../addon.c:97:59: error: passing argument 3 of 'napi_get_value_int64' from incompatible pointer type [->npm error    97 |         NAPI_CALL(env, napi_get_value_int64(env, argv[2], &work->length));
npm error       |                                                           ^~~~~~~~~~~~~
npm error       |                                                           |
npm error       |                                                           long long int *
npm error ../addon.c:10:39: note: in definition of macro 'NAPI_CALL'
npm error    10 |                 napi_status status = (call);                                    \
npm error       |                                       ^~~~
npm error /nix/store/m42x79zlw68sjx4fdg90ahacdrnqwxby-nodejs-24.4.1-source/src/js_native_api.h:169:66: note: expe>npm error   169 |                                                         int64_t* result);
npm error       |                                                         ~~~~~~~~~^~~~~~
npm error ../addon.c:108:17: warning: cast between incompatible function types from 'struct napi_value__ * (*)(st>npm error   108 |                 (napi_async_complete_callback)lock_finish, work, &work->async
npm error       |                 ^
npm error ../addon.c:10:39: note: in definition of macro 'NAPI_CALL'
npm error    10 |                 napi_status status = (call);                                    \
npm error       |                                       ^~~~
npm error ../addon.c: In function 'unlock_async':
npm error ../addon.c:124:59: error: passing argument 3 of 'napi_get_value_int64' from incompatible pointer type [>npm error   124 |         NAPI_CALL(env, napi_get_value_int64(env, argv[1], &work->start));
npm error       |                                                           ^~~~~~~~~~~~
npm error       |                                                           |
npm error       |                                                           long long int *
npm error ../addon.c:10:39: note: in definition of macro 'NAPI_CALL'
npm error    10 |                 napi_status status = (call);                                    \
npm error       |                                       ^~~~
npm error /nix/store/m42x79zlw68sjx4fdg90ahacdrnqwxby-nodejs-24.4.1-source/src/js_native_api.h:169:66: note: expe>npm error   169 |                                                         int64_t* result);
npm error       |                                                         ~~~~~~~~~^~~~~~
npm error ../addon.c:125:59: error: passing argument 3 of 'napi_get_value_int64' from incompatible pointer type [>npm error   125 |         NAPI_CALL(env, napi_get_value_int64(env, argv[2], &work->length));
npm error       |                                                           ^~~~~~~~~~~~~
npm error       |                                                           |
npm error       |                                                           long long int *
npm error ../addon.c:10:39: note: in definition of macro 'NAPI_CALL'
npm error    10 |                 napi_status status = (call);                                    \
npm error       |                                       ^~~~
npm error /nix/store/m42x79zlw68sjx4fdg90ahacdrnqwxby-nodejs-24.4.1-source/src/js_native_api.h:169:66: note: expe>npm error   169 |                                                         int64_t* result);
npm error       |                                                         ~~~~~~~~~^~~~~~
npm error ../addon.c:134:17: warning: cast between incompatible function types from 'struct napi_value__ * (*)(st>npm error   134 |                 (napi_async_complete_callback)lock_finish, work, &work->async
npm error       |                 ^
npm error ../addon.c:10:39: note: in definition of macro 'NAPI_CALL'
npm error    10 |                 napi_status status = (call);                                    \
npm error       |                                       ^~~~
npm error make: *** [addon.target.mk:108: Release/obj.target/addon/addon.o] Error 1
npm error gyp ERR! build error 
npm error gyp ERR! stack Error: `make` failed with exit code: 2
npm error gyp ERR! stack at ChildProcess.<anonymous> (/nix/store/2bg4yn1ccasnw6cscqhgqwzfw8j2xq1m-nodejs-24.4.1/l>npm error gyp ERR! System Linux 6.15.7
npm error gyp ERR! command "/nix/store/2bg4yn1ccasnw6cscqhgqwzfw8j2xq1m-nodejs-24.4.1/bin/node" "/nix/store/2bg4y>npm error gyp ERR! cwd /build/source/node_modules/os-lock
npm error gyp ERR! node -v v24.4.1
npm error gyp ERR! node-gyp -v v11.2.0
npm error gyp ERR! not ok
npm error Log files were not written due to an error writing to the directory: /nix/store/y61n00g3dhq9x87n5zi35jb>npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

I’ve tried node version 20, 22, 24, with no change.

I’d appreciate any help.

I managed to build it, here’s the working recipe for reference:

      prantlf-jsonlint =
        let
          lockfile = ./../../packages/prantlf-jsonlint/package-lock.json;
        in
        pkgs.buildNpmPackage rec {
          pname = "jsonlint";
          version = "16.0.0";

          src = pkgs.fetchFromGitHub {
            owner = "prantlf";
            repo = "jsonlint";
            rev = "v16.0.0";
            hash = "sha256-pXTw9U8E/Xocy4+M9P3hQjZxvUq/iAHhxwnrJA3hLK0=";
          };

          postPatch = ''
            cp ${lockfile} package-lock.json
          '';

          npmInstallFlags = [ "--omit=dev" ];

          buildPhase = ''
            ${pkgs.coreutils-full}/bin/cat \
              src/prefix.js.txt \
              src/unicode.js \
              src/custom-parser.js \
              src/pointer.js \
              src/native-parser.js \
              src/configurable-parser.js \
              src/suffix.js.txt \
              > lib/jsonlint.js
          '';

          npmDepsHash = "sha256-EIghZWuPvynS+EnhCSPe/PnWF0QjC0csX3Kg2ClQnOU=";

          meta = with lib; {
            description = "JSON/CJSON/JSON5 parser, syntax & schema validator and pretty-printer with a command-line client, written in pure JavaScript. ";
            homepage = "https://prantlf.github.io/jsonlint/";
            license = licenses.mit;
          };
        };