Skip to content

Commit

Permalink
pgadmin4: use new yarnBerry3ConfigHook
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Brandes <[email protected]>
  • Loading branch information
gador committed Nov 12, 2024
1 parent 379aa01 commit e2615ea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12,017 deletions.
71 changes: 39 additions & 32 deletions pkgs/tools/admin/pgadmin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
nixosTests,
postgresqlTestHook,
postgresql,
yarn,
fixup-yarn-lock,
yarnBerry3ConfigHook,
nodejs,
stdenv,
server-mode ? true,
Expand All @@ -17,7 +16,7 @@
let
pname = "pgadmin";
version = "8.12";
yarnHash = "sha256-C5CI8oP9vEana3OEs1yAsSSTvO2uLEuCU1nHhC7LerY=";
yarnHash = "sha256-S8+9hvTyfWpjmoCAo6cJb5Eu8JJVoIvZ4UTnf/QfyUs=";

src = fetchFromGitHub {
owner = "pgadmin-org";
Expand All @@ -26,15 +25,16 @@ let
hash = "sha256-OIFHaU+Ty0xJn42iqYhse8dfFJZpx8AV/10RNxp1Y4o=";
};

yarnOfflineCache = fetchYarnDeps {
src = "${src}/web";
yarnVersion = 3;
hash = yarnHash;
};

# 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 "," (
Expand All @@ -46,6 +46,22 @@ let
"browser.server_groups.servers.tests.test_is_password_saved"
]
);

frontend = stdenv.mkDerivation {
inherit version yarnOfflineCache;
name = "pgadmin4-frontend";
src = "${src}/web";

nativeBuildInputs = [ yarnBerry3ConfigHook ];

installPhase = ''
runHook preInstall
yarn webpacker
mkdir -p $out
mv * $out/
runHook postInstall
'';
};
in

