diff options
Diffstat (limited to 'nixpkgs/pkgs/tools/admin/pgadmin/default.nix')
-rw-r--r-- | nixpkgs/pkgs/tools/admin/pgadmin/default.nix | 254 |
1 files changed, 159 insertions, 95 deletions
diff --git a/nixpkgs/pkgs/tools/admin/pgadmin/default.nix b/nixpkgs/pkgs/tools/admin/pgadmin/default.nix index dadd79824927..0c54f6759152 100644 --- a/nixpkgs/pkgs/tools/admin/pgadmin/default.nix +++ b/nixpkgs/pkgs/tools/admin/pgadmin/default.nix @@ -1,88 +1,38 @@ { lib , python3 -, fetchurl +, fetchFromGitHub +, fetchYarnDeps , zlib -, mkYarnModules -, sphinx , nixosTests -, pkgs +, postgresqlTestHook +, postgresql +, yarn +, fixup_yarn_lock +, nodejs +, server-mode ? true }: let pname = "pgadmin"; - version = "6.12"; - - src = fetchurl { - url = "https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v${version}/source/pgadmin4-${version}.tar.gz"; - sha256 = "sha256-cO7GdZDfJ0pq1jpMyrVy0UM49WhrKOIJOmMJauSkbyo="; + version = "7.3"; + yarnSha256 = "sha256-gbFAeTB24EU0SWSAMnPus1rcgQmHcPySb6wXX3xKnvg="; + + src = fetchFromGitHub { + owner = "pgadmin-org"; + repo = "pgadmin4"; + rev = "REL-${lib.versions.major version}_${lib.versions.minor version}"; + hash = "sha256-7qdM/CkrSy9g85WhaG57O9uqHIwQIpOThHKxGs+U0dQ="; }; - yarnDeps = mkYarnModules { - pname = "${pname}-yarn-deps"; - inherit version; - packageJSON = ./package.json; + # 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; - yarnNix = ./yarn.nix; + hash = yarnSha256; }; - # move buildDeps here to easily pass to test suite - buildDeps = with pythonPackages; [ - flask - flask-gravatar - flask_login - flask_mail - flask_migrate - flask-sqlalchemy - flask-wtf - flask-compress - passlib - pytz - simplejson - six - sqlparse - wtforms - flask-paranoid - psutil - psycopg2 - python-dateutil - sqlalchemy - itsdangerous - flask-security-too - bcrypt - cryptography - sshtunnel - ldap3 - flask-babelex - flask-babel - gssapi - flask-socketio - eventlet - httpagentparser - user-agents - wheel - authlib - qrcode - pillow - pyotp - botocore - boto3 - azure-mgmt-subscription - azure-mgmt-rdbms - azure-mgmt-resource - azure-identity - ]; - - # override necessary on pgadmin4 6.12 - pythonPackages = python3.pkgs.overrideScope (final: prev: rec { - werkzeug = prev.werkzeug.overridePythonAttrs (oldAttrs: rec { - version = "2.0.3"; - src = oldAttrs.src.override { - inherit version; - sha256 = "sha256-uGP4/wV8UiFktgZ8niiwQRYbS+W6TQ2s7qpQoWOCLTw="; - }; - }); - }); - in pythonPackages.buildPythonApplication rec { @@ -96,6 +46,8 @@ pythonPackages.buildPythonApplication rec { 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 = '' @@ -111,10 +63,17 @@ pythonPackages.buildPythonApplication rec { # relax dependencies sed 's|==|>=|g' -i requirements.txt - # don't use Server Mode (can be overridden later) + #TODO: Can be removed once cryptography>=40 has been merged to master + substituteInPlace requirements.txt \ + --replace "cryptography>=40.0.*" "cryptography>=39.0.*" + # fix extra_require error with "*" in match + sed 's|*|0|g' -i requirements.txt substituteInPlace pkg/pip/setup_pip.py \ - --replace "req = req.replace('psycopg2', 'psycopg2-binary')" "req = req" \ - --replace "builtins.SERVER_MODE = None" "builtins.SERVER_MODE = False" + --replace "req = req.replace('psycopg[c]', 'psycopg[binary]')" "req = req" + ${lib.optionalString (!server-mode) '' + substituteInPlace web/config.py \ + --replace "SERVER_MODE = True" "SERVER_MODE = False" + ''} ''; preBuild = '' @@ -122,25 +81,40 @@ pythonPackages.buildPythonApplication rec { echo Creating required directories... mkdir -p pip-build/pgadmin4/docs - # build the documentation + echo Building the documentation cd docs/en_US - ${sphinx}/bin/sphinx-build -W -b html -d _build/doctrees . _build/html + sphinx-build -W -b html -d _build/doctrees . _build/html # Build the clean tree - cd ../../web - cp -r * ../pip-build/pgadmin4 - cd ../docs + 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 -Rv ''${DIR}_build/html ../pip-build/pgadmin4/docs/''${DIR}_build + cp -R ''${DIR}_build/html ../pip-build/pgadmin4/docs/''${DIR}_build fi done cd ../ - cp -r ${yarnDeps}/* pip-build/pgadmin4 + # 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 @@ -156,29 +130,119 @@ pythonPackages.buildPythonApplication rec { cp -v ../pkg/pip/setup_pip.py setup.py ''; - nativeBuildInputs = with pythonPackages; [ cython pip ]; + nativeBuildInputs = with pythonPackages; [ cython pip sphinx yarn fixup_yarn_lock nodejs ]; buildInputs = [ zlib pythonPackages.wheel ]; - # tests need an own data, log directory - # and a working and correctly setup postgres database - # checks will be run through nixos/tests - doCheck = false; - - # speaklater3 is seperate because when passing buildDeps - # to the test, it fails there due to a collision with speaklater - propagatedBuildInputs = buildDeps ++ [ pythonPackages.speaklater3 ]; + propagatedBuildInputs = with pythonPackages; [ + flask + flask-gravatar + 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-too + bcrypt + cryptography + sshtunnel + ldap3 + flask-babelex + flask-babel + gssapi + flask-socketio + eventlet + httpagentparser + 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 + ]; passthru.tests = { - standalone = nixosTests.pgadmin4-standalone; - # regression and function tests of the package itself - package = import ../../../../nixos/tests/pgadmin4.nix { inherit pkgs buildDeps; pythonEnv = pythonPackages; }; + inherit (nixosTests) pgadmin4; }; + nativeCheckInputs = [ + postgresqlTestHook + postgresql + pythonPackages.testscenarios + pythonPackages.selenium + ]; + + 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 "localhost" "$PGHOST" + substituteInPlace regression/runtests.py --replace "builtins.SERVER_MODE = None" "builtins.SERVER_MODE = False" + + ## Browser test ## + + # don't bother to test kerberos authentication + python regression/runtests.py --pkg browser --exclude browser.tests.test_kerberos_with_mocking + + ## Reverse engineered SQL test ## + + python regression/runtests.py --pkg resql + + runHook postCheck + ''; + meta = with lib; { - description = "Administration and development platform for PostgreSQL"; + description = "Administration and development platform for PostgreSQL${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. + This should NOT be used in combination with the NixOS module `pgadmin` as they will interfere. + ''} + ''; homepage = "https://www.pgadmin.org/"; license = licenses.mit; changelog = "https://www.pgadmin.org/docs/pgadmin4/latest/release_notes_${lib.versions.major version}_${lib.versions.minor version}.html"; |