expose function to create `node_modules` only
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.
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
It would be convenient to move nodeDependencies derivation at the top level
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.
I believe this can be closed by https://github.com/svanderburg/node2nix/pull/199.