|
528 | 528 | pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
|
529 | 529 | supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
|
530 | 530 | pg_regress = basePackages.pg_regress;
|
| 531 | + tmpDirCmd = if pkgs.stdenv.isDarwin then |
| 532 | + "$(pwd)/postgres-tmp" |
| 533 | + else |
| 534 | + "mktemp -d"; |
531 | 535 | in
|
532 | 536 | pkgs.runCommand "postgres-${pgpkg.version}-check-harness"
|
533 | 537 | {
|
534 | 538 | nativeBuildInputs = with pkgs; [ coreutils bash pgpkg pg_prove pg_regress procps supabase-groonga ];
|
535 | 539 | } ''
|
536 |
| - TMPDIR=$(mktemp -d) |
| 540 | + $WORKDIR=$(${tmpDirCmd}) |
537 | 541 | if [ $? -ne 0 ]; then
|
538 | 542 | echo "Failed to create temp directory" >&2
|
539 | 543 | exit 1
|
540 | 544 | fi
|
541 | 545 |
|
| 546 | + chmod 700 "$WORKDIR" |
| 547 | +
|
542 | 548 | # Ensure the temporary directory is removed on exit
|
543 |
| - trap 'rm -rf "$TMPDIR"' EXIT |
| 549 | + #trap 'rm -rf "$WORKDIR"' EXIT |
544 | 550 |
|
545 |
| - export PGDATA="$TMPDIR/pgdata" |
546 |
| - export PGSODIUM_DIR="$TMPDIR/pgsodium" |
| 551 | + export PGDATA="$WORKDIR/pgdata" |
| 552 | + export PGSODIUM_DIR="$WORKDIR/pgsodium" |
547 | 553 |
|
548 | 554 | mkdir -p $PGDATA
|
549 |
| - mkdir -p $TMPDIR/logfile |
| 555 | + mkdir -p $WORKDIR/logfile |
550 | 556 | # Generate a random key and store it in an environment variable
|
551 | 557 | export PGSODIUM_KEY=$(head -c 32 /dev/urandom | od -A n -t x1 | tr -d ' \n')
|
552 | 558 | export GRN_PLUGINS_DIR=${supabase-groonga}/lib/groonga/plugins
|
553 | 559 | # Create a simple script to echo the key
|
554 |
| - echo '#!/bin/sh' > $TMPDIR/getkey.sh |
555 |
| - echo 'echo $PGSODIUM_KEY' >> $TMPDIR/getkey.sh |
556 |
| - chmod +x $TMPDIR/getkey.sh |
| 560 | + echo '#!/bin/sh' > $WORKDIR/getkey.sh |
| 561 | + echo 'echo $PGSODIUM_KEY' >> $WORKDIR/getkey.sh |
| 562 | + chmod +x $WORKDIR/getkey.sh |
557 | 563 | initdb --locale=C --username=supabase_admin
|
558 | 564 | substitute ${./nix/tests/postgresql.conf.in} $PGDATA/postgresql.conf \
|
559 |
| - --subst-var-by PGSODIUM_GETKEY_SCRIPT "$TMPDIR/getkey.sh" |
| 565 | + --subst-var-by PGSODIUM_GETKEY_SCRIPT "$WORKDIR/getkey.sh" |
560 | 566 | echo "listen_addresses = '*'" >> $PGDATA/postgresql.conf
|
561 | 567 | echo "port = 5432" >> $PGDATA/postgresql.conf
|
562 | 568 | echo "host all all 127.0.0.1/32 trust" >> $PGDATA/pg_hba.conf
|
563 |
| - #postgres -D "$PGDATA" -k "$TMPDIR" -h localhost -p 5432 >$TMPDIR/logfile/postgresql.log 2>&1 & |
564 |
| - pg_ctl -D "$PGDATA" -l $TMPDIR/logfile/postgresql.log -o "-k $TMPDIR -p 5432" start |
| 569 | + #postgres -D "$PGDATA" -k "$WORKDIR" -h localhost -p 5432 >$WORKDIR/logfile/postgresql.log 2>&1 & |
| 570 | + pg_ctl -D "$PGDATA" -l $WORKDIR/logfile/postgresql.log -o "-k $WORKDIR -p 5432" start |
565 | 571 | for i in {1..60}; do
|
566 | 572 | if pg_isready -h localhost -p 5432; then
|
567 | 573 | echo "PostgreSQL is ready"
|
|
573 | 579 | echo "PostgreSQL status:"
|
574 | 580 | pg_ctl -D "$PGDATA" status
|
575 | 581 | echo "PostgreSQL log content:"
|
576 |
| - cat $TMPDIR/logfile/postgresql.log |
| 582 | + cat $WORKDIR/logfile/postgresql.log |
577 | 583 | exit 1
|
578 | 584 | fi
|
579 | 585 | done
|
580 | 586 | createdb -p 5432 -h localhost --username=supabase_admin testing
|
581 | 587 | if ! psql -p 5432 -h localhost --username=supabase_admin -d testing -v ON_ERROR_STOP=1 -Xaf ${./nix/tests/prime.sql}; then
|
582 | 588 | echo "Error executing SQL file. PostgreSQL log content:"
|
583 |
| - cat $TMPDIR/logfile/postgresql.log |
| 589 | + cat $WORKDIR/logfile/postgresql.log |
584 | 590 | pg_ctl -D "$PGDATA" stop
|
585 | 591 | exit 1
|
586 | 592 | fi
|
|
598 | 604 | $(ls ${./nix/tests/sql} | sed -e 's/\..*$//' | sort )
|
599 | 605 |
|
600 | 606 | pg_ctl -D "$PGDATA" stop
|
601 |
| - mv $TMPDIR/logfile/postgresql.log $out |
| 607 | + mv $WORKDIR/logfile/postgresql.log $out |
602 | 608 | echo ${pgpkg}
|
603 | 609 | '';
|
604 | 610 | in
|
|
0 commit comments