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