pythonPackages.buildPythonApplication rec {
Expand Down Expand Up @@ -76,9 +92,6 @@ pythonPackages.buildPythonApplication rec {
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\": \"[email protected]\"" "\"\": \"\""
substituteInPlace pkg/pip/setup_pip.py \
--replace-fail "req = req.replace('psycopg[c]', 'psycopg[binary]')" "req = req"
${lib.optionalString (!server-mode) ''
Expand Down Expand Up @@ -108,24 +121,17 @@ pythonPackages.buildPythonApplication rec {
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
cp -r ${frontend}/* pip-build/pgadmin4
# copy our patched files
chmod +w pip-build/pgadmin4/config.py
cp -a web/config.py pip-build/pgadmin4/
chmod +w pip-build/pgadmin4/pgadmin/model/__init__.py
cp -a web/pgadmin/model/__init__.py pip-build/pgadmin4/pgadmin/model/
chmod +w pip-build/pgadmin4/pgadmin/evaluate_config.py
cp -a web/pgadmin/evaluate_config.py pip-build/pgadmin4/pgadmin/
# save some disk space
rm -rf ../pip-build/pgadmin4/node_modules
cd ..
chmod -R +w pip-build/pgadmin4/node_modules
rm -rf pip-build/pgadmin4/node_modules
echo Creating distro config...
echo HELP_PATH = \'../../docs/en_US/_build/html/\' > pip-build/pgadmin4/config_distro.py
Expand All @@ -145,8 +151,6 @@ pythonPackages.buildPythonApplication rec {
cython
pip
sphinx
yarn
fixup-yarn-lock
nodejs
];
buildInputs = [
Expand Down Expand Up @@ -208,8 +212,10 @@ pythonPackages.buildPythonApplication rec {
setuptools
];

passthru.tests = {
inherit (nixosTests) pgadmin4;
passthru = {
tests = {
inherit (nixosTests) pgadmin4;
};
};

nativeCheckInputs = [
Expand All @@ -235,6 +241,7 @@ pythonPackages.buildPythonApplication rec {
# 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
chmod -R +w regression
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"
Expand Down
62 changes: 8 additions & 54 deletions pkgs/tools/admin/pgadmin/update.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl wget jq yq common-updater-scripts prefetch-yarn-deps yarn-lock-converter
#!nix-shell -i bash -p curl wget jq yq common-updater-scripts yarn-berry3

set -eu -o pipefail

TMPDIR=/tmp/pgadmin-update-script

################################################################
# This script will update pgadmin4 in nixpkgs #
# Due to recent changes upstream, we will need to convert the #
# `yarn.lock` file back to version 1. #
# This isn't trivially done and relies on 3rd party tools #
# and a hand-written converter (in this script). #
# Also, the converter cannot check for `github` repos in the #
# `yarn.lock` file, which this script will add automatically #
# #
################################################################

cleanup() {
Expand Down Expand Up @@ -52,56 +47,15 @@ wget -c $url
tar -xzf "pgadmin4-$newest_version.tar.gz"
cd "pgadmin4-$newest_version/web"

printf "Will now convert the v2 lockfile. This will download the npm packages to get the metadata.\n"
printf "Please note: This will take some time! For details, see the logfile ${TMPDIR}/update.log\n"
yarn-lock-converter -i yarn.lock -o yarn_v1.lock --cache .cache > $TMPDIR/update.log
printf "Conversion done\n"
export YARN_ENABLE_TELEMETRY=0
yarn config set enableGlobalCache false
yarn config set cacheFolder cache
yarn config set supportedArchitectures --json '{ "os": [ "darwin", "linux" ], "cpu": [ "arm", "arm64", "ia32", "x64" ], "libc": [ "glibc", "musl" ] }'

printf "Will now do some regex substitution post-processing\n"
sed -i -E "s|(.), |\1\", \"|g" yarn_v1.lock
sed -i -E "s|npm:||g" yarn_v1.lock
printf "Substituion done\n"

printf "Will now add missing github packages back to the v1 yarn.lock file\n"
# remove header
tail +8 yarn.lock > yarn_mod.lock
LENGTH=$(yq '. | with_entries(select(.value.resolution | contains("github"))) | keys | length' yarn_mod.lock)
for i in $(seq 0 $(($LENGTH-1)));
do
ENTRY=$(yq ". | with_entries(select(.value.resolution | contains(\"github\"))) | keys | .[$i]" yarn_mod.lock)
URL=$(echo $ENTRY | cut -d "@" -f 2)
VERSION=$(yq ".$ENTRY.version" yarn_mod.lock)
LENGTH_DEP=$(yq ".$ENTRY.dependencies | keys | length" yarn_mod.lock)
echo "$ENTRY:" >> adendum.lock
echo " version $VERSION" >> adendum.lock
echo " resolved \"$URL" >> adendum.lock
echo " dependencies:" >> adendum.lock

for j in $(seq 0 $(($LENGTH_DEP-1)));
do
DEPENDENCY_KEY=$(yq ".$ENTRY.dependencies | keys | .[$j]" yarn_mod.lock)
DEPENDENCY_VALUE=$(yq ".$ENTRY.dependencies.$DEPENDENCY_KEY" yarn_mod.lock)
# remove '"'
DEPENDENCY_KEY=${DEPENDENCY_KEY//\"}
echo " \"$DEPENDENCY_KEY\" $DEPENDENCY_VALUE" >> adendum.lock
done
done

echo "" >> yarn_v1.lock
cat adendum.lock >> yarn_v1.lock
yarn install --immutable --mode skip-build
printf "Done\n"

rm yarn.lock
mv yarn_v1.lock yarn.lock

printf "Will now generate the hash. This will download the packages to the nix store and also take some time\n"
YARN_HASH=$(prefetch-yarn-deps yarn.lock)
YARN_HASH=$(nix hash to-sri --type sha256 "$YARN_HASH")
printf "Done\n"

printf "Copy files to nixpkgs\n"
cp yarn.lock "$nixpkgs/pkgs/tools/admin/pgadmin/"
printf "Done\n"
YARN_HASH=$(nix hash path cache)
popd

sed -i -E -e "s#yarnHash = \".*\"#yarnHash = \"$YARN_HASH\"#" ${scriptDir}/default.nix
Expand Down
Loading

0 comments on commit e2615ea

Please sign in to comment.