Skip to content

Commit 10ff832

Browse files
committed
pgadmin4: fix build for sandbox=relaxed builds on darwin
fixes: clang: error: no such file or directory: '/usr/local/lib/libpng16.a' on sandboxed darwin boxes 1. mozjpeg hasn't been updated since 2021. The newest commit from 2023 fixes the build on darwin but no new release was put forward (see imagemin/mozjpeg-bin#64 and imagemin/mozjpeg-bin#81) 2. This prompts to manually patching the yarn.lock file 3. Which also needs to split the yarnConfigHook logic and duplicate it in parts in the derivation The benefit is to be able to build pgadmin on aarch64-darwin without network. Signed-off-by: Florian Brandes <[email protected]>
1 parent 4279efe commit 10ff832

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

pkgs/tools/admin/pgadmin/default.nix

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
libtool,
1414
libpng,
1515
nasm,
16+
cmake,
1617
pkg-config,
1718
stdenv,
19+
srcOnly,
1820
server-mode ? true,
1921
}:
2022

2123
let
2224
pname = "pgadmin";
2325
version = "9.3";
24-
yarnHash = "sha256-75FwwQ67j0aTHGvD4YwAaR8CWV4u4KsuMghidbkgVsw=";
26+
yarnHash = "sha256-T6RKWuAAoJgbzJKef4ioOoUDtoGM9s9BFqxFdy5EtyQ=";
2527

2628
src = fetchFromGitHub {
2729
owner = "pgadmin-org";
@@ -30,6 +32,13 @@ let
3032
hash = "sha256-4uupF1dw6OE/briAI5PWiQ7h6RPx1sUqf8PB8cJsNSU=";
3133
};
3234

