lightning-terminal: fix frontend build

Previously, the yarn app was not built correctly and the resulting files were
not placed where the backend (via Go's //go:embed) expects them. As a result,
litd served an empty web UI page with a single link to .gitkeep, the only file
present in app/build from Git.

Upstream uses a Dockerfile and app/gen_app_docker.sh to install yarn and
populate that directory. This commit replicates that behavior using Nix.

Since the app uses yarn v1, mkYarnPackage was inappropriate and was replaced
with a stdenv.mkDerivation using yarnConfigHook, yarnInstallHook, yarnBuildHook.
Linters were disabled to prevent build failures due to findings such as single
vs double quotes.

The package.json file included a postbuild step using 'git restore', which
failed in the Nix sandbox due to the absence of Git. This step was disabled,
as the file it touches is not modified or necessary for the build.

To ensure the backend can embed the frontend properly, this commit copies the
built frontend files into app/build inside the backend's source tree during
postUnpack. An assertion was added to check that index.html exists there to
prevent this issue from silently recurring. Also a nix test was added that runs
litd and checks that it serves index.html using curl.
This commit is contained in:
Boris Nagaev
2025-07-06 20:51:45 -03:00
parent 34fa8ce995
commit 0a41957296
+66 -13
View File
@@ -1,11 +1,18 @@
{
lib,
stdenv,
buildGoModule,
fetchFromGitHub,
mkYarnPackage,
nodejs,
yarn,
yarnConfigHook,
yarnBuildHook,
fetchYarnDeps,
go,
versionCheckHook,
testers,
curl,
lightning-terminal,
}:
buildGoModule rec {
@@ -30,6 +37,18 @@ buildGoModule rec {
vendorHash = "sha256-Gbx4uz6q9Ef4QNv6DpIoCACjhT66iZ7GPNpd/g9MgKQ=";
buildInputs = [ lightning-app ];
postUnpack = ''
echo "Copying app build output into app/build dir to embed into litd."
cp -r ${lightning-app}/* source/app/build/
echo "Asserting that app/build/index.html exists."
if [ ! -f source/app/build/index.html ]; then
echo "ERROR: app/build/index.html not found!"
exit 1
fi
'';
ldflags = [
"-s"
"-w"
@@ -75,24 +94,59 @@ buildGoModule rec {
versionCheckHook
];
lightning-app = mkYarnPackage {
passthru.tests.litd-app = testers.runCommand {
name = "test-litd-app";
nativeBuildInputs = [
curl
lightning-terminal
];
script = ''
litd \
--uipassword=12345678 \
--insecure-httplisten=127.0.0.1:8080 \
--httpslisten= &
sleep 2
GETindexHTTPCode=$(curl -o /dev/null -w "%{http_code}" -Lvs 127.0.0.1:8080/index.html)
if [ "$GETindexHTTPCode" = 200 ]; then
touch $out
fi
'';
};
lightning-app = stdenv.mkDerivation {
pname = "lightning-app";
src = "${src}/app";
version = "0.0.1";
packageJSON = "${src}/app/package.json";
yarnLock = "${src}/app/yarn.lock";
offlineCache = fetchYarnDeps {
yarnOfflineCache = fetchYarnDeps {
yarnLock = "${src}/app/yarn.lock";
hash = "sha256-ulOgKQRLG4cRi1N1DajmbZ0L7d08g5cYDA9itXu+Esw=";
};
# Remove this command from package.json. It requires Git and it is not
# really needed.
postPatch = ''
substituteInPlace package.json \
--replace '"postbuild": "git restore build/.gitkeep",' ' '
'';
nativeBuildInputs = [
nodejs
yarn
yarnConfigHook
yarnBuildHook
];
preBuild = ''
# Disable linter. It finds a lot of proposed substitutions and fails.
export DISABLE_ESLINT_PLUGIN=true
export CI=false
'';
installPhase = ''
mkdir -p $out
cp -r build/* $out/
'';
};
outputs = [
"out"
"app"
];
postFixup = ''
ln -s ${lightning-app} "$app"
'';
meta = {
description = "All-in-one Lightning node management tool that includes LND, Loop, Pool, Faraday, and Tapd";
@@ -101,6 +155,5 @@ buildGoModule rec {
changelog = "https://github.com/lightninglabs/lightning-terminal/releases/tag/v${version}";
maintainers = with lib.maintainers; [ HannahMR ];
mainProgram = "litcli";
outputsToInstall = [ "out" ];
};
}