`npm rebuild` will call `node-gyp install`, which install files to `~/.cache` and NixOS don't allow it

I nix build but failed:

npm ERR! code 1
npm ERR! path /build/source
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@10.0.1
npm ERR! gyp info using node@20.11.1 | linux | x64
npm ERR! gyp info find Python using Python version 3.11.8 found at "/nix/store/7wz6hm9i8wljz0hgwz1wqmn2zlbgavrq-python3-3.11.8/bin/python3"
npm ERR! gyp WARN EACCES current user ("nixbld") does not have permission to access the dev dir "/homeless-shelter/.cache/node-gyp/20.11.1"
npm ERR! gyp WARN EACCES attempting to reinstall using temporary dev dir "/build/.node-gyp"
npm ERR! gyp http GET https://nodejs.org/download/release/v20.11.1/node-v20.11.1-headers.tar.gz
npm ERR! gyp WARN install got an error, rolling back install
npm ERR! gyp WARN install got an error, rolling back install
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack FetchError: request to https://nodejs.org/download/release/v20.11.1/node-v20.11.1-headers.tar.gz failed, reason: getaddrinfo EAI_AGAIN nodejs.org
npm ERR! gyp ERR! stack at ClientRequest.<anonymous> (/nix/store/rlv9fcq70pniyrm3xy21wgk5rdhdh12h-nodejs-20.11.1/lib/node_modules/npm/node_modules/minipass-fetch/li
npm ERR! gyp ERR! stack at ClientRequest.emit (node:events:518:28)
npm ERR! gyp ERR! stack at _destroy (node:_http_client:875:13)
npm ERR! gyp ERR! stack at onSocketNT (node:_http_client:895:5)
npm ERR! gyp ERR! stack at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
npm ERR! gyp ERR! System Linux 6.8.1
npm ERR! gyp ERR! command "/nix/store/rlv9fcq70pniyrm3xy21wgk5rdhdh12h-nodejs-20.11.1/bin/node" "/nix/store/rlv9fcq70pniyrm3xy21wgk5rdhdh12h-nodejs-20.11.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /build/source
npm ERR! gyp ERR! node -v v20.11.1
npm ERR! gyp ERR! node-gyp -v v10.0.1
npm ERR! gyp ERR! not ok

How to get node-v20.11.1 headers?

I found some information.

npm install node-gyp
node-gyp install

will download some code to ~/.cache/node-gyp. However, NixOS don’t allow it download files to ~/.cache. How can I solve it?

If you set XDG_CACHE_HOME to e.g. $(pwd)/node-gyp-cache, does that solve your problem?

If you’re building npm projects with nix, you should probably anyway be using dream2nix or such, you’ll run into lots of issues like this.

The bug seems to be stack FetchError: request to https://nodejs.org/download/release/v20.11.1/node-v20.11.1-headers.tar.gz failed, reason: getaddrinfo EAI_AGAIN nodejs.org.

dream2nix

I’ll take a look :+1:

Yeah, you can’t actually download during a nix build unless it’s in a FOD. Use one of the various npm builders instead of trying to hand-write a derivation for this.

1 Like