Building the npm package `puppeteer`

I am hoping to build the npm package puppeteer using nix. Here, I am using a flake.nix file, but would be glad to upstream to nixpkgs with some help. I have two questions:

  1. how can I get around the log writing issue without resorting to a hack?
  2. how can I resolve issues related to angular-cli?

Regarding log writing

{
  description = "Node.js API for Chrome";

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

  outputs = { self, nixpkgs }: {

    packages.x86_64-linux = with nixpkgs.legacyPackages.x86_64-linux; {
      puppeteer = buildNpmPackage rec {
          pname = "puppeteer";
          version = "1.9.1";
        
          src = fetchFromGitHub {
            owner = "puppeteer";
            repo = pname;
            rev = "browsers-v${version}";
            hash = "sha256-iIGKikuN3ndlRjGEYb9R/0da/1dsHLGWLJ69vLyO04Q=";
          };
        
          npmDepsHash = "sha256-QJig+9hmdV3lXSIBJi6nPyWfuEvZRPOdfOxVj0wzYes";
        };
    };

    defaultPackage.x86_64-linux = self.packages.x86_64-linux.puppeteer;
  };
}
$ nix log /nix/store/fb8gs25mxv9zp05wqvzf65h75zsqs8ap-puppeteer-1.9.1.drv
@nix { "action": "setPhase", "phase": "unpackPhase" }
Running phase: unpackPhase
unpacking source archive /nix/store/wnsb5rr78fjw5a9phx108j8rf2ms459x-source
source root is source
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: patchPhase
Executing npmConfigHook
Configuring npm
Validating consistency between /build/source/package-lock.json and /nix/store/0xiipwwchp3l853s6mv0shpcfs1ij956-puppeteer-1.9.1-npm-deps/package-lock.json
Installing dependencies
npm ERR! code ENOTCACHED
npm ERR! request to https://registry.npmjs.org/@angular%2fcli failed: cache mode is 'only-if-cached' but no cached response is available.

npm ERR! Log files were not written due to an error writing to the directory: /nix/store/0xiipwwchp3l853s6mv0shpcfs1ij956-puppeteer-1.9.1-npm-deps/_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

ERROR: npm failed to install dependencies

Here are a few things you can try, depending on the error:
1. Set `makeCacheWritable = true`
  Note that this won't help if npm is complaining about not being able to write to the logs directory -- look above that for the actual error.
2. Set `npmFlags = [ "--legacy-peer-deps" ]`

This is resolvable via the hack of adding makeCacheWritable = true (despite nix’s reported error message). Is there a way of fixing this issue without enabling cache writing?


Regarding angular-cli

{
  description = "Node.js API for Chrome";

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

  outputs = { self, nixpkgs }: {

    packages.x86_64-linux = with nixpkgs.legacyPackages.x86_64-linux; {
      puppeteer = buildNpmPackage rec {
          pname = "puppeteer";
          version = "1.9.1";

          src = fetchFromGitHub {
            owner = "puppeteer";
            repo = pname;
            rev = "browsers-v${version}";
            hash = "sha256-iIGKikuN3ndlRjGEYb9R/0da/1dsHLGWLJ69vLyO04Q=";
          };

          npmDepsHash = "sha256-QJig+9hmdV3lXSIBJi6nPyWfuEvZRPOdfOxVj0wzYes";

          makeCacheWritable = true;
        };
    };

    defaultPackage.x86_64-linux = self.packages.x86_64-linux.puppeteer;
  };
}
$ nix log /nix/store/rx0g3cigyfv80pwvk9v7yclb9l5syiad-puppeteer-1.9.1.drv
@nix { "action": "setPhase", "phase": "unpackPhase" }
Running phase: unpackPhase
unpacking source archive /nix/store/wnsb5rr78fjw5a9phx108j8rf2ms459x-source
source root is source
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: patchPhase
Executing npmConfigHook
Configuring npm
Validating consistency between /build/source/package-lock.json and /nix/store/0xiipwwchp3l853s6mv0shpcfs1ij956-puppeteer-1.9.1-npm-deps/package-lock.json
Making cache writable
Installing dependencies
npm ERR! code ENOTCACHED
npm ERR! request to https://registry.npmjs.org/@angular%2fcli failed: cache mode is 'only-if-cached' but no cached response is available.

npm ERR! A complete log of this run can be found in: /build/cache/_logs/2024-01-10T05_20_40_191Z-debug-0.log

ERROR: npm failed to install dependencies

Here are a few things you can try, depending on the error:
1. Set `makeCacheWritable = true`
  Note that this won't help if npm is complaining about not being able to write to the logs directory -- look above that for the actual error.
2. Set `npmFlags = [ "--legacy-peer-deps" ]

I have also tried using nixpkgs-23.11, which ships with nodejs_18 by default, but a similar error occurs. Here is a link to gituhub:puppeteer/puppeteer.

1 Like