diff options
Diffstat (limited to 'pkgs/development/node-packages/node-env.nix')
-rw-r--r-- | pkgs/development/node-packages/node-env.nix | 91 |
1 files changed, 36 insertions, 55 deletions
diff --git a/pkgs/development/node-packages/node-env.nix b/pkgs/development/node-packages/node-env.nix index c2b723195b77..f65cb65cf8da 100644 --- a/pkgs/development/node-packages/node-env.nix +++ b/pkgs/development/node-packages/node-env.nix @@ -1,11 +1,8 @@ # This file originates from node2nix -{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile}: +{stdenv, nodejs, python2, util-linux, libtool, runCommand, writeTextFile}: let - # Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master - utillinux = if pkgs ? utillinux then pkgs.utillinux else pkgs.util-linux; - python = if nodejs ? python then nodejs.python else python2; # Create a tar wrapper that filters all the 'Ignoring unknown extended header keyword' noise @@ -41,8 +38,8 @@ let }; includeDependencies = {dependencies}: - lib.optionalString (dependencies != []) - (lib.concatMapStrings (dependency: + stdenv.lib.optionalString (dependencies != []) + (stdenv.lib.concatMapStrings (dependency: '' # Bundle the dependencies of the package mkdir -p node_modules @@ -103,7 +100,7 @@ let cd "$DIR/${packageName}" ${includeDependencies { inherit dependencies; }} cd .. - ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} + ${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} ''; pinpointDependencies = {dependencies, production}: @@ -164,12 +161,12 @@ let '' node ${pinpointDependenciesFromPackageJSON} ${if production then "production" else "development"} - ${lib.optionalString (dependencies != []) + ${stdenv.lib.optionalString (dependencies != []) '' if [ -d node_modules ] then cd node_modules - ${lib.concatMapStrings (dependency: pinpointDependenciesOfPackage dependency) dependencies} + ${stdenv.lib.concatMapStrings (dependency: pinpointDependenciesOfPackage dependency) dependencies} cd .. fi ''} @@ -186,7 +183,7 @@ let cd "${packageName}" ${pinpointDependencies { inherit dependencies production; }} cd .. - ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} + ${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} fi ''; @@ -245,8 +242,8 @@ let if(fs.existsSync("./package-lock.json")) { var packageLock = JSON.parse(fs.readFileSync("./package-lock.json")); - if(![1, 2].includes(packageLock.lockfileVersion)) { - process.stderr.write("Sorry, I only understand lock file versions 1 and 2!\n"); + if(packageLock.lockfileVersion !== 1) { + process.stderr.write("Sorry, I only understand lock file version 1!\n"); process.exit(1); } @@ -347,8 +344,8 @@ let cd "${packageName}" runHook preRebuild - ${lib.optionalString bypassCache '' - ${lib.optionalString reconstructLock '' + ${stdenv.lib.optionalString bypassCache '' + ${stdenv.lib.optionalString reconstructLock '' if [ -f package-lock.json ] then echo "WARNING: Reconstruct lock option enabled, but a lock file already exists!" @@ -364,14 +361,14 @@ let node ${addIntegrityFieldsScript} ''} - npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${lib.optionalString production "--production"} rebuild + npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} rebuild if [ "''${dontNpmInstall-}" != "1" ] then # NPM tries to download packages even when they already exist if npm-shrinkwrap is used. rm -f npm-shrinkwrap.json - npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${lib.optionalString production "--production"} install + npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install fi ''; @@ -391,16 +388,17 @@ let , dontStrip ? true , unpackPhase ? "true" , buildPhase ? "true" + , meta ? {} , ... }@args: let - extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" ]; + extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" "meta" ]; in stdenv.mkDerivation ({ name = "node_${name}-${version}"; buildInputs = [ tarWrapper python nodejs ] - ++ lib.optional (stdenv.isLinux) utillinux - ++ lib.optional (stdenv.isDarwin) libtool + ++ stdenv.lib.optional (stdenv.isLinux) util-linux + ++ stdenv.lib.optional (stdenv.isDarwin) libtool ++ buildInputs; inherit nodejs; @@ -446,10 +444,15 @@ let # Run post install hook, if provided runHook postInstall ''; + + meta = { + # default to Node.js' platforms + platforms = nodejs.meta.platforms; + } // meta; } // extraArgs); - # Builds a node environment (a node_modules folder and a set of binaries) - buildNodeDependencies = + # Builds a development shell + buildNodeShell = { name , packageName , version @@ -468,13 +471,13 @@ let let extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ]; - in - stdenv.mkDerivation ({ + + nodeDependencies = stdenv.mkDerivation ({ name = "node-dependencies-${name}-${version}"; buildInputs = [ tarWrapper python nodejs ] - ++ lib.optional (stdenv.isLinux) utillinux - ++ lib.optional (stdenv.isDarwin) libtool + ++ stdenv.lib.optional (stdenv.isLinux) util-linux + ++ stdenv.lib.optional (stdenv.isDarwin) libtool ++ buildInputs; inherit dontStrip; # Stripping may fail a build for some package deployments @@ -494,7 +497,7 @@ let # Create fake package.json to make the npm commands work properly cp ${src}/package.json . chmod 644 package.json - ${lib.optionalString bypassCache '' + ${stdenv.lib.optionalString bypassCache '' if [ -f ${src}/package-lock.json ] then cp ${src}/package-lock.json . @@ -503,44 +506,23 @@ let # Go to the parent folder to make sure that all packages are pinpointed cd .. - ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} + ${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} ${prepareAndInvokeNPM { inherit packageName bypassCache reconstructLock npmFlags production; }} # Expose the executables that were installed cd .. - ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} + ${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} mv ${packageName} lib ln -s $out/lib/node_modules/.bin $out/bin ''; } // extraArgs); - - # Builds a development shell - buildNodeShell = - { name - , packageName - , version - , src - , dependencies ? [] - , buildInputs ? [] - , production ? true - , npmFlags ? "" - , dontNpmInstall ? false - , bypassCache ? false - , reconstructLock ? false - , dontStrip ? true - , unpackPhase ? "true" - , buildPhase ? "true" - , ... }@args: - - let - nodeDependencies = buildNodeDependencies args; in stdenv.mkDerivation { name = "node-shell-${name}-${version}"; - buildInputs = [ python nodejs ] ++ lib.optional (stdenv.isLinux) utillinux ++ buildInputs; + buildInputs = [ python nodejs ] ++ stdenv.lib.optional (stdenv.isLinux) util-linux ++ buildInputs; buildCommand = '' mkdir -p $out/bin cat > $out/bin/shell <<EOF @@ -553,15 +535,14 @@ let # Provide the dependencies in a development shell through the NODE_PATH environment variable inherit nodeDependencies; - shellHook = lib.optionalString (dependencies != []) '' + shellHook = stdenv.lib.optionalString (dependencies != []) '' export NODE_PATH=${nodeDependencies}/lib/node_modules export PATH="${nodeDependencies}/bin:$PATH" ''; }; in { - buildNodeSourceDist = lib.makeOverridable buildNodeSourceDist; - buildNodePackage = lib.makeOverridable buildNodePackage; - buildNodeDependencies = lib.makeOverridable buildNodeDependencies; - buildNodeShell = lib.makeOverridable buildNodeShell; + buildNodeSourceDist = stdenv.lib.makeOverridable buildNodeSourceDist; + buildNodePackage = stdenv.lib.makeOverridable buildNodePackage; + buildNodeShell = stdenv.lib.makeOverridable buildNodeShell; } |