Fix mempool package: remove fetchNodeModules dependency
Replace fetchNodeModules (nix-bitcoin specific) with standard npm ci approach. The package-lock.json files in the mempool repo will be used directly.
This commit is contained in:
+97
-121
@@ -3,22 +3,18 @@
|
|||||||
, nodejs_22
|
, nodejs_22
|
||||||
, nodejs-slim_22
|
, nodejs-slim_22
|
||||||
, fetchFromGitHub
|
, fetchFromGitHub
|
||||||
, fetchNodeModules
|
|
||||||
, runCommand
|
, runCommand
|
||||||
, makeWrapper
|
, makeWrapper
|
||||||
, curl
|
, curl
|
||||||
, cacert
|
, cacert
|
||||||
, rsync
|
, rsync
|
||||||
# for rust-gbt (backend module)
|
|
||||||
, cargo
|
, cargo
|
||||||
, rustc
|
, rustc
|
||||||
, rustPlatform
|
, rustPlatform
|
||||||
, napi-rs-cli
|
, napi-rs-cli
|
||||||
}:
|
}:
|
||||||
rec {
|
|
||||||
nodejs = nodejs_22;
|
|
||||||
nodejsRuntime = nodejs-slim_22;
|
|
||||||
|
|
||||||
|
let
|
||||||
version = "3.2.1";
|
version = "3.2.1";
|
||||||
|
|
||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
@@ -28,105 +24,22 @@ rec {
|
|||||||
hash = "sha256-O2XPD1/BXQnzuOP/vMVyRfmFZEgjA85r+PShWne0vqU=";
|
hash = "sha256-O2XPD1/BXQnzuOP/vMVyRfmFZEgjA85r+PShWne0vqU=";
|
||||||
};
|
};
|
||||||
|
|
||||||
nodeModules = {
|
frontendAssets = stdenvNoCC.mkDerivation {
|
||||||
frontend = fetchNodeModules {
|
|
||||||
inherit src nodejs;
|
|
||||||
sourceRoot = "source/frontend";
|
|
||||||
hash = "sha256-+jfgsAkDdYvgso8uSHaBj/sQL3fC/ABQWzVTXfdZcU0=";
|
|
||||||
};
|
|
||||||
backend = fetchNodeModules {
|
|
||||||
inherit src nodejs;
|
|
||||||
sourceRoot = "source/backend";
|
|
||||||
hash = "sha256-y5l2SYZYK9SKSy6g0+mtTWD6JFkkdQHHBboECpEvWZ4=";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
frontendAssets = fetchFiles {
|
|
||||||
name = "mempool-frontend-assets";
|
name = "mempool-frontend-assets";
|
||||||
hash = "sha256-r6GfOY8Pdh15o2OQMk8syfvWMV6WMCReToAEkQm7tqQ=";
|
outputHashMode = "recursive";
|
||||||
fetcher = ./frontend-assets-fetch.sh;
|
outputHashAlgo = "sha256";
|
||||||
};
|
outputHash = "sha256-r6GfOY8Pdh15o2OQMk8syfvWMV6WMCReToAEkQm7tqQ=";
|
||||||
|
nativeBuildInputs = [ curl cacert ];
|
||||||
mempool-backend = mkDerivationMempool {
|
buildCommand = ''
|
||||||
pname = "mempool-backend";
|
mkdir $out
|
||||||
|
cd $out
|
||||||
patches = [ ./0001-allow-disabling-mining-pool-fetching.patch ];
|
${builtins.readFile ./frontend-assets-fetch.sh}
|
||||||
|
|
||||||
buildPhase = ''
|
|
||||||
cd backend
|
|
||||||
${sync} --chmod=+w ${nodeModules.backend}/lib/node_modules .
|
|
||||||
patchShebangs node_modules
|
|
||||||
|
|
||||||
${sync} ${mempool-rust-gbt}/ rust-gbt
|
|
||||||
npm run package
|
|
||||||
|
|
||||||
runHook postBuild
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
mkdir -p $out/lib/mempool-backend
|
|
||||||
${sync} package/ $out/lib/mempool-backend
|
|
||||||
|
|
||||||
makeWrapper ${nodejsRuntime}/bin/node $out/bin/mempool-backend \
|
|
||||||
--add-flags $out/lib/mempool-backend/index.js
|
|
||||||
|
|
||||||
runHook postInstall
|
|
||||||
'';
|
|
||||||
|
|
||||||
passthru = {
|
|
||||||
inherit nodejs nodejsRuntime;
|
|
||||||
nodeModules = nodeModules.backend;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
mempool-frontend = mkFrontend {};
|
|
||||||
|
|
||||||
# Argument `config` (type: attrset) defines the mempool frontend config.
|
|
||||||
# If `{}`, the default config is used.
|
|
||||||
# See here for available options:
|
|
||||||
# https://github.com/mempool/mempool/blob/master/frontend/src/app/services/state.service.ts
|
|
||||||
# (`interface Env` and `defaultEnv`)
|
|
||||||
mkFrontend = config: mkDerivationMempool {
|
|
||||||
pname = "mempool-frontend";
|
|
||||||
|
|
||||||
buildPhase = ''
|
|
||||||
cd frontend
|
|
||||||
|
|
||||||
${sync} --chmod=+w ${nodeModules.frontend}/lib/node_modules .
|
|
||||||
patchShebangs node_modules
|
|
||||||
|
|
||||||
# sync-assets.js is called during `npm run build` and downloads assets from the
|
|
||||||
# internet. Disable this script and instead add the assets manually after building.
|
|
||||||
: > sync-assets.js
|
|
||||||
|
|
||||||
${lib.optionalString (config != {}) ''
|
|
||||||
ln -s ${builtins.toFile "mempool-frontend-config" (builtins.toJSON config)} mempool-frontend-config.json
|
|
||||||
''}
|
|
||||||
|
|
||||||
npm run build
|
|
||||||
|
|
||||||
# Add assets that would otherwise be downloaded by sync-assets.js
|
|
||||||
${sync} ${frontendAssets}/ dist/mempool/browser/resources
|
|
||||||
|
|
||||||
runHook postBuild
|
|
||||||
'';
|
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
${sync} dist/mempool/browser/ $out
|
|
||||||
|
|
||||||
runHook postInstall
|
|
||||||
'';
|
|
||||||
|
|
||||||
passthru = {
|
|
||||||
withConfig = mkFrontend;
|
|
||||||
assets = frontendAssets;
|
|
||||||
nodeModules = nodeModules.frontend;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mempool-rust-gbt = stdenvNoCC.mkDerivation rec {
|
mempool-rust-gbt = stdenvNoCC.mkDerivation rec {
|
||||||
pname = "mempool-rust-gbt";
|
pname = "mempool-rust-gbt";
|
||||||
inherit version src meta;
|
inherit version src;
|
||||||
|
|
||||||
sourceRoot = "source/rust/gbt";
|
sourceRoot = "source/rust/gbt";
|
||||||
|
|
||||||
@@ -159,43 +72,106 @@ rec {
|
|||||||
passthru = { inherit cargoDeps; };
|
passthru = { inherit cargoDeps; };
|
||||||
};
|
};
|
||||||
|
|
||||||
mempool-nginx-conf = runCommand "mempool-nginx-conf" {} ''
|
|
||||||
${sync} --chmod=u+w ${./nginx-conf}/ $out
|
|
||||||
${sync} ${src}/production/nginx/http-language.conf $out
|
|
||||||
'';
|
|
||||||
|
|
||||||
sync = "${rsync}/bin/rsync -a --inplace";
|
sync = "${rsync}/bin/rsync -a --inplace";
|
||||||
|
|
||||||
mkDerivationMempool = args: stdenvNoCC.mkDerivation ({
|
mkDerivationMempool = args: stdenvNoCC.mkDerivation ({
|
||||||
inherit version src meta;
|
inherit version src;
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
makeWrapper
|
makeWrapper
|
||||||
nodejs
|
nodejs_22
|
||||||
rsync
|
rsync
|
||||||
];
|
];
|
||||||
|
|
||||||
phases = "unpackPhase patchPhase buildPhase installPhase";
|
phases = "unpackPhase patchPhase buildPhase installPhase";
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "Bitcoin blockchain and mempool explorer";
|
||||||
|
homepage = "https://github.com/mempool/mempool/";
|
||||||
|
license = licenses.agpl3Plus;
|
||||||
|
maintainers = with maintainers; [ erikarvstedt ];
|
||||||
|
platforms = platforms.unix;
|
||||||
|
};
|
||||||
} // args);
|
} // args);
|
||||||
|
|
||||||
fetchFiles = { name, hash, fetcher }: stdenvNoCC.mkDerivation {
|
in rec {
|
||||||
inherit name;
|
mempool-backend = mkDerivationMempool {
|
||||||
outputHashMode = "recursive";
|
pname = "mempool-backend";
|
||||||
outputHashAlgo = "sha256";
|
|
||||||
outputHash = hash;
|
patches = [ ./0001-allow-disabling-mining-pool-fetching.patch ];
|
||||||
nativeBuildInputs = [ curl cacert ];
|
|
||||||
buildCommand = ''
|
buildPhase = ''
|
||||||
mkdir $out
|
cd backend
|
||||||
cd $out
|
# Install dependencies using npm ci (requires package-lock.json)
|
||||||
${builtins.readFile fetcher}
|
npm ci --legacy-peer-deps --ignore-scripts
|
||||||
|
patchShebangs node_modules
|
||||||
|
|
||||||
|
${sync} ${mempool-rust-gbt}/ rust-gbt
|
||||||
|
npm run package
|
||||||
|
|
||||||
|
runHook postBuild
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/lib/mempool-backend
|
||||||
|
${sync} package/ $out/lib/mempool-backend
|
||||||
|
|
||||||
|
makeWrapper ${nodejs-slim_22}/bin/node $out/bin/mempool-backend \
|
||||||
|
--add-flags $out/lib/mempool-backend/index.js
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
|
||||||
|
passthru = {
|
||||||
|
nodejs = nodejs_22;
|
||||||
|
nodejsRuntime = nodejs-slim_22;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
meta = with lib; {
|
mempool-frontend = mkFrontend {};
|
||||||
description = "Bitcoin blockchain and mempool explorer";
|
|
||||||
homepage = "https://github.com/mempool/mempool/";
|
# Argument `config` (type: attrset) defines the mempool frontend config.
|
||||||
license = licenses.agpl3Plus;
|
# If `{}`, the default config is used.
|
||||||
maintainers = with maintainers; [ erikarvstedt ];
|
mkFrontend = config: mkDerivationMempool {
|
||||||
platforms = platforms.unix;
|
pname = "mempool-frontend";
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
cd frontend
|
||||||
|
|
||||||
|
# Install dependencies using npm ci (requires package-lock.json)
|
||||||
|
npm ci --legacy-peer-deps --ignore-scripts
|
||||||
|
patchShebangs node_modules
|
||||||
|
|
||||||
|
# sync-assets.js is called during `npm run build` and downloads assets from the
|
||||||
|
# internet. Disable this script and instead add the assets manually after building.
|
||||||
|
: > sync-assets.js
|
||||||
|
|
||||||
|
${lib.optionalString (config != {}) ''
|
||||||
|
ln -s ${builtins.toFile "mempool-frontend-config" (builtins.toJSON config)} mempool-frontend-config.json
|
||||||
|
''}
|
||||||
|
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# Add assets that would otherwise be downloaded by sync-assets.js
|
||||||
|
${sync} ${frontendAssets}/ dist/mempool/browser/resources
|
||||||
|
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
${sync} dist/mempool/browser/ $out
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
|
||||||
|
passthru = {
|
||||||
|
withConfig = mkFrontend;
|
||||||
|
assets = frontendAssets;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mempool-nginx-conf = runCommand "mempool-nginx-conf" {} ''
|
||||||
|
${sync} --chmod=u+w ${./nginx-conf}/ $out
|
||||||
|
${sync} ${src}/production/nginx/http-language.conf $out
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user