Create derivation with npm install <pkg>

I try packaging voice over translation, but I do not know the npm ecosystem

{ buildNpmPackage, fetchurl, lib, nodejs, cacert }:

buildNpmPackage rec {
  pname = "vot-cli";
  version = "1.4.3";

  src = fetchurl {
    url = "https://registry.npmjs.org/${pname}/-/${pname}-${version}.tgz";
    hash = "sha256-eOUfy6l48MD9IcWiFlC142vXvo5XobKTJ2uC6xzDGS4=";
  };

  nativeBuildInputs = [ cacert ];

  postPatch = ''
    export HOME=$TMPDIR
    export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
    ${nodejs}/bin/npm install --package-lock-only --no-audit --no-fund --ignore-scripts
  '';

  npmDepsHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";

  meta = {
    description = "Voice Over Translation CLI tool";
    homepage = "https://www.npmjs.com/package/vot-cli";
    license = lib.licenses.mit;
    platforms = lib.platforms.all;
  };
}

But this derivation not worked. Please help write correct derivation

Start here https://nixos.org/manual/nixpkgs/stable/#language-javascript

I’m not going to write the derivation for you, but I will point out something that definitely won’t work:

You’re obviously expecting npm install to have network access. Derivations never have network access, other than fixed-output derivations like fetchurl, as that would not be reproducible.

1 Like

And there is already a package in the nixos system that is installed from https://registry.npmjs.org?

And there is already a package in the nixos system that is installed from https://registry.npmjs.org? So that you can see how it’s done and do it by analogy.

You can just find them with tools like ripgrep or with the github search.

https://github.com/search?q=repo%3ANixOS%2Fnixpkgs+buildNpmPackage&type=code