
`importNpmLock.buildNodeModules` returns a derivation with a pre-built `node_modules` directory, as imported by `importNpmLock`. This is to be used together with `importNpmLock.hooks.linkNodeModulesHook` to facilitate `nix-shell`/`nix develop` based development workflows: ```nix pkgs.mkShell { packages = [ importNpmLock.hooks.linkNodeModulesHook nodejs ]; npmDeps = importNpmLock.buildNodeModules { npmRoot = ./.; inherit nodejs; }; } ``` will create a development shell where a `node_modules` directory is created & packages symlinked to the Nix store when activated. This code is adapted from https://github.com/adisbladis/buildNodeModules
24 lines
687 B
Nix
24 lines
687 B
Nix
{ callPackage, lib, makeSetupHook, srcOnly, nodejs }:
|
|
{
|
|
npmConfigHook = makeSetupHook
|
|
{
|
|
name = "npm-config-hook";
|
|
substitutions = {
|
|
nodeSrc = srcOnly nodejs;
|
|
nodeGyp = "${nodejs}/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js";
|
|
canonicalizeSymlinksScript = ./canonicalize-symlinks.js;
|
|
storePrefix = builtins.storeDir;
|
|
};
|
|
} ./npm-config-hook.sh;
|
|
|
|
linkNodeModulesHook = makeSetupHook
|
|
{
|
|
name = "node-modules-hook.sh";
|
|
substitutions = {
|
|
nodejs = lib.getExe nodejs;
|
|
script = ./link-node-modules.js;
|
|
storePrefix = builtins.storeDir;
|
|
};
|
|
} ./link-node-modules-hook.sh;
|
|
}
|