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" ]; }; }