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