rtl: 0.12.3-beta -> 0.13.0

- Use `fetch-node-modules` to remove the 4161 line file `node-packages.nix`
- Only use nodejs-slim as a runtime dependency
- Shrink package size by >500M by excluding certain dev-only dependencies
This commit is contained in:
Erik Arvstedt 2022-08-21 14:41:37 +02:00
parent e63dafe0f7
commit 617ed4c8e8
No known key found for this signature in database
GPG key ID: 33312B944DD97846
6 changed files with 118 additions and 4225 deletions

View file

@ -1,16 +1,67 @@
{ pkgs, lib, makeWrapper }:
let
nodejs = pkgs.nodejs-14_x;
nodePackages = import ./composition.nix { inherit pkgs nodejs; };
in
nodePackages.package.overrideAttrs (old: {
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [
{ lib
, stdenvNoCC
, nodejs-16_x
, nodejs-slim-16_x
, fetchNodeModules
, fetchpatch
, fetchurl
, applyPatches
, makeWrapper
}:
let self = stdenvNoCC.mkDerivation {
pname = "rtl";
version = "0.13.0";
src = applyPatches {
src = fetchurl {
url = "https://github.com/Ride-The-Lightning/RTL/archive/refs/tags/v${self.version}.tar.gz";
hash = "sha256-6eopIO5ge6+vkNvZomjAB6e5Qi2kkhXpnSOWQQm53R0=";
};
patches = [
# Move non-runtime deps to `devDependencies`
# https://github.com/Ride-The-Lightning/RTL/pull/1070
(fetchpatch {
url = "https://github.com/Ride-The-Lightning/RTL/pull/1070.patch";
sha256 = "sha256-esDkYI27SNzj2AhYHS9XqlW0r2mr+o0K4A6PUE2kbWU=";
})
];
};
passthru = {
nodejs = nodejs-16_x;
nodejsRuntime = nodejs-slim-16_x;
nodeModules = fetchNodeModules {
inherit (self) src nodejs;
hash = "sha256-LmCrf+lIXz9i9NVALYk9IOBUoPbW8fj+fUsyVJgAANI=";
};
};
nativeBuildInputs = [
makeWrapper
];
postInstall = ''
makeWrapper ${nodejs}/bin/node $out/bin/rtl \
--add-flags $out/lib/node_modules/rtl/rtl
phases = "unpackPhase patchPhase installPhase";
# `src` already contains the precompiled frontend and backend.
# Copy all files required for packaging, like in
# https://github.com/Ride-The-Lightning/RTL/blob/master/dockerfiles/Dockerfile
installPhase = ''
dest=$out/lib/node_modules/rtl
mkdir -p $dest
cp -r \
rtl.js \
package.json \
frontend \
backend \
${self.nodeModules}/lib/node_modules \
$dest
makeWrapper ${self.nodejsRuntime}/bin/node $out/bin/rtl \
--add-flags $dest/rtl.js
runHook postInstall
'';
meta = with lib; {
@ -20,4 +71,4 @@ nodePackages.package.overrideAttrs (old: {
maintainers = with maintainers; [ nixbitcoin earvstedt ];
platforms = platforms.unix;
};
})
}; in self