I am trying to learn how to write a derivation properly for Nodejs. I do aware yarn2nix
and mkYarnModules
exist, but I want to do it once by myself.
I am trying to use node2nix
to generate the nix file for package.json in a derivation like this:
{ pkgs, lib, stdenv, ... }:
{
mkNpmModules = { pname, version, src }:
let cwd = pkgs.fetchFromGitHub src;
in (pkgs.stdenv.mkDerivation {
inherit pname version;
src = cwd;
buildInputs = with pkgs; [ nodejs nodePackages.node2nix git ];
buildPhase = let
nodeDependencies = pkgs.runCommand "node.nix" { } ''
${pkgs.nodePackages.node2nix}/bin/node2nix -i ${cwd}/package.json
'';
in ''
ls -a ${nodeDependencies}
'';
});
}
Unfortunately this doesn’t work. I am getting info retry will retry, error on last attempt: Error: getaddrinfo ENOTFOUND registry.npmjs.org
, which I believe is because of the sandbox nature of derivation, which network doesn’t exist there?
But I have seen similar being done in mkYarnModules
like this. Why is that? Is the derivation from yarn2nix
generated before entering the derivation?