pkgs: add fetch-node-modules

This commit is contained in:
Erik Arvstedt 2022-08-21 14:41:36 +02:00
parent b214018c29
commit e63dafe0f7
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
3 changed files with 83 additions and 1 deletions

View File

@ -73,7 +73,13 @@
nbPkgs = self.lib.mkNbPkgs { inherit system pkgs; };
in rec {
packages = flake-utils.lib.flattenTree (removeAttrs nbPkgs [
"pinned" "modulesPkgs" "nixops19_09" "krops" "generate-secrets" "netns-exec"
"fetchNodeModules"
"krops"
"modulesPkgs"
"netns-exec"
"nixops19_09"
"pinned"
"generate-secrets"
]) // {
inherit (import ./examples/qemu-vm/minimal-vm.nix self pkgs system)
# A simple demo VM.

View File

@ -0,0 +1,74 @@
# This is a modified version of
# https://github.com/NixOS/nixpkgs/pull/128749
{ lib, stdenvNoCC, makeWrapper, nodejs }:
{ src
, hash ? ""
, runScripts ? false
, preferLocalBuild ? true
, npmFlags ? ""
, ...
} @ args:
stdenvNoCC.mkDerivation ({
inherit src preferLocalBuild;
name = "${src.name}-node_modules";
nativeBuildInputs = [
makeWrapper
(if args ? nodejs then args.nodejs else nodejs)
];
outputHashMode = "recursive";
impureEnvVars = lib.fetchers.proxyImpureEnvVars;
phases = "unpackPhase patchPhase buildPhase installPhase";
buildPhase = ''
runHook preBuild
if [[ ! -f package.json ]]; then
echo "Error: file `package.json` doesn't exist"
exit 1
fi
if [[ ! -f package-lock.json ]]; then
echo "Error: file `package-lock.json` doesn't exist"
exit 1
fi
export SOURCE_DATE_EPOCH=1
export npm_config_cache=/tmp
NPM_FLAGS="--omit=dev --omit=optional --no-update-notifier $npmFlags"
# Scripts may result in non-deterministic behavior.
# Some packages (e.g., Puppeteer) use postinstall scripts to download extra data.
if [[ ! $runScripts ]]; then
NPM_FLAGS+=" --ignore-scripts"
fi
echo "Running npm ci $NPM_FLAGS"
npm ci $NPM_FLAGS
cp package.json \
package-lock.json node_modules/
rm -f node_modules/.package-lock.json
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/lib
cp -r node_modules $out/lib
runHook postInstall
'';
} // (
if hash == "" then {
outputHashAlgo = "sha256";
outputHash = "";
} else {
outputHash = hash;
}
) // (builtins.removeAttrs args [ "hash" ]))

View File

@ -25,6 +25,8 @@ let self = {
packageOverrides = import ./python-packages self;
}).pkgs;
fetchNodeModules = pkgs.callPackage ./build-support/fetch-node-modules.nix { };
# Fix clightning build by using python package mistune 0.8.4, which is a
# strict requirement. This version is affected by CVE-2022-34749, but this
# is irrelevant in this context.