From 759179662a680c7c4de624832266db3e3d249965 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Sat, 7 May 2022 15:04:57 +0000 Subject: [PATCH] web/quotes: bump to NodeJS current LTS (16.x) --- web/quotes/node-default.nix | 6 +- web/quotes/node-env.nix | 109 +++++++++++++++++++++-------------- web/quotes/node-packages.nix | 2 +- web/quotes/regen_node2nix.sh | 1 + 4 files changed, 72 insertions(+), 46 deletions(-) diff --git a/web/quotes/node-default.nix b/web/quotes/node-default.nix index 64326c6b21..ca76a98f5a 100644 --- a/web/quotes/node-default.nix +++ b/web/quotes/node-default.nix @@ -1,12 +1,12 @@ -# This file has been generated by node2nix 1.9.0. Do not edit! +# This file has been generated by node2nix 1.11.1. Do not edit! {pkgs ? import { inherit system; - }, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-12_x"}: + }, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-16_x"}: let nodeEnv = import ./node-env.nix { - inherit (pkgs) stdenv lib python2 runCommand writeTextFile; + inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; inherit pkgs nodejs; libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; }; diff --git a/web/quotes/node-env.nix b/web/quotes/node-env.nix index 21089c4d54..2590dd267a 100644 --- a/web/quotes/node-env.nix +++ b/web/quotes/node-env.nix @@ -1,6 +1,6 @@ # This file originates from node2nix -{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile}: +{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 @@ -40,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)" @@ -79,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.packageName}" ]; 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 .."} @@ -246,8 +257,8 @@ let 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"); - process.exit(1); + process.stderr.write("Sorry, I only understand lock file versions 1 and 2!\n"); + process.exit(1); } if(packageLock.dependencies !== undefined) { @@ -379,7 +390,7 @@ let buildNodePackage = { name , packageName - , version + , version ? null , dependencies ? [] , buildInputs ? [] , production ? true @@ -398,7 +409,7 @@ let extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" "meta" ]; in stdenv.mkDerivation ({ - name = "${name}-${version}"; + name = "${name}${if version == null then "" else "-${version}"}"; buildInputs = [ tarWrapper python nodejs ] ++ lib.optional (stdenv.isLinux) utillinux ++ lib.optional (stdenv.isDarwin) libtool @@ -415,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 @@ -428,6 +441,14 @@ let if [ -d "$out/lib/node_modules/.bin" ] then ln -s $out/lib/node_modules/.bin $out/bin + + # Patch the shebang lines of all the executables + ls $out/bin/* | while read i + do + file="$(readlink -f "$i")" + chmod u+rwx "$file" + patchShebangs "$file" + done fi # Create symlinks to the deployed manual page folders, if applicable @@ -458,7 +479,7 @@ let buildNodeDependencies = { name , packageName - , version + , version ? null , src , dependencies ? [] , buildInputs ? [] @@ -476,7 +497,7 @@ let extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ]; in stdenv.mkDerivation ({ - name = "node-dependencies-${name}-${version}"; + name = "node-dependencies-${name}${if version == null then "" else "-${version}"}"; buildInputs = [ tarWrapper python nodejs ] ++ lib.optional (stdenv.isLinux) utillinux @@ -492,6 +513,8 @@ let passAsFile = [ "includeScript" "pinpointDependenciesScript" ]; installPhase = '' + source ${installPackage} + mkdir -p $out/${packageName} cd $out/${packageName} @@ -504,6 +527,7 @@ let if [ -f ${src}/package-lock.json ] then cp ${src}/package-lock.json . + chmod 644 package-lock.json fi ''} @@ -526,7 +550,7 @@ let buildNodeShell = { name , packageName - , version + , version ? null , src , dependencies ? [] , buildInputs ? [] @@ -542,9 +566,10 @@ let let nodeDependencies = buildNodeDependencies args; + extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "unpackPhase" "buildPhase" ]; in - stdenv.mkDerivation { - name = "node-shell-${name}-${version}"; + stdenv.mkDerivation ({ + name = "node-shell-${name}${if version == null then "" else "-${version}"}"; buildInputs = [ python nodejs ] ++ lib.optional (stdenv.isLinux) utillinux ++ buildInputs; buildCommand = '' @@ -563,7 +588,7 @@ let export NODE_PATH=${nodeDependencies}/lib/node_modules export PATH="${nodeDependencies}/bin:$PATH" ''; - }; + } // extraArgs); in { buildNodeSourceDist = lib.makeOverridable buildNodeSourceDist; diff --git a/web/quotes/node-packages.nix b/web/quotes/node-packages.nix index 43f4e1b3ce..82b8dd8d65 100644 --- a/web/quotes/node-packages.nix +++ b/web/quotes/node-packages.nix @@ -1,4 +1,4 @@ -# This file has been generated by node2nix 1.9.0. Do not edit! +# This file has been generated by node2nix 1.11.1. Do not edit! {nodeEnv, fetchurl, fetchgit, nix-gitignore, stdenv, lib, globalBuildInputs ? []}: diff --git a/web/quotes/regen_node2nix.sh b/web/quotes/regen_node2nix.sh index b9ca7b4943..3873b18c91 100755 --- a/web/quotes/regen_node2nix.sh +++ b/web/quotes/regen_node2nix.sh @@ -1,6 +1,7 @@ #!/bin/sh exec node2nix \ + -16 \ -i ./theme/static_src/package.json \ -l ./theme/static_src/package-lock.json \ -c node-default.nix \