diff options
Diffstat (limited to 'pkgs/build-support/node/build-npm-package/default.nix')
-rw-r--r-- | pkgs/build-support/node/build-npm-package/default.nix | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/pkgs/build-support/node/build-npm-package/default.nix b/pkgs/build-support/node/build-npm-package/default.nix new file mode 100644 index 0000000000000..1038bb2abcb47 --- /dev/null +++ b/pkgs/build-support/node/build-npm-package/default.nix @@ -0,0 +1,54 @@ +{ lib, stdenv, fetchNpmDeps, npmHooks, nodejs }: + +{ name ? "${args.pname}-${args.version}" +, src ? null +, srcs ? null +, sourceRoot ? null +, patches ? [ ] +, nativeBuildInputs ? [ ] +, buildInputs ? [ ] + # The output hash of the dependencies for this project. + # Can be calculated in advance with prefetch-npm-deps. +, npmDepsHash ? "" + # Whether to make the cache writable prior to installing dependencies. + # Don't set this unless npm tries to write to the cache directory, as it can slow down the build. +, makeCacheWritable ? false + # The script to run to build the project. +, npmBuildScript ? "build" + # Flags to pass to all npm commands. +, npmFlags ? [ ] + # Flags to pass to `npm ci`. +, npmInstallFlags ? [ ] + # Flags to pass to `npm rebuild`. +, npmRebuildFlags ? [ ] + # Flags to pass to `npm run ${npmBuildScript}`. +, npmBuildFlags ? [ ] + # Flags to pass to `npm pack`. +, npmPackFlags ? [ ] +, ... +} @ args: + +let + npmDeps = fetchNpmDeps { + inherit src srcs sourceRoot patches; + name = "${name}-npm-deps"; + hash = npmDepsHash; + }; + + inherit (npmHooks.override { inherit nodejs; }) npmConfigHook npmBuildHook npmInstallHook; +in +stdenv.mkDerivation (args // { + inherit npmDeps npmBuildScript; + + nativeBuildInputs = nativeBuildInputs ++ [ nodejs npmConfigHook npmBuildHook npmInstallHook ]; + buildInputs = buildInputs ++ [ nodejs ]; + + strictDeps = true; + + # Stripping takes way too long with the amount of files required by a typical Node.js project. + dontStrip = args.dontStrip or true; + + passthru = { inherit npmDeps; } // (args.passthru or { }); + + meta = (args.meta or { }) // { platforms = args.meta.platforms or nodejs.meta.platforms; }; +}) |