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

@ -0,0 +1,24 @@
set -euo pipefail
# The file that defines the derivation that should be updated
file=$1
# The name of the output of this flake that should be updated
flakeOutput=$2
# A pattern in a line preceding the hash that should be updated
patternPrecedingHash=$3
sed -i "/$patternPrecedingHash/,/hash/ s|hash = .*|hash = \"\";|" $file
# Display stderr and capture it. stdbuf is required to disable output buffering.
stderr=$(
nix build --no-link -L .#$flakeOutput |&
stdbuf -oL grep -v '\berror:.*failed to build$' |
tee /dev/stderr || :
)
hash=$(echo "$stderr" | sed -nE 's/.*?\bgot: *?(sha256-.*)/\1/p')
if [[ ! $hash ]]; then
echo
echo "Error: No hash in build output."
exit 1
fi
sed -i "/$patternPrecedingHash/,/hash/ s|hash = .*|hash = \"$hash\";|" $file
echo "(Note: The above hash mismatch message is not an error. It is part of the fetching process.)"

View File

@ -16,7 +16,7 @@ let self = {
joinmarket = pkgs.callPackage ./joinmarket { nbPythonPackageOverrides = import ./python-packages self; };
lndinit = pkgs.callPackage ./lndinit { };
liquid-swap = pkgs.python3Packages.callPackage ./liquid-swap { };
rtl = pkgs.callPackage ./rtl { };
rtl = pkgs.callPackage ./rtl { inherit (self) fetchNodeModules; };
# The secp256k1 version used by joinmarket
secp256k1 = pkgs.callPackage ./secp256k1 { };
spark-wallet = pkgs.callPackage ./spark-wallet { };

View File

@ -1,17 +0,0 @@
# This file has been generated by node2nix 1.9.0. Do not edit!
{pkgs ? import <nixpkgs> {
inherit system;
}, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-12_x"}:
let
nodeEnv = import "${toString pkgs.path}/pkgs/development/node-packages/node-env.nix" {
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 nix-gitignore stdenv lib fetchgit;
inherit nodeEnv;
}

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

View File

@ -1,44 +1,40 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p nodePackages.node2nix gnupg wget jq gnused
#! nix-shell -i bash -p gnupg wget gnused
set -euo pipefail
TMPDIR="$(mktemp -d -p /tmp)"
trap "rm -rf $TMPDIR" EXIT
version="0.12.3"
version="0.13.0"
repo=https://github.com/Ride-The-Lightning/RTL
# Fetch and verify source tarball
file=v${version}.tar.gz
url=$repo/archive/refs/tags/$file
export GNUPGHOME=$TMPDIR
gpg --keyserver hkps://keyserver.ubuntu.com --recv-key 3E9BD4436C288039CA827A9200C9E2BC2E45666F
wget -P $TMPDIR $url
wget -P $TMPDIR $repo/releases/download/v${version}/$file.asc
gpg --verify $TMPDIR/$file.asc $TMPDIR/$file
hash=$(nix hash file $TMPDIR/$file)
scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd)
# Extract source
src=$TMPDIR/src
mkdir $src
tar xvf $TMPDIR/$file -C $src --strip-components 1 >/dev/null
updateSrc() {
TMPDIR="$(mktemp -d /tmp/rtl.XXX)"
trap "rm -rf $TMPDIR" EXIT
# Generate nix pkg
node2nix \
--input $src/package.json \
--lock $src/package-lock.json \
--composition composition.nix \
--no-copy-node-env
# Fetch and verify source tarball
export GNUPGHOME=$TMPDIR
# Fetch saubyk's key
gpg --keyserver hkps://keyserver.ubuntu.com --recv-key 3E9BD4436C288039CA827A9200C9E2BC2E45666F
file=v${version}.tar.gz
wget -P $TMPDIR $repo/archive/refs/tags/$file
wget -P $TMPDIR $repo/releases/download/v${version}/$file.asc
gpg --verify $TMPDIR/$file.asc $TMPDIR/$file
hash=$(nix hash file $TMPDIR/$file)
# Use node-env.nix from nixpkgs
nodeEnvImport='import "${toString pkgs.path}/pkgs/development/node-packages/node-env.nix"'
sed -i "s|import ./node-env.nix|$nodeEnvImport|" composition.nix
sed -i "
s|\bversion = .*;|version = \"$version\";|
s|\bhash = .*;|hash = \"$hash\";|
" default.nix
}
# Use the verified package src
read -d '' fetchurl <<EOF || :
fetchurl {
url = "$url";
hash = "$hash";
};
EOF
sed -i "s|src = .*/src;|src = ${fetchurl//$'\n'/\\n}|" node-packages.nix
updateNodeModulesHash() {
$scriptDir/../../helper/update-fixed-output-derivation.sh ./default.nix rtl.nodeModules nodeModules
}
if [[ $# == 0 ]]; then
# Each of these can be run separately
updateSrc
updateNodeModulesHash
else
eval "$@"
fi

File diff suppressed because it is too large Load Diff