How to set NPM command line flags with `node2nix`?

Trying to install Puppeteer, but it keeps failing for some security limitations as the install process is trying to download the latest Chromium binary from there. After looking at many related GitHub issues (1,2,3), the only thing that works is setting npm's --unsafe-perm=true command line flag when using a non-Nix-installed npm.

I couldn’t find anything in the main node2nix README and in the node2nix --help output on how to specify additional NPM command line flags. (Did I overlook something?)

Found the buildNodePackage lambda below in the node2nix source with an npmFlags argument defaulting to an empty string:

  # Builds and composes an NPM package including all its dependencies
  buildNodePackage =
    { name
    , packageName
    , version
    , dependencies ? []
    , buildInputs ? []
    , production ? true
    , npmFlags ? ""
    , dontNpmInstall ? false
    , bypassCache ? false
    , reconstructLock ? false
    , preRebuild ? ""
    , dontStrip ? true
    , unpackPhase ? "true"
    , buildPhase ? "true"
    , ... }@args:

If this npmFlags needs to be overridden, how would I do this?

(Also posted on Stackoverflow.)

I haven’t ever tried this, but the packages vended by node2nix are ultimately derivations created by buildNodePackage, which is an overridable function, so I would assume you could say something like

puppeteer = nodePackages.puppeteer.override {
  npmFlags = "--unsafe-perm=true";
1 Like