at master 110 lines 3.4 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchNpmDeps, 5 buildPackages, 6 nodejs, 7 cctools, 8}@topLevelArgs: 9 10lib.extendMkDerivation { 11 constructDrv = stdenv.mkDerivation; 12 13 extendDrvArgs = 14 finalAttrs: 15 { 16 name ? "${args.pname}-${args.version}", 17 src ? null, 18 srcs ? null, 19 sourceRoot ? null, 20 prePatch ? "", 21 patches ? [ ], 22 postPatch ? "", 23 patchFlags ? [ ], 24 nativeBuildInputs ? [ ], 25 buildInputs ? [ ], 26 # The output hash of the dependencies for this project. 27 # Can be calculated in advance with prefetch-npm-deps. 28 npmDepsHash ? "", 29 # Whether to force the usage of Git dependencies that have install scripts, but not a lockfile. 30 # Use with care. 31 forceGitDeps ? false, 32 # Whether to force allow an empty dependency cache. 33 # This can be enabled if there are truly no remote dependencies, but generally an empty cache indicates something is wrong. 34 forceEmptyCache ? false, 35 # Whether to make the cache writable prior to installing dependencies. 36 # Don't set this unless npm tries to write to the cache directory, as it can slow down the build. 37 makeCacheWritable ? false, 38 # The script to run to build the project. 39 npmBuildScript ? "build", 40 # Flags to pass to all npm commands. 41 npmFlags ? [ ], 42 # Flags to pass to `npm ci`. 43 npmInstallFlags ? [ ], 44 # Flags to pass to `npm rebuild`. 45 npmRebuildFlags ? [ ], 46 # Flags to pass to `npm run ${npmBuildScript}`. 47 npmBuildFlags ? [ ], 48 # Flags to pass to `npm pack`. 49 npmPackFlags ? [ ], 50 # Flags to pass to `npm prune`. 51 npmPruneFlags ? npmInstallFlags, 52 # Value for npm `--workspace` flag and directory in which the files to be installed are found. 53 npmWorkspace ? null, 54 nodejs ? topLevelArgs.nodejs, 55 npmDeps ? fetchNpmDeps { 56 inherit 57 forceGitDeps 58 forceEmptyCache 59 src 60 srcs 61 sourceRoot 62 prePatch 63 patches 64 postPatch 65 patchFlags 66 ; 67 name = "${name}-npm-deps"; 68 hash = npmDepsHash; 69 }, 70 # Custom npmConfigHook 71 npmConfigHook ? null, 72 # Custom npmBuildHook 73 npmBuildHook ? null, 74 # Custom npmInstallHook 75 npmInstallHook ? null, 76 ... 77 }@args: 78 79 let 80 # .override {} negates splicing, so we need to use buildPackages explicitly 81 npmHooks = buildPackages.npmHooks.override { 82 inherit nodejs; 83 }; 84 in 85 { 86 inherit npmDeps npmBuildScript; 87 88 nativeBuildInputs = 89 nativeBuildInputs 90 ++ [ 91 nodejs 92 # Prefer passed hooks 93 (if npmConfigHook != null then npmConfigHook else npmHooks.npmConfigHook) 94 (if npmBuildHook != null then npmBuildHook else npmHooks.npmBuildHook) 95 (if npmInstallHook != null then npmInstallHook else npmHooks.npmInstallHook) 96 nodejs.python 97 ] 98 ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]; 99 buildInputs = buildInputs ++ [ nodejs ]; 100 101 strictDeps = true; 102 103 # Stripping takes way too long with the amount of files required by a typical Node.js project. 104 dontStrip = args.dontStrip or true; 105 106 meta = (args.meta or { }) // { 107 platforms = args.meta.platforms or nodejs.meta.platforms; 108 }; 109 }; 110}