1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
{
lib,
python3,
fetchFromGitHub,
fetchYarnDeps,
zlib,
nixosTests,
postgresqlTestHook,
postgresql,
yarn,
fixup-yarn-lock,
nodejs,
stdenv,
server-mode ? true,
}:
let
pname = "pgadmin";
version = "8.11";
yarnHash = "sha256-2N1UsGrR9rTIP50kn+gB+iGz9D/Dj0K5Y/10A5wPKTY=";
src = fetchFromGitHub {
owner = "pgadmin-org";
repo = "pgadmin4";
rev = "REL-${lib.versions.major version}_${lib.versions.minor version}";
hash = "sha256-6v7/jFkWooUHztL+x6falD04XyDYa1beoY/yEpfbX4U=";
};
# keep the scope, as it is used throughout the derivation and tests
# this also makes potential future overrides easier
pythonPackages = python3.pkgs.overrideScope (final: prev: rec { });
offlineCache = fetchYarnDeps {
yarnLock = ./yarn.lock;
hash = yarnHash;
};
# don't bother to test kerberos authentication
# skip tests on macOS which fail due to an error in keyring, see https://github.com/NixOS/nixpkgs/issues/281214
skippedTests = builtins.concatStringsSep "," (
[ "browser.tests.test_kerberos_with_mocking" ]
++ lib.optionals stdenv.isDarwin [
"browser.server_groups.servers.tests.test_all_server_get"
"browser.server_groups.servers.tests.test_check_connect"
"browser.server_groups.servers.tests.test_check_ssh_mock_connect"
"browser.server_groups.servers.tests.test_is_password_saved"
]
);
in
pythonPackages.buildPythonApplication rec {
inherit pname version src;
# from Dockerfile
CPPFLAGS = "-DPNG_ARM_NEON_OPT=0";
format = "setuptools";
patches = [
# Expose setup.py for later use
./expose-setup.py.patch
# check for permission of /etc/pgadmin/config_system and don't fail
./check-system-config-dir.patch
];
postPatch = ''
# patching Makefile, so it doesn't try to build sphinx documentation here
# (will do so later)
substituteInPlace Makefile \
--replace-fail 'LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 $(MAKE) -C docs/en_US -f Makefile.sphinx html' "true"
# fix document which refers a non-existing document and fails
substituteInPlace docs/en_US/contributions.rst \
--replace-fail "code_snippets" ""
# relax dependencies
sed 's|==|>=|g' -i requirements.txt
# fix extra_require error with "*" in match
sed 's|*|0|g' -i requirements.txt
# remove packageManager from package.json so we can work without corepack
substituteInPlace web/package.json \
--replace-fail "\"packageManager\": \"yarn@3.8.3\"" "\"\": \"\""
substituteInPlace pkg/pip/setup_pip.py \
--replace-fail "req = req.replace('psycopg[c]', 'psycopg[binary]')" "req = req"
${lib.optionalString (!server-mode) ''
substituteInPlace web/config.py \
--replace-fail "SERVER_MODE = True" "SERVER_MODE = False"
''}
'';
preBuild = ''
# Adapted from pkg/pip/build.sh
echo Creating required directories...
mkdir -p pip-build/pgadmin4/docs
echo Building the documentation
cd docs/en_US
sphinx-build -W -b html -d _build/doctrees . _build/html
# Build the clean tree
cd ..
cp -r * ../pip-build/pgadmin4/docs
for DIR in `ls -d ??_??/`
do
if [ -d ''${DIR}_build/html ]; then
mkdir -p ../pip-build/pgadmin4/docs/''${DIR}_build
cp -R ''${DIR}_build/html ../pip-build/pgadmin4/docs/''${DIR}_build
fi
done
cd ../
# mkYarnModules and mkYarnPackage have problems running the webpacker
echo Building the web frontend...
cd web
export HOME="$TMPDIR"
yarn config --offline set yarn-offline-mirror "${offlineCache}"
# replace with converted yarn.lock file
rm yarn.lock
cp ${./yarn.lock} yarn.lock
chmod +w yarn.lock
fixup-yarn-lock yarn.lock
yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
patchShebangs node_modules/
yarn webpacker
cp -r * ../pip-build/pgadmin4
# save some disk space
rm -rf ../pip-build/pgadmin4/node_modules
cd ..
echo Creating distro config...
echo HELP_PATH = \'../../docs/en_US/_build/html/\' > pip-build/pgadmin4/config_distro.py
echo MINIFY_HTML = False >> pip-build/pgadmin4/config_distro.py
echo Creating manifest...
echo recursive-include pgadmin4 \* > pip-build/MANIFEST.in
echo Building wheel...
cd pip-build
# copy non-standard setup.py to local directory
# so setuptools-build-hook can call it
cp -v ../pkg/pip/setup_pip.py setup.py
'';
nativeBuildInputs = with pythonPackages; [
cython
pip
sphinx
yarn
fixup-yarn-lock
nodejs
];
buildInputs = [
zlib
pythonPackages.wheel
];
propagatedBuildInputs = with pythonPackages; [
flask
flask-login
flask-mail
flask-migrate
flask-sqlalchemy
flask-wtf
flask-compress
passlib
pytz
simplejson
sqlparse
wtforms
flask-paranoid
psutil
psycopg
python-dateutil
sqlalchemy
itsdangerous
flask-security
bcrypt
cryptography
sshtunnel
ldap3
flask-babel
gssapi
flask-socketio
eventlet
user-agents
wheel
authlib
qrcode
pillow
pyotp
botocore
boto3
azure-mgmt-subscription
azure-mgmt-rdbms
azure-mgmt-resource
azure-identity
sphinxcontrib-youtube
dnspython
greenlet
speaklater3
google-auth-oauthlib
google-api-python-client
keyring
typer
rich
jsonformatter
libgravatar
];
passthru.tests = {
inherit (nixosTests) pgadmin4;
};
nativeCheckInputs = [
postgresqlTestHook
postgresql
pythonPackages.testscenarios
pythonPackages.selenium
];
# sandboxing issues on aarch64-darwin, see https://github.com/NixOS/nixpkgs/issues/198495
doCheck = postgresql.doCheck;
checkPhase = ''
runHook preCheck
## Setup ##
# pgadmin needs a home directory to save the configuration
export HOME=$TMPDIR
cd pgadmin4
# set configuration for postgresql test
# also ensure Server Mode is set to false. If not, the tests will fail, since pgadmin expects read/write permissions
# in /var/lib/pgadmin and /var/log/pgadmin
# see https://github.com/pgadmin-org/pgadmin4/blob/fd1c26408bbf154fa455a49ee5c12895933833a3/web/regression/runtests.py#L217-L226
cp -v regression/test_config.json.in regression/test_config.json
substituteInPlace regression/test_config.json --replace-fail "localhost" "$PGHOST"
substituteInPlace regression/runtests.py --replace-fail "builtins.SERVER_MODE = None" "builtins.SERVER_MODE = False"
## Browser test ##
python regression/runtests.py --pkg browser --exclude ${skippedTests}
## Reverse engineered SQL test ##
python regression/runtests.py --pkg resql
runHook postCheck
'';
meta = {
description = "Administration and development platform for PostgreSQL${
lib.optionalString (!server-mode) ". Desktop Mode"
}";
longDescription = ''
pgAdmin 4 is designed to meet the needs of both novice and experienced Postgres users alike,
providing a powerful graphical interface that simplifies the creation, maintenance and use of database objects.
${
if server-mode then
''
This version is build with SERVER_MODE set to True (the default). It will require access to `/var/lib/pgadmin`
and `/var/log/pgadmin`. This is the default version for the NixOS module `services.pgadmin`.
This should NOT be used in combination with the `pgadmin4-desktopmode` package as they will interfere.
''
else
''
This version is build with SERVER_MODE set to False. It will require access to `~/.pgadmin/`. This version is suitable
for single-user deployment or where access to `/var/lib/pgadmin` cannot be granted or the NixOS module cannot be used (e.g. on MacOS).
This should NOT be used in combination with the NixOS module `pgadmin` as they will interfere.
''
}
'';
homepage = "https://www.pgadmin.org/";
license = lib.licenses.mit;
changelog = "https://www.pgadmin.org/docs/pgadmin4/latest/release_notes_${lib.versions.major version}_${lib.versions.minor version}.html";
maintainers = with lib.maintainers; [ gador ];
mainProgram = "pgadmin4";
platforms = lib.platforms.unix;
};
}
|