20 yarnHash = "sha256-C5CI8oP9vEana3OEs1yAsSSTvO2uLEuCU1nHhC7LerY=";
22 src = fetchFromGitHub {
23 owner = "pgadmin-org";
25 rev = "REL-${lib.versions.major version}_${lib.versions.minor version}";
26 hash = "sha256-OIFHaU+Ty0xJn42iqYhse8dfFJZpx8AV/10RNxp1Y4o=";
29 # keep the scope, as it is used throughout the derivation and tests
30 # this also makes potential future overrides easier
31 pythonPackages = python3.pkgs.overrideScope (final: prev: rec { });
33 offlineCache = fetchYarnDeps {
34 yarnLock = ./yarn.lock;
38 # don't bother to test kerberos authentication
39 # skip tests on macOS which fail due to an error in keyring, see https://github.com/NixOS/nixpkgs/issues/281214
40 skippedTests = builtins.concatStringsSep "," (
41 [ "browser.tests.test_kerberos_with_mocking" ]
42 ++ lib.optionals stdenv.hostPlatform.isDarwin [
43 "browser.server_groups.servers.tests.test_all_server_get"
44 "browser.server_groups.servers.tests.test_check_connect"
45 "browser.server_groups.servers.tests.test_check_ssh_mock_connect"
46 "browser.server_groups.servers.tests.test_is_password_saved"
51 pythonPackages.buildPythonApplication rec {
52 inherit pname version src;
55 CPPFLAGS = "-DPNG_ARM_NEON_OPT=0";
57 format = "setuptools";
60 # Expose setup.py for later use
61 ./expose-setup.py.patch
62 # check for permission of /etc/pgadmin/config_system and don't fail
63 ./check-system-config-dir.patch
67 # patching Makefile, so it doesn't try to build sphinx documentation here
69 substituteInPlace Makefile \
70 --replace-fail 'LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 $(MAKE) -C docs/en_US -f Makefile.sphinx html' "true"
72 # fix document which refers a non-existing document and fails
73 substituteInPlace docs/en_US/contributions.rst \
74 --replace-fail "code_snippets" ""
76 sed 's|==|>=|g' -i requirements.txt
77 # fix extra_require error with "*" in match
78 sed 's|*|0|g' -i requirements.txt
79 # remove packageManager from package.json so we can work without corepack
80 substituteInPlace web/package.json \
81 --replace-fail "\"packageManager\": \"yarn@3.8.3\"" "\"\": \"\""
82 substituteInPlace pkg/pip/setup_pip.py \
83 --replace-fail "req = req.replace('psycopg[c]', 'psycopg[binary]')" "req = req"
84 ${lib.optionalString (!server-mode) ''
85 substituteInPlace web/config.py \
86 --replace-fail "SERVER_MODE = True" "SERVER_MODE = False"
91 # Adapted from pkg/pip/build.sh
92 echo Creating required directories...
93 mkdir -p pip-build/pgadmin4/docs
95 echo Building the documentation
97 sphinx-build -W -b html -d _build/doctrees . _build/html
99 # Build the clean tree
101 cp -r * ../pip-build/pgadmin4/docs
102 for DIR in `ls -d ??_??/`
104 if [ -d ''${DIR}_build/html ]; then
105 mkdir -p ../pip-build/pgadmin4/docs/''${DIR}_build
106 cp -R ''${DIR}_build/html ../pip-build/pgadmin4/docs/''${DIR}_build
111 # mkYarnModules and mkYarnPackage have problems running the webpacker
112 echo Building the web frontend...
114 export HOME="$TMPDIR"
115 yarn config --offline set yarn-offline-mirror "${offlineCache}"
116 # replace with converted yarn.lock file
118 cp ${./yarn.lock} yarn.lock
120 fixup-yarn-lock yarn.lock
121 yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
122 patchShebangs node_modules/
124 cp -r * ../pip-build/pgadmin4
125 # save some disk space
126 rm -rf ../pip-build/pgadmin4/node_modules
130 echo Creating distro config...
131 echo HELP_PATH = \'../../docs/en_US/_build/html/\' > pip-build/pgadmin4/config_distro.py
132 echo MINIFY_HTML = False >> pip-build/pgadmin4/config_distro.py
134 echo Creating manifest...
135 echo recursive-include pgadmin4 \* > pip-build/MANIFEST.in
137 echo Building wheel...
139 # copy non-standard setup.py to local directory
140 # so setuptools-build-hook can call it
141 cp -v ../pkg/pip/setup_pip.py setup.py
144 nativeBuildInputs = with pythonPackages; [
157 propagatedBuildInputs = with pythonPackages; [
193 azure-mgmt-subscription
197 sphinxcontrib-youtube
202 google-api-python-client
212 inherit (nixosTests) pgadmin4;
215 nativeCheckInputs = [
218 pythonPackages.testscenarios
219 pythonPackages.selenium
222 # sandboxing issues on aarch64-darwin, see https://github.com/NixOS/nixpkgs/issues/198495
223 doCheck = postgresql.doCheck;
230 # pgadmin needs a home directory to save the configuration
234 # set configuration for postgresql test
235 # also ensure Server Mode is set to false. If not, the tests will fail, since pgadmin expects read/write permissions
236 # in /var/lib/pgadmin and /var/log/pgadmin
237 # see https://github.com/pgadmin-org/pgadmin4/blob/fd1c26408bbf154fa455a49ee5c12895933833a3/web/regression/runtests.py#L217-L226
238 cp -v regression/test_config.json.in regression/test_config.json
239 substituteInPlace regression/test_config.json --replace-fail "localhost" "$PGHOST"
240 substituteInPlace regression/runtests.py --replace-fail "builtins.SERVER_MODE = None" "builtins.SERVER_MODE = False"
243 python regression/runtests.py --pkg browser --exclude ${skippedTests}
245 ## Reverse engineered SQL test ##
247 python regression/runtests.py --pkg resql
253 description = "Administration and development platform for PostgreSQL${
254 lib.optionalString (!server-mode) ". Desktop Mode"
257 pgAdmin 4 is designed to meet the needs of both novice and experienced Postgres users alike,
258 providing a powerful graphical interface that simplifies the creation, maintenance and use of database objects.
262 This version is build with SERVER_MODE set to True (the default). It will require access to `/var/lib/pgadmin`
263 and `/var/log/pgadmin`. This is the default version for the NixOS module `services.pgadmin`.
264 This should NOT be used in combination with the `pgadmin4-desktopmode` package as they will interfere.
268 This version is build with SERVER_MODE set to False. It will require access to `~/.pgadmin/`. This version is suitable
269 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).
270 This should NOT be used in combination with the NixOS module `pgadmin` as they will interfere.
274 homepage = "https://www.pgadmin.org/";
275 license = lib.licenses.mit;
276 changelog = "https://www.pgadmin.org/docs/pgadmin4/latest/release_notes_${lib.versions.major version}_${lib.versions.minor version}.html";
277 maintainers = with lib.maintainers; [ gador ];
278 mainProgram = "pgadmin4";
279 platforms = lib.platforms.unix;