diff --git a/pkgs/applications/version-management/commitizen/generate-dependencies.sh b/pkgs/applications/version-management/commitizen/generate-dependencies.sh index 7111289d2909..9855e2d41d1a 100755 --- a/pkgs/applications/version-management/commitizen/generate-dependencies.sh +++ b/pkgs/applications/version-management/commitizen/generate-dependencies.sh @@ -1,5 +1,5 @@ #!/usr/bin/env nix-shell -#! nix-shell -i bash -p nodePackages.node2nix +#! nix-shell -I nixpkgs=../../../.. -i bash -p nodePackages.node2nix node2nix \ --node-env node-env.nix \ diff --git a/pkgs/applications/version-management/commitizen/node-composition.nix b/pkgs/applications/version-management/commitizen/node-composition.nix index 0769168a78fa..53bdef1f9864 100644 --- a/pkgs/applications/version-management/commitizen/node-composition.nix +++ b/pkgs/applications/version-management/commitizen/node-composition.nix @@ -1,4 +1,4 @@ -# This file has been generated by node2nix 1.8.0. Do not edit! +# This file has been generated by node2nix 1.9.0. Do not edit! {pkgs ? import { inherit system; @@ -6,12 +6,12 @@ let nodeEnv = import ./node-env.nix { - inherit (pkgs) lib stdenv python2 util-linux runCommand writeTextFile; - inherit nodejs; + inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; + inherit pkgs nodejs; libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; }; in import ./node-packages.nix { - inherit (pkgs) fetchurl fetchgit; + inherit (pkgs) fetchurl nix-gitignore stdenv lib fetchgit; inherit nodeEnv; } diff --git a/pkgs/applications/version-management/commitizen/node-env.nix b/pkgs/applications/version-management/commitizen/node-env.nix index 3803723a5147..5f055785791b 100644 --- a/pkgs/applications/version-management/commitizen/node-env.nix +++ b/pkgs/applications/version-management/commitizen/node-env.nix @@ -1,8 +1,11 @@ # This file originates from node2nix -{lib, stdenv, nodejs, python2, util-linux, libtool, runCommand, writeTextFile, writeShellScript}: +{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile, writeShellScript}: 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 @@ -37,36 +40,22 @@ let ''; }; - includeDependencies = {dependencies}: - lib.optionalString (dependencies != []) - (lib.concatMapStrings (dependency: - '' - # Bundle the dependencies of the package - mkdir -p node_modules - cd node_modules + # Common shell logic + installPackage = writeShellScript "install-package" '' + installPackage() { + local packageName=$1 src=$2 - # Only include dependencies if they don't exist. They may also be bundled in the package. - if [ ! -e "${dependency.name}" ] - then - ${composePackage dependency} - fi + local strippedName - cd .. - '' - ) dependencies); - - # Recursively composes the dependencies of a package - composePackage = { name, packageName, src, dependencies ? [], ... }@args: - builtins.addErrorContext "while evaluating node package '${packageName}'" '' - DIR=$(pwd) + local DIR=$PWD cd $TMPDIR - unpackFile ${src} + unpackFile $src # Make the base dir in which the target dependency resides first - mkdir -p "$(dirname "$DIR/${packageName}")" + mkdir -p "$(dirname "$DIR/$packageName")" - if [ -f "${src}" ] + if [ -f "$src" ] then # Figure out what directory has been unpacked packageDir="$(find . -maxdepth 1 -type d | tail -1)" @@ -76,28 +65,53 @@ let chmod -R u+w "$packageDir" # Move the extracted tarball into the output folder - mv "$packageDir" "$DIR/${packageName}" - elif [ -d "${src}" ] + mv "$packageDir" "$DIR/$packageName" + elif [ -d "$src" ] then # Get a stripped name (without hash) of the source directory. # On old nixpkgs it's already set internally. if [ -z "$strippedName" ] then - strippedName="$(stripHash ${src})" + strippedName="$(stripHash $src)" fi # Restore write permissions to make building work chmod -R u+w "$strippedName" # Move the extracted directory into the output folder - mv "$strippedName" "$DIR/${packageName}" + mv "$strippedName" "$DIR/$packageName" fi - # Unset the stripped name to not confuse the next unpack step - unset strippedName + # Change to the package directory to install dependencies + cd "$DIR/$packageName" + } + ''; - # Include the dependencies of the package - cd "$DIR/${packageName}" + # Bundle the dependencies of the package + # + # Only include dependencies if they don't exist. They may also be bundled in the package. + includeDependencies = {dependencies}: + lib.optionalString (dependencies != []) ( + '' + mkdir -p node_modules + cd node_modules + '' + + (lib.concatMapStrings (dependency: + '' + if [ ! -e "${dependency.name}" ]; then + ${composePackage dependency} + fi + '' + ) dependencies) + + '' + cd .. + '' + ); + + # Recursively composes the dependencies of a package + composePackage = { name, packageName, src, dependencies ? [], ... }@args: + builtins.addErrorContext "while evaluating node package '${packageName}'" '' + installPackage "${packageName}" "${src}" ${includeDependencies { inherit dependencies; }} cd .. ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."} @@ -242,8 +256,8 @@ let if(fs.existsSync("./package-lock.json")) { var packageLock = JSON.parse(fs.readFileSync("./package-lock.json")); - if(packageLock.lockfileVersion !== 1) { - process.stderr.write("Sorry, I only understand lock file version 1!\n"); + if(![1, 2].includes(packageLock.lockfileVersion)) { + process.stderr.write("Sorry, I only understand lock file versions 1 and 2!\n"); process.exit(1); } @@ -388,15 +402,16 @@ 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}"; + name = "${name}-${version}"; buildInputs = [ tarWrapper python nodejs ] - ++ lib.optional (stdenv.isLinux) util-linux + ++ lib.optional (stdenv.isLinux) utillinux ++ lib.optional (stdenv.isDarwin) libtool ++ buildInputs; @@ -411,6 +426,8 @@ let passAsFile = [ "compositionScript" "pinpointDependenciesScript" ]; installPhase = '' + source ${installPackage} + # Create and enter a root node_modules/ folder mkdir -p $out/lib/node_modules cd $out/lib/node_modules @@ -443,10 +460,15 @@ let # Run post install hook, if provided runHook postInstall ''; + + meta = { + # default to Node.js' platforms + platforms = nodejs.meta.platforms; + } // meta; } // extraArgs); - # Builds a development shell - buildNodeShell = + # Builds a node environment (a node_modules folder and a set of binaries) + buildNodeDependencies = { name , packageName , version @@ -465,12 +487,12 @@ let let extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ]; - - nodeDependencies = stdenv.mkDerivation ({ + in + stdenv.mkDerivation ({ name = "node-dependencies-${name}-${version}"; buildInputs = [ tarWrapper python nodejs ] - ++ lib.optional (stdenv.isLinux) util-linux + ++ lib.optional (stdenv.isLinux) utillinux ++ lib.optional (stdenv.isDarwin) libtool ++ buildInputs; @@ -483,6 +505,8 @@ let passAsFile = [ "includeScript" "pinpointDependenciesScript" ]; installPhase = '' + source ${installPackage} + mkdir -p $out/${packageName} cd $out/${packageName} @@ -512,11 +536,32 @@ let 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) util-linux ++ buildInputs; + buildInputs = [ python nodejs ] ++ lib.optional (stdenv.isLinux) utillinux ++ buildInputs; buildCommand = '' mkdir -p $out/bin cat > $out/bin/shell <