35+
mozjpeg-bin = fetchFromGitHub {
36+
owner = "imagemin";
37+
repo = "mozjpeg-bin";
38+
rev = "c0587fbc00b21ed8cad8bae499a0827baeaf7ffa";
39+
hash = "sha256-D/pXQBlIIyk7KAgxJ1gKqxYxtlfBbLzUSmYZbH659cA=";
40+
};
41+
3342
# keep the scope, as it is used throughout the derivation and tests
3443
# this also makes potential future overrides easier
3544
pythonPackages = python3.pkgs.overrideScope (final: prev: { });
@@ -51,6 +60,14 @@ pythonPackages.buildPythonApplication rec {
5160
inherit pname version src;
5261

5362
offlineCache = yarn-berry_3.fetchYarnBerryDeps {
63+
# mozjpeg fails to build on darwin due to a hardocded path
64+
# this has been fixed upstream on master but no new version
65+
# has been released. We therefore point yarn to upstream
66+
# see https://github.com/imagemin/mozjpeg-bin/issues/64
67+
# and https://github.com/imagemin/mozjpeg-bin/issues/81
68+
patches = [
69+
./mozjpeg.patch
70+
];
5471
src = src + "/web";
5572
hash = yarnHash;
5673
};
@@ -68,6 +85,11 @@ pythonPackages.buildPythonApplication rec {
6885
];
6986

7087
postPatch = ''
88+
# the patch needs to be executed inside the /web subfolder
89+
# therefore it is included here and not in `patches`
90+
cd web
91+
patch -u yarn.lock ${./mozjpeg.patch}
92+
cd ..
7193
# patching Makefile, so it doesn't try to build sphinx documentation here
7294
# (will do so later)
7395
substituteInPlace Makefile \
@@ -89,6 +111,8 @@ pythonPackages.buildPythonApplication rec {
89111
'';
90112

91113
dontYarnBerryInstallDeps = true;
114+
env.YARN_ENABLE_SCRIPTS = "0";
115+
dontUseCmakeConfigure = true;
92116

93117
preBuild = ''
94118
# Adapted from pkg/pip/build.sh
@@ -117,6 +141,25 @@ pythonPackages.buildPythonApplication rec {
117141
export LD=$CC # https://github.com/imagemin/optipng-bin/issues/108
118142
yarnBerryConfigHook
119143
)
144+
# mozjpeg vendored source isn't included in the checkout for yarn. If we copy it before the
145+
# yarnConfigHook it will just get overwritten. So we first run the configHook without build,
146+
# then copy the vendored source and then build the dependencies
147+
# This has the disadvantage of repeating some of the yarnConfigHooks logic here
148+
mkdir -p node_modules/mozjpeg/vendor/source
149+
cp ${mozjpeg-bin}/vendor/source/mozjpeg.tar.gz node_modules/mozjpeg/vendor/source/
150+
(
151+
# https://github.com/mozilla/mozjpeg/issues/438
152+
substituteInPlace node_modules/mozjpeg/lib/install.js --replace-fail "cmake -DCMAKE" "cmake -DENABLE_STATIC=FALSE -DCMAKE"
153+
substituteInPlace node_modules/mozjpeg/lib/install.js --replace-fail "cp cjpeg-static" "cp cjpeg"
154+
export LD=$CC
155+
export HOME=$(mktemp -d)
156+
export YARN_ENABLE_SCRIPTS=1
157+
YARN_IGNORE_PATH=1 ${yarn-berry_3.yarn-berry-offline}/bin/yarn config set enableTelemetry false
158+
YARN_IGNORE_PATH=1 ${yarn-berry_3.yarn-berry-offline}/bin/yarn config set enableGlobalCache false
159+
export npm_config_nodedir="${srcOnly nodejs}"
160+
export npm_config_node_gyp="${nodejs}/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js"
161+
YARN_IGNORE_PATH=1 ${yarn-berry_3.yarn-berry-offline}/bin/yarn install --inline-builds
162+
)
120163
yarn webpacker
121164
cp -r * ../pip-build/pgadmin4
122165
# save some disk space
@@ -147,6 +190,7 @@ pythonPackages.buildPythonApplication rec {
147190
nodejs
148191

149192
# for building mozjpeg2
193+
cmake
150194
autoconf
151195
automake
152196
libtool
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
diff --git a/yarn.lock b/yarn.lock
2+
index fa189ef..54066a6 100644
3+
--- a/yarn.lock
4+
+++ b/yarn.lock
5+
@@ -7299,6 +7299,23 @@ __metadata:
6+
languageName: node
7+
linkType: hard
8+
9+
+"execa@npm:^7.1.1":
10+
+ version: 7.1.1
11+
+ resolution: "execa@npm:7.1.1"
12+
+ dependencies:
13+
+ cross-spawn: ^7.0.3
14+
+ get-stream: ^6.0.1
15+
+ human-signals: ^3.0.1
16+
+ is-stream: ^3.0.0
17+
+ merge-stream: ^2.0.0
18+
+ npm-run-path: ^5.1.0
19+
+ onetime: ^6.0.0
20+
+ signal-exit: ^3.0.7
21+
+ strip-final-newline: ^3.0.0
22+
+ checksum: 21fa46fc69314ace4068cf820142bdde5b643a5d89831c2c9349479c1555bff137a291b8e749e7efca36535e4e0a8c772c11008ca2e84d2cbd6ca141a3c8f937
23+
+ languageName: node
24+
+ linkType: hard
25+
+
26+
"executable@npm:^4.1.0":
27+
version: 4.1.1
28+
resolution: "executable@npm:4.1.1"
29+
@@ -11027,13 +11044,14 @@ __metadata:
30+
31+
"mozjpeg@npm:^8.0.0":
32+
version: 8.0.0
33+
- resolution: "mozjpeg@npm:8.0.0"
34+
+ resolution: "mozjpeg@https://github.com/imagemin/mozjpeg-bin.git#commit=c0587fbc00b21ed8cad8bae499a0827baeaf7ffa"
35+
dependencies:
36+
bin-build: ^3.0.0
37+
bin-wrapper: ^4.0.0
38+
+ execa: ^7.1.1
39+
bin:
40+
mozjpeg: cli.js
41+
- checksum: cba27c2efbc21a48434da1c6c8d6886988432430f958315fc59ef9b52bc2d6ee597e19f1cf6aae0fd611d5b2a113561fe2e85ec30a1ccd55c007340c638eb557
42+
+ checksum: cba27c2efbc21a48434da1c6c8d6886988432430f958315fc59ef9b52bc2d6ee597e19f1cf6aae0fd611d5b2a113561fe2e85ec30a1ccd55c007340c638eb556
43+
languageName: node
44+
linkType: hard
45+

0 commit comments

Comments
 (0)