Merge pull request #234124 from tie/pufferpanel-frontend

pufferpanel: build frontend from source
This commit is contained in:
Sandro 2023-07-17 23:48:25 +02:00 committed by GitHub
commit 27eb2708d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,43 +1,40 @@
{ lib
, buildGoModule
, fetchFromGitHub
, makeWrapper
, fetchzip
, fetchpatch
, pathDeps ? [ ]
, applyPatches
, buildGoModule
, buildNpmPackage
, makeWrapper
, go-swag
, nixosTests
}:
buildGoModule rec {
pname = "pufferpanel";
version = "2.6.6";
version = "2.6.7";
patches = [
# Bump go-sqlite3 version to avoid a GNU C compiler error.
(fetchpatch {
url = "https://github.com/PufferPanel/PufferPanel/commit/dd7fc80c33c7618c98311af09c78c25b77658aef.patch";
hash = "sha256-ygMrhJoba8swoRBBii7BEiLihqOebLUtSH7os7W3s+k=";
})
src = applyPatches {
src = fetchFromGitHub {
owner = "PufferPanel";
repo = "PufferPanel";
rev = "v${version}";
hash = "sha256-ay9NNcK+6QFobe/rwtZF8USl0vMbDZBg5z57fjA5VLw=";
};
patches = [
# Bump sha1cd package, otherwise i686-linux fails to build.
./bump-sha1cd.patch
# Fix errors in tests.
(fetchpatch {
url = "https://github.com/PufferPanel/PufferPanel/commit/ad6ab4b4368e1111292fadfb3d9f058fa399fa21.patch";
hash = "sha256-BzGfcWhzRrCHKkAhWf0uvXiiiutWqthn/ed7bN2hR8U=";
})
# Seems to be an anti-feature. Startup is the only place where user/group is
# hardcoded and checked.
#
# There is no technical reason PufferPanel cannot run as a different user,
# especially for simple commands like `pufferpanel version`.
./disable-group-checks.patch
# Bump sha1cd package, otherwise i686-linux fails to build.
./bump-sha1cd.patch
# Seems to be an anti-feature. Startup is the only place where user/group is
# hardcoded and checked.
#
# There is no technical reason PufferPanel cannot run as a different user,
# especially for simple commands like `pufferpanel version`.
./disable-group-checks.patch
# Some tests do not have network requests stubbed :(
./skip-network-tests.patch
];
# Some tests do not have network requests stubbed :(
./skip-network-tests.patch
];
};
ldflags = [
"-s"
@ -46,50 +43,50 @@ buildGoModule rec {
"-X=github.com/pufferpanel/pufferpanel/v2.Version=${version}-nixpkgs"
];
src = fetchFromGitHub {
owner = "pufferpanel";
repo = pname;
rev = "v${version}";
hash = "sha256-0Vyi47Rkpe3oODHfsl/7tCerENpiEa3EWBHhfTO/uu4=";
frontend = buildNpmPackage {
pname = "pufferpanel-frontend";
inherit version;
src = "${src}/client";
npmDepsHash = "sha256-oWFXtV/dxzHv3sfIi01l1lHE5tcJgpVq87XgS6Iy62g=";
NODE_OPTIONS = "--openssl-legacy-provider";
npmBuildFlags = [ "--" "--dest=${placeholder "out"}" ];
dontNpmInstall = true;
};
# PufferPanel is split into two parts: the backend daemon and the
# frontend.
# Getting the frontend to build in the Nix environment fails even
# with all the proper node_modules populated. To work around this,
# we just download the built frontend and package that.
frontend = fetchzip {
url = "https://github.com/PufferPanel/PufferPanel/releases/download/v${version}/pufferpanel_${version}_linux_arm64.zip";
hash = "sha256-z7HWhiEBma37OMGEkTGaEbnF++Nat8wAZE2UeOoaO/U=";
stripRoot = false;
postFetch = ''
mv $out $TMPDIR/subdir
mv $TMPDIR/subdir/www $out
'';
};
nativeBuildInputs = [ makeWrapper ];
nativeBuildInputs = [ makeWrapper go-swag ];
vendorHash = "sha256-Esfk7SvqiWeiobXSI+4wYVEH9yVkB+rO7bxUQ5TzvG4=";
proxyVendor = true;
postFixup = ''
mkdir -p $out/share/pufferpanel
cp -r ${src}/assets/email $out/share/pufferpanel/templates
cp -r ${frontend} $out/share/pufferpanel/www
# Generate code for Swagger documentation endpoints (see web/swagger/docs.go).
# Note that GOROOT embedded in go-swag is empty by default since it is built
# with -trimpath (see https://go.dev/cl/399214). It looks like go-swag skips
# file paths that start with $GOROOT, thus all files when it is empty.
preBuild = ''
GOROOT=''${GOROOT-$(go env GOROOT)} swag init --output web/swagger --generalInfo web/loader.go
'';
# Rename cmd to pufferpanel and remove other binaries.
mv $out/bin $TMPDIR/bin
mkdir $out/bin
mv $TMPDIR/bin/cmd $out/bin/pufferpanel
installPhase = ''
runHook preInstall
# Set up directory structure similar to the official PufferPanel releases.
mkdir -p $out/share/pufferpanel
cp "$GOPATH"/bin/cmd $out/share/pufferpanel/pufferpanel
cp -r $frontend $out/share/pufferpanel/www
cp -r $src/assets/email $out/share/pufferpanel/email
cp web/swagger/swagger.{json,yaml} $out/share/pufferpanel
# Wrap the binary with the path to the external files, but allow setting
# custom paths if needed.
wrapProgram $out/bin/pufferpanel \
makeWrapper $out/share/pufferpanel/pufferpanel $out/bin/pufferpanel \
--set-default GIN_MODE release \
--set-default PUFFER_PANEL_EMAIL_TEMPLATES $out/share/pufferpanel/templates/emails.json \
--set-default PUFFER_PANEL_WEB_FILES $out/share/pufferpanel/www \
--prefix PATH : ${lib.escapeShellArg (lib.makeBinPath pathDeps)}
--set-default PUFFER_PANEL_EMAIL_TEMPLATES $out/share/pufferpanel/email/emails.json \
--set-default PUFFER_PANEL_WEB_FILES $out/share/pufferpanel/www
runHook postInstall
'';
passthru.tests = {