node2nix icon indicating copy to clipboard operation
node2nix copied to clipboard

expose function to create `node_modules` only

Open gilligan opened this issue 9 years ago • 4 comments

I have a rather big nodejs project in which I currently have a node_modules derivation which creates the contents of the node_modules directory by calling npm install - obviously I would like to replace that.

It would be great if node2nix could provide a public function to only create node_modules. My project is more complex and so none of of the other targets quite match for me use case.

gilligan avatar Jul 15 '16 09:07 gilligan

Apparently, you could already do something like this by using the shell attribute from the composition expression (default.nix):

For example:

with import <nixpkgs> {};

let shell = (import ./default.nix {}).shell;
in
stdenv.mkDerivation {
  name = "foo";
  buildCommand = ''
    echo "Path to node_modules: ${shell.nodeDependencies}/lib/node_modules"
  '';
}

Obviously, you should do something more meaningful with shell.nodeDependencies than the example expression shown above

svanderburg avatar Jul 18 '16 21:07 svanderburg

It would be convenient to move nodeDependencies derivation at the top level

srghma avatar Apr 29 '18 10:04 srghma

Agree with @srghma.

Also very convenient as the nodeDependencies would not need to be rebuilt so often (related: https://github.com/svanderburg/node2nix/issues/74). Currently it is rebuild a lot as src = ./. (implicit trough buildNodeShell) although that is not necessary (only a dummy package.json is required https://github.com/svanderburg/node2nix/blob/add2ea4c69851507b3ae74d7832dea07f5af625e/nix/node-env.nix#L466).

Currently I am using following workaround:

nodeDependencies = ((import ./node-composition.nix {}).shell.override { src = ./dummy; }).nodeDependencies;

Where ./dummy is a folder containing a copy of package.json.

Edit: Unsure about how "dummy" packages.json can be. The solution above didn't work with an empty package.json, works with a copy of the real packages.json.

pukkamustard avatar Oct 23 '18 07:10 pukkamustard

I believe this can be closed by https://github.com/svanderburg/node2nix/pull/199.

sebastianblunt avatar Apr 15 '22 07:04 sebastianblunt