From 34fa8ce995b5a377fae41031340210444f50ca89 Mon Sep 17 00:00:00 2001 From: Ethan Carter Edwards Date: Fri, 7 Mar 2025 22:10:41 -0500 Subject: [PATCH 1/2] lightning-terminal: remove package.json package.json is included upstream and there is no reason for it to be inlcuded in the nixpkgs repo. Signed-off-by: Ethan Carter Edwards --- .../li/lightning-terminal/package.json | 139 ------------------ .../by-name/li/lightning-terminal/package.nix | 2 +- 2 files changed, 1 insertion(+), 140 deletions(-) delete mode 100644 pkgs/by-name/li/lightning-terminal/package.json diff --git a/pkgs/by-name/li/lightning-terminal/package.json b/pkgs/by-name/li/lightning-terminal/package.json deleted file mode 100644 index 3452ada9c1ca..000000000000 --- a/pkgs/by-name/li/lightning-terminal/package.json +++ /dev/null @@ -1,139 +0,0 @@ -{ - "name": "lightning-terminal", - "version": "0.0.1", - "description": "Lightning Terminal", - "repository": "https://github.com/lightninglabs/lightning-terminal", - "private": true, - "scripts": { - "start": "BROWSER=none react-scripts start", - "develop": "REACT_APP_USE_SAMPLE_DATA=true yarn start", - "build": "react-scripts build", - "postbuild": "git restore build/.gitkeep", - "test": "react-scripts test --env=jest-environment-jsdom --transformIgnorePatterns \"node_modules/(?!d3)/\"", - "test:ci": "cross-env CI=true yarn test --coverage", - "eject": "react-scripts eject", - "lint": "eslint --ext .ts,.tsx --ignore-path .eslintignore .", - "tsc": "tsc --noEmit", - "protos": "node ./scripts/build-protos.js", - "storybook": "storybook dev -p 9009 -s public", - "build-storybook": "storybook build -s public" - }, - "dependencies": { - "@emotion/react": "11.4.0", - "@emotion/styled": "11.3.0", - "@improbable-eng/grpc-web": "0.14.0", - "@types/react-collapse": "^5.0.1", - "big.js": "6.1.1", - "bootstrap": "4.6.1", - "buffer": "6.0.3", - "copy-to-clipboard": "3.3.1", - "d3": "7.8.5", - "date-fns": "2.14.0", - "debug": "4.3.1", - "file-saver": "2.0.2", - "http-proxy-middleware": "2.0.7", - "i18next": "19.5.1", - "i18next-browser-languagedetector": "5.0.0", - "lodash": "4.17.21", - "lottie-web": "5.7.0", - "mobx": "6.3.2", - "mobx-react-lite": "3.2.0", - "mobx-utils": "6.0.4", - "qrcode.react": "^3.1.0", - "rc-dialog": "^8.9.0", - "rc-select": "11.5.0", - "rc-switch": "^4.0.0", - "rc-tooltip": "4.2.1", - "react": "17.0.2", - "react-collapse": "^5.1.1", - "react-dom": "17.0.2", - "react-i18next": "13.5.0", - "react-router-dom": "^6.3.0", - "react-toastify": "6.0.6", - "react-virtualized": "9.21.2", - "reactour": "1.18.0", - "semver": "^7.5.2", - "styled-components": "5.1.1" - }, - "devDependencies": { - "@storybook/addon-actions": "7.5.3", - "@storybook/addon-docs": "7.5.3", - "@storybook/addon-links": "7.5.3", - "@storybook/addons": "7.5.3", - "@storybook/preset-create-react-app": "7.5.3", - "@storybook/react": "7.5.3", - "@storybook/react-webpack5": "7.5.3", - "@testing-library/jest-dom": "5.11.5", - "@testing-library/react": "11.1.1", - "@testing-library/user-event": "12.2.0", - "@types/big.js": "6.1.1", - "@types/d3": "7.4.3", - "@types/debug": "4.1.5", - "@types/file-saver": "2.0.1", - "@types/google-protobuf": "3.15.10", - "@types/history": "4.7.6", - "@types/jest": "27.4.1", - "@types/lodash": "4.14.157", - "@types/node": "14.0.14", - "@types/react": "17.0.13", - "@types/react-dom": "17.0.8", - "@types/react-router-dom": "^5.3.3", - "@types/react-virtualized": "9.21.10", - "@types/reactour": "1.17.1", - "@types/semver": "^7.3.9", - "@typescript-eslint/eslint-plugin": "5.17.0", - "@typescript-eslint/parser": "5.17.0", - "cross-env": "7.0.2", - "eslint-config-prettier": "8.5.0", - "eslint-plugin-prettier": "4.0.0", - "eslint-plugin-react": "7.29.4", - "google-protobuf": "3.14.0", - "jest-canvas-mock": "2.3.0", - "jest-environment-jsdom": "27.5.1", - "prettier": "2.1.2", - "protoc-gen-js": "3.21.2", - "react-scripts": "^5.0.1", - "sass": "1.43.4", - "storybook": "7.5.3", - "ts-protoc-gen": "0.15.0", - "typescript": "4.1.6", - "webpack": "5.89.0" - }, - "resolutions": { - "strip-ansi": "6.0.1", - "jackspeak": "2.1.1", - "wrap-ansi": "7.0.0" - }, - "eslintConfig": { - "extends": "react-app", - "ignorePatterns": [ - "src/types/generated/**/*.js" - ] - }, - "jest": { - "globalSetup": "./src/setupTestsGlobal.ts", - "resetMocks": false, - "collectCoverageFrom": [ - "src/**/*.{js,jsx,ts,tsx}", - "!src/**/*.d.ts", - "!src/__(stories|mocks)__/**/*.{ts,tsx}", - "!src/types/**/*.{js,ts}", - "!src/i18n/**/*.{js,ts}", - "!src/util/tests/**/*.{ts,tsx}", - "!src/setupProxy.js", - "!src/index.tsx" - ] - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - } -} diff --git a/pkgs/by-name/li/lightning-terminal/package.nix b/pkgs/by-name/li/lightning-terminal/package.nix index 1918a87752c4..bb987952bc06 100644 --- a/pkgs/by-name/li/lightning-terminal/package.nix +++ b/pkgs/by-name/li/lightning-terminal/package.nix @@ -79,7 +79,7 @@ buildGoModule rec { pname = "lightning-app"; src = "${src}/app"; version = "0.0.1"; - packageJSON = ./package.json; + packageJSON = "${src}/app/package.json"; yarnLock = "${src}/app/yarn.lock"; offlineCache = fetchYarnDeps { yarnLock = "${src}/app/yarn.lock"; From 0a419572969eff6ebcf90ce5d6af1c67df11faaa Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Fri, 20 Jun 2025 03:09:55 -0300 Subject: [PATCH 2/2] 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. --- .../by-name/li/lightning-terminal/package.nix | 79 ++++++++++++++++--- 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/pkgs/by-name/li/lightning-terminal/package.nix b/pkgs/by-name/li/lightning-terminal/package.nix index bb987952bc06..f656f0670ead 100644 --- a/pkgs/by-name/li/lightning-terminal/package.nix +++ b/pkgs/by-name/li/lightning-terminal/package.nix @@ -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" ]; }; }