From 2134950e0abb2a2cbcf8279883ff227a15648ef5 Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Thu, 19 Jun 2025 10:51:14 +0200 Subject: [PATCH 1/3] chore: add `treefmt` config for nix files * add a ci job that run `treefmt` * make it `nix fmt` default formatter * add dumb simple `pre-commit` and `editorconfig` --- .editorconfig | 12 ++++++++++++ .github/workflows/treefmt.yml | 15 +++++++++++++++ .gitignore | 2 +- .pre-commit-config.yaml | 8 ++++++++ flake.nix | 5 +++++ treefmt.toml | 5 +++++ 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/treefmt.yml create mode 100644 .pre-commit-config.yaml create mode 100644 treefmt.toml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..8e5e8509b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*.nix] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.github/workflows/treefmt.yml b/.github/workflows/treefmt.yml new file mode 100644 index 000000000..d7a4254af --- /dev/null +++ b/.github/workflows/treefmt.yml @@ -0,0 +1,15 @@ +name: treefmt +on: + pull_request: + push: + branches: develop +jobs: + formatter: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v31 + with: + nix_path: nixpkgs=channel:nixos-unstable + - name: treefmt + run: nix-shell -p treefmt nixpkgs-fmt --run "treefmt --ci" diff --git a/.gitignore b/.gitignore index d32cc8f60..647ebc601 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ __pycache__/ result* .env-local .history - +.envrc #IDE .idea/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..b22621683 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +repos: + - repo: local + hooks: + - id: treefmt + name: treefmt + entry: treefmt + language: system + types: [file] \ No newline at end of file diff --git a/flake.nix b/flake.nix index 18cd9ba13..26ce6db7d 100644 --- a/flake.nix +++ b/flake.nix @@ -1413,6 +1413,8 @@ trigger-nix-build = mkApp "trigger-nix-build" "trigger-nix-build"; }; + formatter = pkgs.treefmt; + # 'devShells.default' lists the set of packages that are included in the # ambient $PATH environment when you run 'nix develop'. This is useful # for development and puts many convenient devtools instantly within @@ -1456,7 +1458,10 @@ basePackages.run-testinfra basePackages.cleanup-ami dbmate + formatter # treefmt + nixpkgs-fmt nushell + pre-commit pythonEnv nix-fast-build ]; diff --git a/treefmt.toml b/treefmt.toml new file mode 100644 index 000000000..071cf03f2 --- /dev/null +++ b/treefmt.toml @@ -0,0 +1,5 @@ +# One CLI to format the code tree - https://github.com/numtide/treefmt + +[formatter.nix] +command = "nixpkgs-fmt" +includes = ["*.nix"] From 53aaea7dd28a2a7ed0a68178945a573241708b91 Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Thu, 19 Jun 2025 10:52:10 +0200 Subject: [PATCH 2/3] chore: format all nix files with `nixpkgs-fmt` --- flake.nix | 774 +++++++++++++------------- nix/cargo-pgrx/buildPgrxExtension.nix | 10 +- nix/cargo-pgrx/default.nix | 2 +- nix/ext/mecab-naist-jdic/default.nix | 6 +- nix/ext/pg-safeupdate.nix | 16 +- nix/ext/pg_backtrace.nix | 12 +- nix/ext/pg_cron.nix | 14 +- nix/ext/pg_graphql.nix | 16 +- nix/ext/pg_jsonschema.nix | 12 +- nix/ext/pg_partman.nix | 16 +- nix/ext/pg_tle.nix | 4 +- nix/ext/pgjwt.nix | 6 +- nix/ext/pgmq.nix | 12 +- nix/ext/pgroonga.nix | 6 +- nix/ext/pgrouting.nix | 20 +- nix/ext/pljava.nix | 14 +- nix/ext/plv8.nix | 21 +- nix/ext/postgis.nix | 37 +- nix/ext/sfcgal/sfcgal.nix | 2 +- nix/ext/wrappers/default.nix | 114 ++-- nix/postgresql/default.nix | 18 +- nix/postgresql/generic.nix | 506 +++++++++-------- nix/supabase-groonga.nix | 29 +- 23 files changed, 869 insertions(+), 798 deletions(-) diff --git a/flake.nix b/flake.nix index 26ce6db7d..a3d441ad1 100644 --- a/flake.nix +++ b/flake.nix @@ -171,7 +171,8 @@ x != ./nix/ext/timescaledb.nix && x != ./nix/ext/timescaledb-2.9.1.nix && x != ./nix/ext/plv8.nix - ) ourExtensions; + ) + ourExtensions; orioledbExtensions = orioleFilteredExtensions ++ [ ./nix/ext/orioledb.nix ]; dbExtensions17 = orioleFilteredExtensions; @@ -656,144 +657,144 @@ aws-vault ]; } '' - mkdir -p $out/bin - cat > $out/bin/build-test-ami << 'EOL' - #!/usr/bin/env bash - set -euo pipefail - - show_help() { - cat << EOF - Usage: build-test-ami [--help] + mkdir -p $out/bin + cat > $out/bin/build-test-ami << 'EOL' + #!/usr/bin/env bash + set -euo pipefail - Build AMI images for PostgreSQL testing. + show_help() { + cat << EOF + Usage: build-test-ami [--help] - This script will: - 1. Check for required tools and AWS authentication - 2. Build two AMI stages using Packer - 3. Clean up any temporary instances - 4. Output the final AMI name for use with run-testinfra + Build AMI images for PostgreSQL testing. - Arguments: - postgres-version PostgreSQL major version to build (required) + This script will: + 1. Check for required tools and AWS authentication + 2. Build two AMI stages using Packer + 3. Clean up any temporary instances + 4. Output the final AMI name for use with run-testinfra - Options: - --help Show this help message and exit + Arguments: + postgres-version PostgreSQL major version to build (required) - Requirements: - - AWS Vault profile must be set in AWS_VAULT environment variable - - Packer, AWS CLI, yq, jq, and OpenSSL must be installed - - Must be run from a git repository + Options: + --help Show this help message and exit - Example: - aws-vault exec -- nix run .#build-test-ami 15 - EOF - } + Requirements: + - AWS Vault profile must be set in AWS_VAULT environment variable + - Packer, AWS CLI, yq, jq, and OpenSSL must be installed + - Must be run from a git repository - # Handle help flag - if [[ "$#" -gt 0 && "$1" == "--help" ]]; then - show_help - exit 0 - fi + Example: + aws-vault exec -- nix run .#build-test-ami 15 + EOF + } - export PATH="${pkgs.lib.makeBinPath (with pkgs; [ - packer - awscli2 - yq - jq - openssl - git - coreutils - aws-vault - ])}:$PATH" + # Handle help flag + if [[ "$#" -gt 0 && "$1" == "--help" ]]; then + show_help + exit 0 + fi - # Check for required tools - for cmd in packer aws-vault yq jq openssl; do - if ! command -v $cmd &> /dev/null; then - echo "Error: $cmd is required but not found" - exit 1 - fi - done + export PATH="${pkgs.lib.makeBinPath (with pkgs; [ + packer + awscli2 + yq + jq + openssl + git + coreutils + aws-vault + ])}:$PATH" - # Check AWS Vault profile - if [ -z "''${AWS_VAULT:-}" ]; then - echo "Error: AWS_VAULT environment variable must be set with the profile name" - echo "Usage: aws-vault exec -- nix run .#build-test-ami " + # Check for required tools + for cmd in packer aws-vault yq jq openssl; do + if ! command -v $cmd &> /dev/null; then + echo "Error: $cmd is required but not found" exit 1 fi + done - # Set values - REGION="ap-southeast-1" - POSTGRES_VERSION="$1" - RANDOM_STRING=$(openssl rand -hex 8) - GIT_SHA=$(git rev-parse HEAD) - RUN_ID=$(date +%s) - - # Generate common-nix.vars.pkr.hcl - PG_VERSION=$(yq -r ".postgres_release[\"postgres$POSTGRES_VERSION\"]" ansible/vars.yml) - echo "postgres-version = \"$PG_VERSION\"" > common-nix.vars.pkr.hcl - - # Build AMI Stage 1 - packer init amazon-arm64-nix.pkr.hcl - packer build \ - -var "git-head-version=$GIT_SHA" \ - -var "packer-execution-id=$RUN_ID" \ - -var-file="development-arm.vars.pkr.hcl" \ - -var-file="common-nix.vars.pkr.hcl" \ - -var "ansible_arguments=" \ - -var "postgres-version=$RANDOM_STRING" \ - -var "region=$REGION" \ - -var 'ami_regions=["'"$REGION"'"]' \ - -var "force-deregister=true" \ - -var "ansible_arguments=-e postgresql_major=$POSTGRES_VERSION" \ - amazon-arm64-nix.pkr.hcl - - # Build AMI Stage 2 - packer init stage2-nix-psql.pkr.hcl - packer build \ - -var "git-head-version=$GIT_SHA" \ - -var "packer-execution-id=$RUN_ID" \ - -var "postgres_major_version=$POSTGRES_VERSION" \ - -var-file="development-arm.vars.pkr.hcl" \ - -var-file="common-nix.vars.pkr.hcl" \ - -var "postgres-version=$RANDOM_STRING" \ - -var "region=$REGION" \ - -var 'ami_regions=["'"$REGION"'"]' \ - -var "force-deregister=true" \ - -var "git_sha=$GIT_SHA" \ - stage2-nix-psql.pkr.hcl - - # Cleanup instances from AMI builds - cleanup_instances() { - echo "Terminating EC2 instances with tag testinfra-run-id=$RUN_ID..." - aws ec2 --region $REGION describe-instances \ - --filters "Name=tag:testinfra-run-id,Values=$RUN_ID" \ - --query "Reservations[].Instances[].InstanceId" \ - --output text | xargs -r aws ec2 terminate-instances \ - --region $REGION --instance-ids || true - } - - # Set up traps for various signals to ensure cleanup - trap cleanup_instances EXIT HUP INT QUIT TERM - - # Create and activate virtual environment - VENV_DIR=$(mktemp -d) - trap 'rm -rf "$VENV_DIR"' EXIT HUP INT QUIT TERM - python3 -m venv "$VENV_DIR" - source "$VENV_DIR/bin/activate" - - # Install required Python packages - echo "Installing required Python packages..." - pip install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest paramiko requests - - # Run the tests with aws-vault - echo "Running tests for AMI: $RANDOM_STRING using AWS Vault profile: $AWS_VAULT_PROFILE" - aws-vault exec $AWS_VAULT_PROFILE -- pytest -vv -s testinfra/test_ami_nix.py - - # Deactivate virtual environment (cleanup is handled by trap) - deactivate - EOL - chmod +x $out/bin/build-test-ami - ''; + # Check AWS Vault profile + if [ -z "''${AWS_VAULT:-}" ]; then + echo "Error: AWS_VAULT environment variable must be set with the profile name" + echo "Usage: aws-vault exec -- nix run .#build-test-ami " + exit 1 + fi + + # Set values + REGION="ap-southeast-1" + POSTGRES_VERSION="$1" + RANDOM_STRING=$(openssl rand -hex 8) + GIT_SHA=$(git rev-parse HEAD) + RUN_ID=$(date +%s) + + # Generate common-nix.vars.pkr.hcl + PG_VERSION=$(yq -r ".postgres_release[\"postgres$POSTGRES_VERSION\"]" ansible/vars.yml) + echo "postgres-version = \"$PG_VERSION\"" > common-nix.vars.pkr.hcl + + # Build AMI Stage 1 + packer init amazon-arm64-nix.pkr.hcl + packer build \ + -var "git-head-version=$GIT_SHA" \ + -var "packer-execution-id=$RUN_ID" \ + -var-file="development-arm.vars.pkr.hcl" \ + -var-file="common-nix.vars.pkr.hcl" \ + -var "ansible_arguments=" \ + -var "postgres-version=$RANDOM_STRING" \ + -var "region=$REGION" \ + -var 'ami_regions=["'"$REGION"'"]' \ + -var "force-deregister=true" \ + -var "ansible_arguments=-e postgresql_major=$POSTGRES_VERSION" \ + amazon-arm64-nix.pkr.hcl + + # Build AMI Stage 2 + packer init stage2-nix-psql.pkr.hcl + packer build \ + -var "git-head-version=$GIT_SHA" \ + -var "packer-execution-id=$RUN_ID" \ + -var "postgres_major_version=$POSTGRES_VERSION" \ + -var-file="development-arm.vars.pkr.hcl" \ + -var-file="common-nix.vars.pkr.hcl" \ + -var "postgres-version=$RANDOM_STRING" \ + -var "region=$REGION" \ + -var 'ami_regions=["'"$REGION"'"]' \ + -var "force-deregister=true" \ + -var "git_sha=$GIT_SHA" \ + stage2-nix-psql.pkr.hcl + + # Cleanup instances from AMI builds + cleanup_instances() { + echo "Terminating EC2 instances with tag testinfra-run-id=$RUN_ID..." + aws ec2 --region $REGION describe-instances \ + --filters "Name=tag:testinfra-run-id,Values=$RUN_ID" \ + --query "Reservations[].Instances[].InstanceId" \ + --output text | xargs -r aws ec2 terminate-instances \ + --region $REGION --instance-ids || true + } + + # Set up traps for various signals to ensure cleanup + trap cleanup_instances EXIT HUP INT QUIT TERM + + # Create and activate virtual environment + VENV_DIR=$(mktemp -d) + trap 'rm -rf "$VENV_DIR"' EXIT HUP INT QUIT TERM + python3 -m venv "$VENV_DIR" + source "$VENV_DIR/bin/activate" + + # Install required Python packages + echo "Installing required Python packages..." + pip install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest paramiko requests + + # Run the tests with aws-vault + echo "Running tests for AMI: $RANDOM_STRING using AWS Vault profile: $AWS_VAULT_PROFILE" + aws-vault exec $AWS_VAULT_PROFILE -- pytest -vv -s testinfra/test_ami_nix.py + + # Deactivate virtual environment (cleanup is handled by trap) + deactivate + EOL + chmod +x $out/bin/build-test-ami + ''; run-testinfra = pkgs.runCommand "run-testinfra" { @@ -804,135 +805,135 @@ coreutils ]; } '' - mkdir -p $out/bin - cat > $out/bin/run-testinfra << 'EOL' - #!/usr/bin/env bash - set -euo pipefail - - show_help() { - cat << EOF - Usage: run-testinfra --ami-name NAME [--aws-vault-profile PROFILE] - - Run the testinfra tests locally against a specific AMI. - - This script will: - 1. Check if aws-vault is installed and configured - 2. Set up the required environment variables - 3. Create and activate a virtual environment - 4. Install required Python packages from pip - 5. Run the tests with aws-vault credentials - 6. Clean up the virtual environment - - Required flags: - --ami-name NAME The name of the AMI to test - - Optional flags: - --aws-vault-profile PROFILE AWS Vault profile to use (default: staging) - --help Show this help message and exit - - Requirements: - - aws-vault installed and configured - - Python 3 with pip - - Must be run from the repository root + mkdir -p $out/bin + cat > $out/bin/run-testinfra << 'EOL' + #!/usr/bin/env bash + set -euo pipefail + + show_help() { + cat << EOF + Usage: run-testinfra --ami-name NAME [--aws-vault-profile PROFILE] + + Run the testinfra tests locally against a specific AMI. + + This script will: + 1. Check if aws-vault is installed and configured + 2. Set up the required environment variables + 3. Create and activate a virtual environment + 4. Install required Python packages from pip + 5. Run the tests with aws-vault credentials + 6. Clean up the virtual environment + + Required flags: + --ami-name NAME The name of the AMI to test + + Optional flags: + --aws-vault-profile PROFILE AWS Vault profile to use (default: staging) + --help Show this help message and exit + + Requirements: + - aws-vault installed and configured + - Python 3 with pip + - Must be run from the repository root + + Examples: + run-testinfra --ami-name supabase-postgres-abc123 + run-testinfra --ami-name supabase-postgres-abc123 --aws-vault-profile production + EOF + } + + # Default values + AWS_VAULT_PROFILE="staging" + AMI_NAME="" + + # Parse arguments + while [[ $# -gt 0 ]]; do + case $1 in + --aws-vault-profile) + AWS_VAULT_PROFILE="$2" + shift 2 + ;; + --ami-name) + AMI_NAME="$2" + shift 2 + ;; + --help) + show_help + exit 0 + ;; + *) + echo "Error: Unexpected argument: $1" + show_help + exit 1 + ;; + esac + done - Examples: - run-testinfra --ami-name supabase-postgres-abc123 - run-testinfra --ami-name supabase-postgres-abc123 --aws-vault-profile production - EOF - } - - # Default values - AWS_VAULT_PROFILE="staging" - AMI_NAME="" - - # Parse arguments - while [[ $# -gt 0 ]]; do - case $1 in - --aws-vault-profile) - AWS_VAULT_PROFILE="$2" - shift 2 - ;; - --ami-name) - AMI_NAME="$2" - shift 2 - ;; - --help) - show_help - exit 0 - ;; - *) - echo "Error: Unexpected argument: $1" - show_help - exit 1 - ;; - esac - done - - # Check for required tools - if ! command -v aws-vault &> /dev/null; then - echo "Error: aws-vault is required but not found" - exit 1 - fi + # Check for required tools + if ! command -v aws-vault &> /dev/null; then + echo "Error: aws-vault is required but not found" + exit 1 + fi - # Check for AMI name argument - if [ -z "$AMI_NAME" ]; then - echo "Error: --ami-name is required" - show_help - exit 1 - fi + # Check for AMI name argument + if [ -z "$AMI_NAME" ]; then + echo "Error: --ami-name is required" + show_help + exit 1 + fi - # Set environment variables - export AWS_REGION="ap-southeast-1" - export AWS_DEFAULT_REGION="ap-southeast-1" - export AMI_NAME="$AMI_NAME" # Export AMI_NAME for pytest - export RUN_ID="local-$(date +%s)" # Generate a unique RUN_ID - - # Function to terminate EC2 instances - terminate_instances() { - echo "Terminating EC2 instances with tag testinfra-run-id=$RUN_ID..." - aws-vault exec $AWS_VAULT_PROFILE -- aws ec2 --region ap-southeast-1 describe-instances \ - --filters "Name=tag:testinfra-run-id,Values=$RUN_ID" \ - --query "Reservations[].Instances[].InstanceId" \ - --output text | xargs -r aws-vault exec $AWS_VAULT_PROFILE -- aws ec2 terminate-instances \ - --region ap-southeast-1 --instance-ids || true - } - - # Set up traps for various signals to ensure cleanup - trap terminate_instances EXIT HUP INT QUIT TERM - - # Create and activate virtual environment - VENV_DIR=$(mktemp -d) - trap 'rm -rf "$VENV_DIR"' EXIT HUP INT QUIT TERM - python3 -m venv "$VENV_DIR" - source "$VENV_DIR/bin/activate" - - # Install required Python packages - echo "Installing required Python packages..." - pip install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest paramiko requests - - # Function to run tests and ensure cleanup - run_tests() { - local exit_code=0 - echo "Running tests for AMI: $AMI_NAME using AWS Vault profile: $AWS_VAULT_PROFILE" - aws-vault exec "$AWS_VAULT_PROFILE" -- pytest -vv -s testinfra/test_ami_nix.py || exit_code=$? - return $exit_code - } - - # Run tests and capture exit code - run_tests - test_exit_code=$? - - # Deactivate virtual environment - deactivate - - # Explicitly call cleanup - terminate_instances - - # Exit with the test exit code - exit $test_exit_code - EOL - chmod +x $out/bin/run-testinfra - ''; + # Set environment variables + export AWS_REGION="ap-southeast-1" + export AWS_DEFAULT_REGION="ap-southeast-1" + export AMI_NAME="$AMI_NAME" # Export AMI_NAME for pytest + export RUN_ID="local-$(date +%s)" # Generate a unique RUN_ID + + # Function to terminate EC2 instances + terminate_instances() { + echo "Terminating EC2 instances with tag testinfra-run-id=$RUN_ID..." + aws-vault exec $AWS_VAULT_PROFILE -- aws ec2 --region ap-southeast-1 describe-instances \ + --filters "Name=tag:testinfra-run-id,Values=$RUN_ID" \ + --query "Reservations[].Instances[].InstanceId" \ + --output text | xargs -r aws-vault exec $AWS_VAULT_PROFILE -- aws ec2 terminate-instances \ + --region ap-southeast-1 --instance-ids || true + } + + # Set up traps for various signals to ensure cleanup + trap terminate_instances EXIT HUP INT QUIT TERM + + # Create and activate virtual environment + VENV_DIR=$(mktemp -d) + trap 'rm -rf "$VENV_DIR"' EXIT HUP INT QUIT TERM + python3 -m venv "$VENV_DIR" + source "$VENV_DIR/bin/activate" + + # Install required Python packages + echo "Installing required Python packages..." + pip install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest paramiko requests + + # Function to run tests and ensure cleanup + run_tests() { + local exit_code=0 + echo "Running tests for AMI: $AMI_NAME using AWS Vault profile: $AWS_VAULT_PROFILE" + aws-vault exec "$AWS_VAULT_PROFILE" -- pytest -vv -s testinfra/test_ami_nix.py || exit_code=$? + return $exit_code + } + + # Run tests and capture exit code + run_tests + test_exit_code=$? + + # Deactivate virtual environment + deactivate + + # Explicitly call cleanup + terminate_instances + + # Exit with the test exit code + exit $test_exit_code + EOL + chmod +x $out/bin/run-testinfra + ''; cleanup-ami = pkgs.runCommand "cleanup-ami" { @@ -941,53 +942,53 @@ aws-vault ]; } '' - mkdir -p $out/bin - cat > $out/bin/cleanup-ami << 'EOL' - #!/usr/bin/env bash - set -euo pipefail - - export PATH="${pkgs.lib.makeBinPath (with pkgs; [ - awscli2 - aws-vault - ])}:$PATH" - - # Check for required tools - for cmd in aws-vault; do - if ! command -v $cmd &> /dev/null; then - echo "Error: $cmd is required but not found" - exit 1 - fi - done - - # Check AWS Vault profile - if [ -z "''${AWS_VAULT:-}" ]; then - echo "Error: AWS_VAULT environment variable must be set with the profile name" - echo "Usage: aws-vault exec -- nix run .#cleanup-ami " + mkdir -p $out/bin + cat > $out/bin/cleanup-ami << 'EOL' + #!/usr/bin/env bash + set -euo pipefail + + export PATH="${pkgs.lib.makeBinPath (with pkgs; [ + awscli2 + aws-vault + ])}:$PATH" + + # Check for required tools + for cmd in aws-vault; do + if ! command -v $cmd &> /dev/null; then + echo "Error: $cmd is required but not found" exit 1 fi + done - # Check for AMI name argument - if [ -z "''${1:-}" ]; then - echo "Error: AMI name must be provided" - echo "Usage: aws-vault exec -- nix run .#cleanup-ami " - exit 1 - fi + # Check AWS Vault profile + if [ -z "''${AWS_VAULT:-}" ]; then + echo "Error: AWS_VAULT environment variable must be set with the profile name" + echo "Usage: aws-vault exec -- nix run .#cleanup-ami " + exit 1 + fi - AMI_NAME="$1" - REGION="ap-southeast-1" - - # Deregister AMIs - for AMI_PATTERN in "supabase-postgres-ci-ami-test-stage-1" "$AMI_NAME"; do - aws ec2 describe-images --region $REGION --owners self \ - --filters "Name=name,Values=$AMI_PATTERN" \ - --query 'Images[*].ImageId' --output text | while read -r ami_id; do - echo "Deregistering AMI: $ami_id" - aws ec2 deregister-image --region $REGION --image-id "$ami_id" || true - done - done - EOL - chmod +x $out/bin/cleanup-ami - ''; + # Check for AMI name argument + if [ -z "''${1:-}" ]; then + echo "Error: AMI name must be provided" + echo "Usage: aws-vault exec -- nix run .#cleanup-ami " + exit 1 + fi + + AMI_NAME="$1" + REGION="ap-southeast-1" + + # Deregister AMIs + for AMI_PATTERN in "supabase-postgres-ci-ami-test-stage-1" "$AMI_NAME"; do + aws ec2 describe-images --region $REGION --owners self \ + --filters "Name=name,Values=$AMI_PATTERN" \ + --query 'Images[*].ImageId' --output text | while read -r ami_id; do + echo "Deregistering AMI: $ami_id" + aws ec2 deregister-image --region $REGION --image-id "$ami_id" || true + done + done + EOL + chmod +x $out/bin/cleanup-ami + ''; trigger-nix-build = pkgs.runCommand "trigger-nix-build" { @@ -997,113 +998,113 @@ coreutils ]; } '' - mkdir -p $out/bin - cat > $out/bin/trigger-nix-build << 'EOL' - #!/usr/bin/env bash - set -euo pipefail - - show_help() { - cat << EOF - Usage: trigger-nix-build [--help] + mkdir -p $out/bin + cat > $out/bin/trigger-nix-build << 'EOL' + #!/usr/bin/env bash + set -euo pipefail - Trigger the nix-build workflow for the current branch and watch its progress. + show_help() { + cat << EOF + Usage: trigger-nix-build [--help] - This script will: - 1. Check if you're authenticated with GitHub - 2. Get the current branch and commit - 3. Verify you're on a standard branch (develop or release/*) or prompt for confirmation - 4. Trigger the nix-build workflow - 5. Watch the workflow progress until completion + Trigger the nix-build workflow for the current branch and watch its progress. - Options: - --help Show this help message and exit + This script will: + 1. Check if you're authenticated with GitHub + 2. Get the current branch and commit + 3. Verify you're on a standard branch (develop or release/*) or prompt for confirmation + 4. Trigger the nix-build workflow + 5. Watch the workflow progress until completion - Requirements: - - GitHub CLI (gh) installed and authenticated - - Git installed - - Must be run from a git repository + Options: + --help Show this help message and exit - Example: - trigger-nix-build - EOF - } + Requirements: + - GitHub CLI (gh) installed and authenticated + - Git installed + - Must be run from a git repository - # Handle help flag - if [[ "$#" -gt 0 && "$1" == "--help" ]]; then - show_help - exit 0 - fi + Example: + trigger-nix-build + EOF + } - export PATH="${pkgs.lib.makeBinPath (with pkgs; [ - gh - git - coreutils - ])}:$PATH" + # Handle help flag + if [[ "$#" -gt 0 && "$1" == "--help" ]]; then + show_help + exit 0 + fi - # Check for required tools - for cmd in gh git; do - if ! command -v $cmd &> /dev/null; then - echo "Error: $cmd is required but not found" - exit 1 - fi - done + export PATH="${pkgs.lib.makeBinPath (with pkgs; [ + gh + git + coreutils + ])}:$PATH" - # Check if user is authenticated with GitHub - if ! gh auth status &>/dev/null; then - echo "Error: Not authenticated with GitHub. Please run 'gh auth login' first." + # Check for required tools + for cmd in gh git; do + if ! command -v $cmd &> /dev/null; then + echo "Error: $cmd is required but not found" exit 1 fi + done - # Get current branch and commit - BRANCH=$(git rev-parse --abbrev-ref HEAD) - COMMIT=$(git rev-parse HEAD) - - # Check if we're on a standard branch - if [[ "$BRANCH" != "develop" && ! "$BRANCH" =~ ^release/ ]]; then - echo "Warning: Running workflow from non-standard branch: $BRANCH" - echo "This is supported for testing purposes." - read -p "Continue? [y/N] " -n 1 -r - echo - if [[ ! $REPLY =~ ^[Yy]$ ]]; then - echo "Aborted." - exit 1 - fi + # Check if user is authenticated with GitHub + if ! gh auth status &>/dev/null; then + echo "Error: Not authenticated with GitHub. Please run 'gh auth login' first." + exit 1 + fi + + # Get current branch and commit + BRANCH=$(git rev-parse --abbrev-ref HEAD) + COMMIT=$(git rev-parse HEAD) + + # Check if we're on a standard branch + if [[ "$BRANCH" != "develop" && ! "$BRANCH" =~ ^release/ ]]; then + echo "Warning: Running workflow from non-standard branch: $BRANCH" + echo "This is supported for testing purposes." + read -p "Continue? [y/N] " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Aborted." + exit 1 fi + fi - # Trigger the workflow - echo "Triggering nix-build workflow for branch $BRANCH (commit: $COMMIT)" - gh workflow run nix-build.yml --ref "$BRANCH" + # Trigger the workflow + echo "Triggering nix-build workflow for branch $BRANCH (commit: $COMMIT)" + gh workflow run nix-build.yml --ref "$BRANCH" - # Wait for workflow to start and get the run ID - echo "Waiting for workflow to start..." - sleep 5 + # Wait for workflow to start and get the run ID + echo "Waiting for workflow to start..." + sleep 5 - # Get the latest run ID for this workflow - RUN_ID=$(gh run list --workflow=nix-build.yml --limit 1 --json databaseId --jq '.[0].databaseId') + # Get the latest run ID for this workflow + RUN_ID=$(gh run list --workflow=nix-build.yml --limit 1 --json databaseId --jq '.[0].databaseId') - if [ -z "$RUN_ID" ]; then - echo "Error: Could not find workflow run ID" - exit 1 - fi + if [ -z "$RUN_ID" ]; then + echo "Error: Could not find workflow run ID" + exit 1 + fi - echo "Watching workflow run $RUN_ID..." - echo "The script will automatically exit when the workflow completes." - echo "Press Ctrl+C to stop watching (workflow will continue running)" - echo "----------------------------------------" + echo "Watching workflow run $RUN_ID..." + echo "The script will automatically exit when the workflow completes." + echo "Press Ctrl+C to stop watching (workflow will continue running)" + echo "----------------------------------------" - # Try to watch the run, but handle network errors gracefully - while true; do - if gh run watch "$RUN_ID" --exit-status; then - break - else - echo "Network error while watching workflow. Retrying in 5 seconds..." - echo "You can also check the status manually with: gh run view $RUN_ID" - sleep 5 - fi - done - EOL - chmod +x $out/bin/trigger-nix-build - ''; + # Try to watch the run, but handle network errors gracefully + while true; do + if gh run watch "$RUN_ID" --exit-status; then + break + else + echo "Network error while watching workflow. Retrying in 5 seconds..." + echo "You can also check the status manually with: gh run view $RUN_ID" + sleep 5 + fi + done + EOL + chmod +x $out/bin/trigger-nix-build + ''; }; @@ -1214,11 +1215,12 @@ # Filter SQL test files filteredSqlTests = filterTestFiles majorVersion ./nix/tests/sql; - pgPort = if (majorVersion == "17") then + pgPort = + if (majorVersion == "17") then "5535" - else if (majorVersion == "15") then + else if (majorVersion == "15") then "5536" - else "5537"; + else "5537"; # Convert filtered tests to a sorted list of basenames (without extension) testList = pkgs.lib.mapAttrsToList diff --git a/nix/cargo-pgrx/buildPgrxExtension.nix b/nix/cargo-pgrx/buildPgrxExtension.nix index 89293ab62..c5336e09e 100644 --- a/nix/cargo-pgrx/buildPgrxExtension.nix +++ b/nix/cargo-pgrx/buildPgrxExtension.nix @@ -52,15 +52,15 @@ , buildFeatures ? [ ] , cargoBuildFlags ? [ ] , postgresql -# cargo-pgrx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the -# dependency here. Set to false and provide rustfmt in nativeBuildInputs, if you need it, e.g. -# if you include the generated code in the output via postInstall. + # cargo-pgrx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the + # dependency here. Set to false and provide rustfmt in nativeBuildInputs, if you need it, e.g. + # if you include the generated code in the output via postInstall. , useFakeRustfmt ? true , usePgTestCheckFeature ? true , ... } @ args: let - rustfmtInNativeBuildInputs = lib.lists.any (dep: lib.getName dep == "rustfmt") (args.nativeBuildInputs or []); + rustfmtInNativeBuildInputs = lib.lists.any (dep: lib.getName dep == "rustfmt") (args.nativeBuildInputs or [ ]); in assert lib.asserts.assertMsg ((args.installPhase or "") == "") @@ -75,7 +75,7 @@ assert lib.asserts.assertMsg (!useFakeRustfmt -> rustfmtInNativeBuildInputs) let fakeRustfmt = writeShellScriptBin "rustfmt" '' exit 0 - ''; + ''; maybeDebugFlag = lib.optionalString (buildType != "release") "--debug"; maybeEnterBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) '' export CARGO_TARGET_DIR="$(pwd)/target" diff --git a/nix/cargo-pgrx/default.nix b/nix/cargo-pgrx/default.nix index c1e1a4dee..49e7ae44f 100644 --- a/nix/cargo-pgrx/default.nix +++ b/nix/cargo-pgrx/default.nix @@ -38,7 +38,7 @@ let ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.Security ]; - + OPENSSL_DIR = "${openssl.dev}"; OPENSSL_INCLUDE_DIR = "${openssl.dev}/include"; OPENSSL_LIB_DIR = "${openssl.out}/lib"; diff --git a/nix/ext/mecab-naist-jdic/default.nix b/nix/ext/mecab-naist-jdic/default.nix index 82f0ed37c..5f0523d30 100644 --- a/nix/ext/mecab-naist-jdic/default.nix +++ b/nix/ext/mecab-naist-jdic/default.nix @@ -3,14 +3,14 @@ stdenv.mkDerivation rec { pname = "mecab-naist-jdic"; version = "0.6.3b-20111013"; - + src = fetchurl { url = "https://github.com/supabase/mecab-naist-jdic/raw/main/mecab-naist-jdic-${version}.tar.gz"; sha256 = "sha256-yzdwDcmne5U/K/OxW0nP7NZ4SFMKLPirywm1lMpWKMw="; }; - + buildInputs = [ mecab ]; - + configureFlags = [ "--with-charset=utf8" ]; diff --git a/nix/ext/pg-safeupdate.nix b/nix/ext/pg-safeupdate.nix index f5ad17a82..4f690b30b 100644 --- a/nix/ext/pg-safeupdate.nix +++ b/nix/ext/pg-safeupdate.nix @@ -7,9 +7,9 @@ stdenv.mkDerivation rec { buildInputs = [ postgresql ]; src = fetchFromGitHub { - owner = "eradman"; - repo = pname; - rev = version; + owner = "eradman"; + repo = pname; + rev = version; hash = "sha256-1cyvVEC9MQGMr7Tg6EUbsVBrMc8ahdFS3+CmDkmAq4Y="; }; @@ -19,10 +19,10 @@ stdenv.mkDerivation rec { meta = with lib; { description = "A simple extension to PostgreSQL that requires criteria for UPDATE and DELETE"; - homepage = "https://github.com/eradman/pg-safeupdate"; - changelog = "https://github.com/eradman/pg-safeupdate/raw/${src.rev}/NEWS"; - platforms = postgresql.meta.platforms; - license = licenses.postgresql; - broken = versionOlder postgresql.version "14"; + homepage = "https://github.com/eradman/pg-safeupdate"; + changelog = "https://github.com/eradman/pg-safeupdate/raw/${src.rev}/NEWS"; + platforms = postgresql.meta.platforms; + license = licenses.postgresql; + broken = versionOlder postgresql.version "14"; }; } diff --git a/nix/ext/pg_backtrace.nix b/nix/ext/pg_backtrace.nix index 0a0b0ae4f..b49545bcd 100644 --- a/nix/ext/pg_backtrace.nix +++ b/nix/ext/pg_backtrace.nix @@ -7,9 +7,9 @@ stdenv.mkDerivation rec { buildInputs = [ postgresql ]; src = fetchFromGitHub { - owner = "pashkinelfe"; - repo = pname; - rev = "d100bac815a7365e199263f5b3741baf71b14c70"; + owner = "pashkinelfe"; + repo = pname; + rev = "d100bac815a7365e199263f5b3741baf71b14c70"; hash = "sha256-IVCL4r4oj1Ams03D8y+XCFkckPFER/W9tQ68GkWQQMY="; }; @@ -25,8 +25,8 @@ stdenv.mkDerivation rec { meta = with lib; { description = "Updated fork of pg_backtrace"; - homepage = "https://github.com/pashkinelfe/pg_backtrace"; - platforms = postgresql.meta.platforms; - license = licenses.postgresql; + homepage = "https://github.com/pashkinelfe/pg_backtrace"; + platforms = postgresql.meta.platforms; + license = licenses.postgresql; }; } diff --git a/nix/ext/pg_cron.nix b/nix/ext/pg_cron.nix index 792db7676..7b25783ec 100644 --- a/nix/ext/pg_cron.nix +++ b/nix/ext/pg_cron.nix @@ -7,9 +7,9 @@ stdenv.mkDerivation rec { buildInputs = [ postgresql ]; src = fetchFromGitHub { - owner = "citusdata"; - repo = pname; - rev = "v${version}"; + owner = "citusdata"; + repo = pname; + rev = "v${version}"; hash = "sha256-t1DpFkPiSfdoGG2NgNT7g1lkvSooZoRoUrix6cBID40="; }; @@ -23,9 +23,9 @@ stdenv.mkDerivation rec { meta = with lib; { description = "Run Cron jobs through PostgreSQL"; - homepage = "https://github.com/citusdata/pg_cron"; - changelog = "https://github.com/citusdata/pg_cron/raw/v${version}/CHANGELOG.md"; - platforms = postgresql.meta.platforms; - license = licenses.postgresql; + homepage = "https://github.com/citusdata/pg_cron"; + changelog = "https://github.com/citusdata/pg_cron/raw/v${version}/CHANGELOG.md"; + platforms = postgresql.meta.platforms; + license = licenses.postgresql; }; } diff --git a/nix/ext/pg_graphql.nix b/nix/ext/pg_graphql.nix index ef406f8d4..dec22808d 100644 --- a/nix/ext/pg_graphql.nix +++ b/nix/ext/pg_graphql.nix @@ -1,8 +1,8 @@ { lib, stdenv, fetchFromGitHub, postgresql, buildPgrxExtension_0_12_9, cargo, rust-bin }: let - rustVersion = "1.81.0"; - cargo = rust-bin.stable.${rustVersion}.default; + rustVersion = "1.81.0"; + cargo = rust-bin.stable.${rustVersion}.default; in buildPgrxExtension_0_12_9 rec { pname = "pg_graphql"; @@ -18,20 +18,20 @@ buildPgrxExtension_0_12_9 rec { nativeBuildInputs = [ cargo ]; buildInputs = [ postgresql ]; - + CARGO = "${cargo}/bin/cargo"; - + cargoLock = { lockFile = "${src}/Cargo.lock"; }; # Setting RUSTFLAGS in env to ensure it's available for all phases env = lib.optionalAttrs stdenv.isDarwin { POSTGRES_LIB = "${postgresql}/lib"; - PGPORT = toString (5430 + - (if builtins.match ".*_.*" postgresql.version != null then 1 else 0) + # +1 for OrioleDB - ((builtins.fromJSON (builtins.substring 0 2 postgresql.version)) - 15) * 2); # +2 for each major version + PGPORT = toString (5430 + + (if builtins.match ".*_.*" postgresql.version != null then 1 else 0) + # +1 for OrioleDB + ((builtins.fromJSON (builtins.substring 0 2 postgresql.version)) - 15) * 2); # +2 for each major version RUSTFLAGS = "-C link-arg=-undefined -C link-arg=dynamic_lookup"; - NIX_BUILD_CORES = "4"; # Limit parallel jobs + NIX_BUILD_CORES = "4"; # Limit parallel jobs CARGO_BUILD_JOBS = "4"; # Limit cargo parallelism }; CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_DEBUG = true; diff --git a/nix/ext/pg_jsonschema.nix b/nix/ext/pg_jsonschema.nix index 654bb93f5..702dc8bd8 100644 --- a/nix/ext/pg_jsonschema.nix +++ b/nix/ext/pg_jsonschema.nix @@ -20,15 +20,15 @@ buildPgrxExtension_0_12_6 rec { # update the following array when the pg_jsonschema version is updated # required to ensure that extensions update scripts from previous versions are generated - previousVersions = ["0.3.1" "0.3.0" "0.2.0" "0.1.4" "0.1.4" "0.1.2" "0.1.1" "0.1.0"]; - CARGO="${cargo}/bin/cargo"; + previousVersions = [ "0.3.1" "0.3.0" "0.2.0" "0.1.4" "0.1.4" "0.1.2" "0.1.1" "0.1.0" ]; + CARGO = "${cargo}/bin/cargo"; #darwin env needs PGPORT to be unique for build to not clash with other pgrx extensions env = lib.optionalAttrs stdenv.isDarwin { POSTGRES_LIB = "${postgresql}/lib"; RUSTFLAGS = "-C link-arg=-undefined -C link-arg=dynamic_lookup"; - PGPORT = toString (5441 + - (if builtins.match ".*_.*" postgresql.version != null then 1 else 0) + # +1 for OrioleDB - ((builtins.fromJSON (builtins.substring 0 2 postgresql.version)) - 15) * 2); # +2 for each major version + PGPORT = toString (5441 + + (if builtins.match ".*_.*" postgresql.version != null then 1 else 0) + # +1 for OrioleDB + ((builtins.fromJSON (builtins.substring 0 2 postgresql.version)) - 15) * 2); # +2 for each major version }; @@ -36,7 +36,7 @@ buildPgrxExtension_0_12_6 rec { lockFile = "${src}/Cargo.lock"; allowBuiltinFetchGit = false; }; - + # FIXME (aseipp): testsuite tries to write files into /nix/store; we'll have # to fix this a bit later. doCheck = false; diff --git a/nix/ext/pg_partman.nix b/nix/ext/pg_partman.nix index 899716b44..ee60b8e3e 100644 --- a/nix/ext/pg_partman.nix +++ b/nix/ext/pg_partman.nix @@ -7,9 +7,9 @@ stdenv.mkDerivation rec { buildInputs = [ postgresql ]; src = fetchFromGitHub { - owner = "pgpartman"; - repo = pname; - rev = "refs/tags/v${version}"; + owner = "pgpartman"; + repo = pname; + rev = "refs/tags/v${version}"; sha256 = "sha256-GrVOJ5ywZMyqyDroYDLdKkXDdIJSDGhDfveO/ZvrmYs="; }; @@ -24,10 +24,10 @@ stdenv.mkDerivation rec { meta = with lib; { description = "Partition management extension for PostgreSQL"; - homepage = "https://github.com/pgpartman/pg_partman"; - changelog = "https://github.com/pgpartman/pg_partman/blob/v${version}/CHANGELOG.md"; - platforms = postgresql.meta.platforms; - license = licenses.postgresql; - broken = versionOlder postgresql.version "14"; + homepage = "https://github.com/pgpartman/pg_partman"; + changelog = "https://github.com/pgpartman/pg_partman/blob/v${version}/CHANGELOG.md"; + platforms = postgresql.meta.platforms; + license = licenses.postgresql; + broken = versionOlder postgresql.version "14"; }; } diff --git a/nix/ext/pg_tle.nix b/nix/ext/pg_tle.nix index a0e9385b2..185efd089 100644 --- a/nix/ext/pg_tle.nix +++ b/nix/ext/pg_tle.nix @@ -14,10 +14,10 @@ stdenv.mkDerivation rec { hash = "sha256-crxj5R9jblIv0h8lpqddAoYe2UqgUlnvbOajKTzVces="; }; - + makeFlags = [ "FLEX=flex" ]; - + installPhase = '' mkdir -p $out/{lib,share/postgresql/extension} diff --git a/nix/ext/pgjwt.nix b/nix/ext/pgjwt.nix index 4ecd76339..bafbfd26b 100644 --- a/nix/ext/pgjwt.nix +++ b/nix/ext/pgjwt.nix @@ -5,9 +5,9 @@ stdenv.mkDerivation rec { version = "9742dab1b2f297ad3811120db7b21451bca2d3c9"; src = fetchFromGitHub { - owner = "michelp"; - repo = "pgjwt"; - rev = "${version}"; + owner = "michelp"; + repo = "pgjwt"; + rev = "${version}"; hash = "sha256-Hw3R9bMGDmh+dMzjmqZSy/rT4mX8cPU969OJiARFg10="; }; diff --git a/nix/ext/pgmq.nix b/nix/ext/pgmq.nix index 97a3c27e3..6e214091d 100644 --- a/nix/ext/pgmq.nix +++ b/nix/ext/pgmq.nix @@ -5,9 +5,9 @@ stdenv.mkDerivation rec { version = "1.4.4"; buildInputs = [ postgresql ]; src = fetchFromGitHub { - owner = "tembo-io"; - repo = pname; - rev = "v${version}"; + owner = "tembo-io"; + repo = pname; + rev = "v${version}"; hash = "sha256-z+8/BqIlHwlMnuIzMz6eylmYbSmhtsNt7TJf/CxbdVw="; }; @@ -25,9 +25,9 @@ stdenv.mkDerivation rec { meta = with lib; { description = "A lightweight message queue. Like AWS SQS and RSMQ but on Postgres."; - homepage = "https://github.com/tembo-io/pgmq"; + homepage = "https://github.com/tembo-io/pgmq"; maintainers = with maintainers; [ olirice ]; - platforms = postgresql.meta.platforms; - license = licenses.postgresql; + platforms = postgresql.meta.platforms; + license = licenses.postgresql; }; } diff --git a/nix/ext/pgroonga.nix b/nix/ext/pgroonga.nix index de0dedc93..2ccb9f0bb 100644 --- a/nix/ext/pgroonga.nix +++ b/nix/ext/pgroonga.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, callPackage, mecab, makeWrapper, xxHash }: +{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, callPackage, mecab, makeWrapper, xxHash }: let supabase-groonga = callPackage ../supabase-groonga.nix { }; in @@ -10,7 +10,7 @@ stdenv.mkDerivation rec { sha256 = "sha256-GM9EOQty72hdE4Ecq8jpDudhZLiH3pP9ODLxs8DXcSY="; }; nativeBuildInputs = [ pkg-config makeWrapper ]; - + buildInputs = [ postgresql msgpack-c supabase-groonga mecab ] ++ lib.optionals stdenv.isDarwin [ xxHash ]; @@ -23,7 +23,7 @@ stdenv.mkDerivation rec { "--with-groonga-plugin-dir=${supabase-groonga}/lib/groonga/plugins" ]; - makeFlags = [ + makeFlags = [ "HAVE_MSGPACK=1" "MSGPACK_PACKAGE_NAME=msgpack-c" "HAVE_MECAB=1" diff --git a/nix/ext/pgrouting.nix b/nix/ext/pgrouting.nix index 3e898022f..c0a7d5c51 100644 --- a/nix/ext/pgrouting.nix +++ b/nix/ext/pgrouting.nix @@ -8,19 +8,19 @@ stdenv.mkDerivation rec { buildInputs = [ postgresql boost ]; src = fetchFromGitHub { - owner = "pgRouting"; - repo = pname; - rev = "v${version}"; + owner = "pgRouting"; + repo = pname; + rev = "v${version}"; hash = "sha256-QC77AnPGpPQGEWi6JtJdiNsB2su5+aV2pKg5ImR2B0k="; }; #disable compile time warnings for incompatible pointer types only on macos and pg16 - NIX_CFLAGS_COMPILE = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") - "-Wno-error=int-conversion -Wno-error=incompatible-pointer-types"; + NIX_CFLAGS_COMPILE = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") + "-Wno-error=int-conversion -Wno-error=incompatible-pointer-types"; cmakeFlags = [ "-DPOSTGRESQL_VERSION=${postgresql.version}" - ] ++ lib.optionals (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") [ + ] ++ lib.optionals (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") [ "-DCMAKE_MACOSX_RPATH=ON" "-DCMAKE_SHARED_MODULE_SUFFIX=.dylib" "-DCMAKE_SHARED_LIBRARY_SUFFIX=.dylib" @@ -51,9 +51,9 @@ stdenv.mkDerivation rec { meta = with lib; { description = "A PostgreSQL/PostGIS extension that provides geospatial routing functionality"; - homepage = "https://pgrouting.org/"; - changelog = "https://github.com/pgRouting/pgrouting/releases/tag/v${version}"; - platforms = postgresql.meta.platforms; - license = licenses.gpl2Plus; + homepage = "https://pgrouting.org/"; + changelog = "https://github.com/pgRouting/pgrouting/releases/tag/v${version}"; + platforms = postgresql.meta.platforms; + license = licenses.gpl2Plus; }; } diff --git a/nix/ext/pljava.nix b/nix/ext/pljava.nix index 51c5e1317..1cad96afe 100644 --- a/nix/ext/pljava.nix +++ b/nix/ext/pljava.nix @@ -3,21 +3,21 @@ maven.buildMavenPackage rec { pname = "pljava"; - version = "1.6.7"; + version = "1.6.7"; src = fetchFromGitHub { owner = "tada"; repo = "pljava"; - rev = "V1_6_7"; - sha256 = "sha256-M17adSLsw47KZ2BoUwxyWkXKRD8TcexDAy61Yfw4fNU="; - + rev = "V1_6_7"; + sha256 = "sha256-M17adSLsw47KZ2BoUwxyWkXKRD8TcexDAy61Yfw4fNU="; + }; - mvnParameters = "clean install -Dmaven.test.skip -DskipTests -Dmaven.javadoc.skip=true"; + mvnParameters = "clean install -Dmaven.test.skip -DskipTests -Dmaven.javadoc.skip=true"; mvnHash = "sha256-lcxRduh/nKcPL6YQIVTsNH0L4ga0LgJpQKgX5IPkRzs="; - + nativeBuildInputs = [ makeWrapper maven openjdk postgresql openssl postgresql gcc libkrb5 pkg-config ]; - buildInputs = [ stdenv.cc.cc.lib which]; + buildInputs = [ stdenv.cc.cc.lib which ]; buildPhase = '' export PATH=$(lib.makeBinPath [ postgresql ]):$PATH diff --git a/nix/ext/plv8.nix b/nix/ext/plv8.nix index b3fd03e07..1879ffd1b 100644 --- a/nix/ext/plv8.nix +++ b/nix/ext/plv8.nix @@ -4,9 +4,9 @@ , v8 , perl , postgresql -# For passthru test on various systems, and local development on macos -# not we are not currently using passthru tests but retaining for possible contrib -# to nixpkgs + # For passthru test on various systems, and local development on macos + # not we are not currently using passthru tests but retaining for possible contrib + # to nixpkgs , runCommand , coreutils , gnugrep @@ -54,7 +54,7 @@ stdenv.mkDerivation (finalAttrs: { # Nixpkgs build a v8 monolith instead of separate v8_libplatform. "USE_SYSTEM_V8=1" "V8_OUTDIR=${v8}/lib" - "PG_CONFIG=${postgresql}/bin/pg_config" + "PG_CONFIG=${postgresql}/bin/pg_config" ] ++ lib.optionals stdenv.isDarwin [ "CC=${clang}/bin/clang" "CXX=${clang}/bin/clang++" @@ -71,12 +71,15 @@ stdenv.mkDerivation (finalAttrs: { "-lpgcommon" "-lpgport" "-F${darwin.apple_sdk.frameworks.CoreFoundation}/Library/Frameworks" - "-framework" "CoreFoundation" + "-framework" + "CoreFoundation" "-F${darwin.apple_sdk.frameworks.Kerberos}/Library/Frameworks" - "-framework" "Kerberos" - "-undefined" "dynamic_lookup" + "-framework" + "Kerberos" + "-undefined" + "dynamic_lookup" "-flat_namespace" - ]); + ]); installFlags = [ # PGXS only supports installing to postgresql prefix so we need to redirect this @@ -97,7 +100,7 @@ stdenv.mkDerivation (finalAttrs: { ''} ''; - postInstall = '' + postInstall = '' # Move the redirected to proper directory. # There appear to be no references to the install directories # so changing them does not cause issues. diff --git a/nix/ext/postgis.nix b/nix/ext/postgis.nix index e5ccda443..79f6e05aa 100644 --- a/nix/ext/postgis.nix +++ b/nix/ext/postgis.nix @@ -1,5 +1,6 @@ { fetchurl -, lib, stdenv +, lib +, stdenv , perl , libxml2 , postgresql @@ -31,7 +32,7 @@ stdenv.mkDerivation rec { }; buildInputs = [ libxml2 postgresql geos proj gdal json_c protobufc pcre2.dev sfcgal ] - ++ lib.optional stdenv.isDarwin libiconv; + ++ lib.optional stdenv.isDarwin libiconv; nativeBuildInputs = [ perl pkg-config ]; dontDisableStatic = true; @@ -57,22 +58,22 @@ stdenv.mkDerivation rec { ln -s ${postgresql}/bin/postgres $out/bin/postgres ''; -postInstall = '' - rm $out/bin/postgres - for prog in $out/bin/*; do # */ - ln -s $prog $prog-${version} - done - # Add function definition and usage to tiger geocoder files - for file in $out/share/postgresql/extension/postgis_tiger_geocoder*--${version}.sql; do - sed -i "/SELECT postgis_extension_AddToSearchPath('tiger');/a SELECT postgis_extension_AddToSearchPath('extensions');" "$file" - done - # Original topology patching - for file in $out/share/postgresql/extension/postgis_topology*--${version}.sql; do - sed -i "/SELECT topology.AddToSearchPath('topology');/i SELECT topology.AddToSearchPath('extensions');" "$file" - done - mkdir -p $doc/share/doc/postgis - mv doc/* $doc/share/doc/postgis/ -''; + postInstall = '' + rm $out/bin/postgres + for prog in $out/bin/*; do # */ + ln -s $prog $prog-${version} + done + # Add function definition and usage to tiger geocoder files + for file in $out/share/postgresql/extension/postgis_tiger_geocoder*--${version}.sql; do + sed -i "/SELECT postgis_extension_AddToSearchPath('tiger');/a SELECT postgis_extension_AddToSearchPath('extensions');" "$file" + done + # Original topology patching + for file in $out/share/postgresql/extension/postgis_topology*--${version}.sql; do + sed -i "/SELECT topology.AddToSearchPath('topology');/i SELECT topology.AddToSearchPath('extensions');" "$file" + done + mkdir -p $doc/share/doc/postgis + mv doc/* $doc/share/doc/postgis/ + ''; passthru.tests.postgis = nixosTests.postgis; diff --git a/nix/ext/sfcgal/sfcgal.nix b/nix/ext/sfcgal/sfcgal.nix index b1d5842f8..b83a3a7bb 100644 --- a/nix/ext/sfcgal/sfcgal.nix +++ b/nix/ext/sfcgal/sfcgal.nix @@ -24,7 +24,7 @@ stdenv.mkDerivation rec { meta = with lib; { description = "A wrapper around CGAL that intents to implement 2D and 3D operations on OGC standards models"; homepage = "https://sfcgal.gitlab.io/SFCGAL/"; - license = with licenses; [ gpl3Plus lgpl3Plus]; + license = with licenses; [ gpl3Plus lgpl3Plus ]; platforms = platforms.all; }; } diff --git a/nix/ext/wrappers/default.nix b/nix/ext/wrappers/default.nix index 2bd424942..31bfafdf7 100644 --- a/nix/ext/wrappers/default.nix +++ b/nix/ext/wrappers/default.nix @@ -20,7 +20,7 @@ buildPgrxExtension_0_12_9 rec { version = "0.5.0"; # update the following array when the wrappers version is updated # required to ensure that extensions update scripts from previous versions are generated - previousVersions = ["0.4.6" "0.4.5" "0.4.4" "0.4.3" "0.4.2" "0.4.1" "0.4.0" "0.3.1" "0.3.0" "0.2.0" "0.1.19" "0.1.18" "0.1.17" "0.1.16" "0.1.15" "0.1.14" "0.1.12" "0.1.11" "0.1.10" "0.1.9" "0.1.8" "0.1.7" "0.1.6" "0.1.5" "0.1.4" "0.1.1" "0.1.0"]; + previousVersions = [ "0.4.6" "0.4.5" "0.4.4" "0.4.3" "0.4.2" "0.4.1" "0.4.0" "0.3.1" "0.3.0" "0.2.0" "0.1.19" "0.1.18" "0.1.17" "0.1.16" "0.1.15" "0.1.14" "0.1.12" "0.1.11" "0.1.10" "0.1.9" "0.1.8" "0.1.7" "0.1.6" "0.1.5" "0.1.4" "0.1.1" "0.1.0" ]; inherit postgresql; src = fetchFromGitHub { owner = "supabase"; @@ -28,12 +28,12 @@ buildPgrxExtension_0_12_9 rec { rev = "v${version}"; hash = "sha256-FbRTUcpEHBa5DI6dutvBeahYM0RZVAXIzIAZWIaxvn0"; }; - + nativeBuildInputs = [ pkg-config cargo git ]; - buildInputs = [ openssl postgresql ] ++ lib.optionals (stdenv.isDarwin) [ - darwin.apple_sdk.frameworks.CoreFoundation - darwin.apple_sdk.frameworks.Security - darwin.apple_sdk.frameworks.SystemConfiguration + buildInputs = [ openssl postgresql ] ++ lib.optionals (stdenv.isDarwin) [ + darwin.apple_sdk.frameworks.CoreFoundation + darwin.apple_sdk.frameworks.Security + darwin.apple_sdk.frameworks.SystemConfiguration ]; NIX_LDFLAGS = "-L${postgresql}/lib -lpq"; @@ -50,16 +50,16 @@ buildPgrxExtension_0_12_9 rec { # - PostgreSQL 15.8 → 5435 + 0 + (15-15)*2 = 5435 # - PostgreSQL 17_0 (OrioleDB) → 5435 + 1 + (17-15)*2 = 5440 # - PostgreSQL 17.4 → 5435 + 0 + (17-15)*2 = 5439 - PGPORT = toString (5534 + - (if builtins.match ".*_.*" postgresql.version != null then 1 else 0) + # +1 for OrioleDB - ((builtins.fromJSON (builtins.substring 0 2 postgresql.version)) - 15) * 2); # +2 for each major version + PGPORT = toString (5534 + + (if builtins.match ".*_.*" postgresql.version != null then 1 else 0) + # +1 for OrioleDB + ((builtins.fromJSON (builtins.substring 0 2 postgresql.version)) - 15) * 2); # +2 for each major version }; OPENSSL_NO_VENDOR = 1; #need to set this to 2 to avoid cpu starvation CARGO_BUILD_JOBS = "2"; - CARGO="${cargo}/bin/cargo"; - + CARGO = "${cargo}/bin/cargo"; + #CARGO_NET_GIT_FETCH_WITH_CLI = "true"; cargoLock = { lockFile = "${src}/Cargo.lock"; @@ -69,7 +69,7 @@ buildPgrxExtension_0_12_9 rec { }; }; - preConfigure = '' + preConfigure = '' cd wrappers # update the clickhouse-rs dependency @@ -103,7 +103,7 @@ buildPgrxExtension_0_12_9 rec { cd .. ''; - + buildAndTestSubdir = "wrappers"; buildFeatures = [ "helloworld_fdw" @@ -116,53 +116,53 @@ buildPgrxExtension_0_12_9 rec { echo '${builtins.concatStringsSep "," previousVersions}' | sed 's/,/\n/g' > git_tags.txt ''; - postInstall = '' - echo "Modifying main SQL file to use unversioned library name..." - current_version="${version}" - main_sql_file="$out/share/postgresql/extension/wrappers--$current_version.sql" - if [ -f "$main_sql_file" ]; then - sed -i 's|$libdir/wrappers-[0-9.]*|$libdir/wrappers|g' "$main_sql_file" - echo "Modified $main_sql_file" - else - echo "Warning: $main_sql_file not found" - fi - echo "Creating and modifying SQL files for previous versions..." + postInstall = '' + echo "Modifying main SQL file to use unversioned library name..." + current_version="${version}" + main_sql_file="$out/share/postgresql/extension/wrappers--$current_version.sql" + if [ -f "$main_sql_file" ]; then + sed -i 's|$libdir/wrappers-[0-9.]*|$libdir/wrappers|g' "$main_sql_file" + echo "Modified $main_sql_file" + else + echo "Warning: $main_sql_file not found" + fi + echo "Creating and modifying SQL files for previous versions..." - if [ -f "$main_sql_file" ]; then - while read -r previous_version; do - if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then - new_file="$out/share/postgresql/extension/wrappers--$previous_version--$current_version.sql" - echo "Creating $new_file" - cp "$main_sql_file" "$new_file" - sed -i 's|$libdir/wrappers-[0-9.]*|$libdir/wrappers|g' "$new_file" - echo "Modified $new_file" - fi - done < git_tags.txt - else - echo "Warning: $main_sql_file not found" - fi - mv $out/lib/wrappers-${version}${postgresql.dlSuffix} $out/lib/wrappers${postgresql.dlSuffix} - ln -s $out/lib/wrappers${postgresql.dlSuffix} $out/lib/wrappers-${version}${postgresql.dlSuffix} + if [ -f "$main_sql_file" ]; then + while read -r previous_version; do + if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then + new_file="$out/share/postgresql/extension/wrappers--$previous_version--$current_version.sql" + echo "Creating $new_file" + cp "$main_sql_file" "$new_file" + sed -i 's|$libdir/wrappers-[0-9.]*|$libdir/wrappers|g' "$new_file" + echo "Modified $new_file" + fi + done < git_tags.txt + else + echo "Warning: $main_sql_file not found" + fi + mv $out/lib/wrappers-${version}${postgresql.dlSuffix} $out/lib/wrappers${postgresql.dlSuffix} + ln -s $out/lib/wrappers${postgresql.dlSuffix} $out/lib/wrappers-${version}${postgresql.dlSuffix} - echo "Creating wrappers.so symlinks to support pg_upgrade..." - if [ -f "$out/lib/wrappers.so" ]; then - while read -r previous_version; do - if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then - new_file="$out/lib/wrappers-$previous_version.so" - echo "Creating $new_file" - ln -s "$out/lib/wrappers.so" "$new_file" - fi - done < git_tags.txt - else - echo "Warning: $out/lib/wrappers.so not found" - fi + echo "Creating wrappers.so symlinks to support pg_upgrade..." + if [ -f "$out/lib/wrappers.so" ]; then + while read -r previous_version; do + if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then + new_file="$out/lib/wrappers-$previous_version.so" + echo "Creating $new_file" + ln -s "$out/lib/wrappers.so" "$new_file" + fi + done < git_tags.txt + else + echo "Warning: $out/lib/wrappers.so not found" + fi - rm git_tags.txt - echo "Contents of updated wrappers.control:" - cat "$out/share/postgresql/extension/wrappers.control" - echo "List of generated SQL files:" - ls -l $out/share/postgresql/extension/wrappers--*.sql - ''; + rm git_tags.txt + echo "Contents of updated wrappers.control:" + cat "$out/share/postgresql/extension/wrappers.control" + echo "List of generated SQL files:" + ls -l $out/share/postgresql/extension/wrappers--*.sql + ''; meta = with lib; { description = "Various Foreign Data Wrappers (FDWs) for PostreSQL"; diff --git a/nix/postgresql/default.nix b/nix/postgresql/default.nix index f7b3c5583..a55d689b6 100644 --- a/nix/postgresql/default.nix +++ b/nix/postgresql/default.nix @@ -6,14 +6,16 @@ let postgresql_orioledb-17 = ./orioledb-17.nix; }; mkAttributes = jitSupport: - self.lib.mapAttrs' (version: path: - let - attrName = if jitSupport then "${version}_jit" else version; - in - self.lib.nameValuePair attrName (import path { - inherit jitSupport self; - }) - ) versions; + self.lib.mapAttrs' + (version: path: + let + attrName = if jitSupport then "${version}_jit" else version; + in + self.lib.nameValuePair attrName (import path { + inherit jitSupport self; + }) + ) + versions; in # variations without and with JIT (mkAttributes false) // (mkAttributes true) diff --git a/nix/postgresql/generic.nix b/nix/postgresql/generic.nix index cefd5a61b..5913c1dc2 100644 --- a/nix/postgresql/generic.nix +++ b/nix/postgresql/generic.nix @@ -1,79 +1,111 @@ let generic = - # adapted from the nixpkgs postgresql package - # dependencies - { stdenv, lib, fetchurl, fetchpatch, makeWrapper - , glibc, zlib, readline, openssl, icu, lz4, zstd, systemd, libossp_uuid - , pkg-config, libxml2, tzdata, libkrb5, substituteAll, darwin - , linux-pam + # adapted from the nixpkgs postgresql package + # dependencies + { stdenv + , lib + , fetchurl + , fetchpatch + , makeWrapper + , glibc + , zlib + , readline + , openssl + , icu + , lz4 + , zstd + , systemd + , libossp_uuid + , pkg-config + , libxml2 + , tzdata + , libkrb5 + , substituteAll + , darwin + , linux-pam #orioledb specific - , perl, bison, flex, docbook_xsl, docbook_xml_dtd_45, docbook_xsl_ns, libxslt + , perl + , bison + , flex + , docbook_xsl + , docbook_xml_dtd_45 + , docbook_xsl_ns + , libxslt # This is important to obtain a version of `libpq` that does not depend on systemd. - , systemdSupport ? lib.meta.availableOn stdenv.hostPlatform systemd && !stdenv.hostPlatform.isStatic - , enableSystemd ? null - , gssSupport ? with stdenv.hostPlatform; !isWindows && !isStatic + , systemdSupport ? lib.meta.availableOn stdenv.hostPlatform systemd && !stdenv.hostPlatform.isStatic + , enableSystemd ? null + , gssSupport ? with stdenv.hostPlatform; !isWindows && !isStatic # for postgresql.pkgs - , self, newScope, buildEnv + , self + , newScope + , buildEnv # source specification - , version, hash, muslPatches ? {} + , version + , hash + , muslPatches ? { } # for tests - , testers + , testers # JIT - , jitSupport - , nukeReferences, patchelf, llvmPackages + , jitSupport + , nukeReferences + , patchelf + , llvmPackages # PL/Python - , pythonSupport ? false - , python3 + , pythonSupport ? false + , python3 # detection of crypt fails when using llvm stdenv, so we add it manually # for <13 (where it got removed: https://github.com/postgres/postgres/commit/c45643d618e35ec2fe91438df15abd4f3c0d85ca) - , libxcrypt + , libxcrypt } @args: - let - atLeast = lib.versionAtLeast version; - olderThan = lib.versionOlder version; - lz4Enabled = atLeast "14"; - zstdEnabled = atLeast "15"; - - systemdSupport' = if enableSystemd == null then systemdSupport else (lib.warn "postgresql: argument enableSystemd is deprecated, please use systemdSupport instead." enableSystemd); - - pname = "postgresql"; - - stdenv' = if jitSupport then llvmPackages.stdenv else stdenv; - in stdenv'.mkDerivation (finalAttrs: { - inherit version; - pname = pname + lib.optionalString jitSupport "-jit"; - - src = if (builtins.match "[0-9][0-9]_.*" version != null) then - fetchurl { - url = "https://github.com/orioledb/postgres/archive/refs/tags/patches${version}.tar.gz"; - inherit hash; - } - else - fetchurl { - url = "mirror://postgresql/source/v${version}/${pname}-${version}.tar.bz2"; - inherit hash; - }; + let + atLeast = lib.versionAtLeast version; + olderThan = lib.versionOlder version; + lz4Enabled = atLeast "14"; + zstdEnabled = atLeast "15"; - hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ]; + systemdSupport' = if enableSystemd == null then systemdSupport else (lib.warn "postgresql: argument enableSystemd is deprecated, please use systemdSupport instead." enableSystemd); - outputs = [ "out" "lib" ]; - setOutputFlags = false; # $out retains configureFlags :-/ + pname = "postgresql"; - buildInputs = [ - zlib - readline - openssl - (libxml2.override {python = python3;}) - icu - ] + stdenv' = if jitSupport then llvmPackages.stdenv else stdenv; + in + stdenv'.mkDerivation (finalAttrs: { + inherit version; + pname = pname + lib.optionalString jitSupport "-jit"; + + src = + if (builtins.match "[0-9][0-9]_.*" version != null) then + fetchurl + { + url = "https://github.com/orioledb/postgres/archive/refs/tags/patches${version}.tar.gz"; + inherit hash; + } + else + fetchurl { + url = "mirror://postgresql/source/v${version}/${pname}-${version}.tar.bz2"; + inherit hash; + }; + + hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ]; + + outputs = [ "out" "lib" ]; + setOutputFlags = false; # $out retains configureFlags :-/ + + buildInputs = [ + zlib + readline + openssl + (libxml2.override { python = python3; }) + icu + ] ++ lib.optionals (olderThan "13") [ libxcrypt ] ++ lib.optionals jitSupport [ llvmPackages.llvm ] ++ lib.optionals lz4Enabled [ lz4 ] @@ -83,212 +115,222 @@ let ++ lib.optionals gssSupport [ libkrb5 ] ++ lib.optionals stdenv'.isLinux [ linux-pam ] ++ lib.optionals (!stdenv'.isDarwin) [ libossp_uuid ] - ++ lib.optionals ((builtins.match "[0-9][0-9]_.*" version != null) || (lib.versionAtLeast version "17")) [ - perl bison flex docbook_xsl docbook_xml_dtd_45 docbook_xsl_ns libxslt + ++ lib.optionals ((builtins.match "[0-9][0-9]_.*" version != null) || (lib.versionAtLeast version "17")) [ + perl + bison + flex + docbook_xsl + docbook_xml_dtd_45 + docbook_xsl_ns + libxslt ]; - nativeBuildInputs = [ - makeWrapper - pkg-config - ] + nativeBuildInputs = [ + makeWrapper + pkg-config + ] ++ lib.optionals jitSupport [ llvmPackages.llvm.dev nukeReferences patchelf ]; - enableParallelBuilding = true; + enableParallelBuilding = true; - separateDebugInfo = true; + separateDebugInfo = true; - buildFlags = [ "world-bin" ]; + buildFlags = [ "world-bin" ]; - # Makes cross-compiling work when xml2-config can't be executed on the host. - # Fixed upstream in https://github.com/postgres/postgres/commit/0bc8cebdb889368abdf224aeac8bc197fe4c9ae6 - env.NIX_CFLAGS_COMPILE = lib.optionalString (olderThan "13") "-I${libxml2.dev}/include/libxml2"; + # Makes cross-compiling work when xml2-config can't be executed on the host. + # Fixed upstream in https://github.com/postgres/postgres/commit/0bc8cebdb889368abdf224aeac8bc197fe4c9ae6 + env.NIX_CFLAGS_COMPILE = lib.optionalString (olderThan "13") "-I${libxml2.dev}/include/libxml2"; - configureFlags = [ - "--with-openssl" - "--with-libxml" - "--with-icu" - "--sysconfdir=/etc" - "--libdir=$(lib)/lib" - "--with-system-tzdata=${tzdata}/share/zoneinfo" - "--enable-debug" - (lib.optionalString systemdSupport' "--with-systemd") - (if stdenv'.isDarwin then "--with-uuid=e2fs" else "--with-ossp-uuid") - ] ++ lib.optionals lz4Enabled [ "--with-lz4" ] + configureFlags = [ + "--with-openssl" + "--with-libxml" + "--with-icu" + "--sysconfdir=/etc" + "--libdir=$(lib)/lib" + "--with-system-tzdata=${tzdata}/share/zoneinfo" + "--enable-debug" + (lib.optionalString systemdSupport' "--with-systemd") + (if stdenv'.isDarwin then "--with-uuid=e2fs" else "--with-ossp-uuid") + ] ++ lib.optionals lz4Enabled [ "--with-lz4" ] ++ lib.optionals zstdEnabled [ "--with-zstd" ] ++ lib.optionals gssSupport [ "--with-gssapi" ] ++ lib.optionals pythonSupport [ "--with-python" ] ++ lib.optionals jitSupport [ "--with-llvm" ] ++ lib.optionals stdenv'.isLinux [ "--with-pam" ]; - patches = [ - (if atLeast "16" then ./patches/relative-to-symlinks-16+.patch else ./patches/relative-to-symlinks.patch) - ./patches/less-is-more.patch - ./patches/paths-for-split-outputs.patch - ./patches/specify_pkglibdir_at_runtime.patch - ./patches/paths-with-postgresql-suffix.patch - - (substituteAll { - src = ./patches/locale-binary-path.patch; - locale = "${if stdenv.isDarwin then darwin.adv_cmds else lib.getBin stdenv.cc.libc}/bin/locale"; - }) - ] ++ lib.optionals stdenv'.hostPlatform.isMusl ( - # Using fetchurl instead of fetchpatch on purpose: https://github.com/NixOS/nixpkgs/issues/240141 - map fetchurl (lib.attrValues muslPatches) - ) ++ lib.optionals stdenv'.isLinux [ - (if atLeast "13" then ./patches/socketdir-in-run-13+.patch else ./patches/socketdir-in-run.patch) - ]; + patches = [ + (if atLeast "16" then ./patches/relative-to-symlinks-16+.patch else ./patches/relative-to-symlinks.patch) + ./patches/less-is-more.patch + ./patches/paths-for-split-outputs.patch + ./patches/specify_pkglibdir_at_runtime.patch + ./patches/paths-with-postgresql-suffix.patch + + (substituteAll { + src = ./patches/locale-binary-path.patch; + locale = "${if stdenv.isDarwin then darwin.adv_cmds else lib.getBin stdenv.cc.libc}/bin/locale"; + }) + ] ++ lib.optionals stdenv'.hostPlatform.isMusl ( + # Using fetchurl instead of fetchpatch on purpose: https://github.com/NixOS/nixpkgs/issues/240141 + map fetchurl (lib.attrValues muslPatches) + ) ++ lib.optionals stdenv'.isLinux [ + (if atLeast "13" then ./patches/socketdir-in-run-13+.patch else ./patches/socketdir-in-run.patch) + ]; - installTargets = [ "install-world-bin" ]; + installTargets = [ "install-world-bin" ]; - postPatch = '' - # Hardcode the path to pgxs so pg_config returns the path in $out - substituteInPlace "src/common/config_info.c" --subst-var out - '' + lib.optionalString jitSupport '' + postPatch = '' + # Hardcode the path to pgxs so pg_config returns the path in $out + substituteInPlace "src/common/config_info.c" --subst-var out + '' + lib.optionalString jitSupport '' # Force lookup of jit stuff in $out instead of $lib substituteInPlace src/backend/jit/jit.c --replace pkglib_path \"$out/lib\" substituteInPlace src/backend/jit/llvm/llvmjit.c --replace pkglib_path \"$out/lib\" substituteInPlace src/backend/jit/llvm/llvmjit_inline.cpp --replace pkglib_path \"$out/lib\" - ''; - - postInstall = - '' - moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it - moveToOutput "lib/libpgcommon*.a" "$out" - moveToOutput "lib/libpgport*.a" "$out" - moveToOutput "lib/libecpg*" "$out" - - # Prevent a retained dependency on gcc-wrapper. - substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld - - if [ -z "''${dontDisableStatic:-}" ]; then - # Remove static libraries in case dynamic are available. - for i in $out/lib/*.a $lib/lib/*.a; do - name="$(basename "$i")" - ext="${stdenv'.hostPlatform.extensions.sharedLibrary}" - if [ -e "$lib/lib/''${name%.a}$ext" ] || [ -e "''${i%.a}$ext" ]; then - rm "$i" - fi - done - fi - '' + lib.optionalString jitSupport '' - # Move the bitcode and libllvmjit.so library out of $lib; otherwise, every client that - # depends on libpq.so will also have libLLVM.so in its closure too, bloating it - moveToOutput "lib/bitcode" "$out" - moveToOutput "lib/llvmjit*" "$out" - - # In the case of JIT support, prevent a retained dependency on clang-wrapper - substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/clang clang - nuke-refs $out/lib/llvmjit_types.bc $(find $out/lib/bitcode -type f) - - # Stop out depending on the default output of llvm - substituteInPlace $out/lib/pgxs/src/Makefile.global \ - --replace ${llvmPackages.llvm.out}/bin "" \ - --replace '$(LLVM_BINPATH)/' "" - - # Stop out depending on the -dev output of llvm - substituteInPlace $out/lib/pgxs/src/Makefile.global \ - --replace ${llvmPackages.llvm.dev}/bin/llvm-config llvm-config \ - --replace -I${llvmPackages.llvm.dev}/include "" - - ${lib.optionalString (!stdenv'.isDarwin) '' - # Stop lib depending on the -dev output of llvm - rpath=$(patchelf --print-rpath $out/lib/llvmjit.so) - nuke-refs -e $out $out/lib/llvmjit.so - # Restore the correct rpath - patchelf $out/lib/llvmjit.so --set-rpath "$rpath" - ''} - ''; - - postFixup = lib.optionalString (!stdenv'.isDarwin && stdenv'.hostPlatform.libc == "glibc") - '' - # initdb needs access to "locale" command from glibc. - wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin ''; - doCheck = !stdenv'.isDarwin; - # autodetection doesn't seem to able to find this, but it's there. - checkTarget = "check"; - - disallowedReferences = [ stdenv'.cc ]; - - passthru = let - this = self.callPackage generic args; - jitToggle = this.override { - jitSupport = !jitSupport; - }; - in - { - psqlSchema = lib.versions.major version; - - withJIT = if jitSupport then this else jitToggle; - withoutJIT = if jitSupport then jitToggle else this; - - dlSuffix = if olderThan "16" then ".so" else stdenv.hostPlatform.extensions.sharedLibrary; - - pkgs = let - scope = { - inherit jitSupport; - inherit (llvmPackages) llvm; - postgresql = this; - stdenv = stdenv'; - }; - newSelf = self // scope; - newSuper = { callPackage = newScope (scope // this.pkgs); }; - in import ./ext newSelf newSuper; - - withPackages = postgresqlWithPackages { - inherit makeWrapper buildEnv; - postgresql = this; - } - this.pkgs; - - tests = { - postgresql-wal-receiver = import ../../../../nixos/tests/postgresql-wal-receiver.nix { - inherit (stdenv) system; - pkgs = self; - package = this; - }; - pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; - } // lib.optionalAttrs jitSupport { - postgresql-jit = import ../../../../nixos/tests/postgresql-jit.nix { - inherit (stdenv) system; - pkgs = self; - package = this; + postInstall = + '' + moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it + moveToOutput "lib/libpgcommon*.a" "$out" + moveToOutput "lib/libpgport*.a" "$out" + moveToOutput "lib/libecpg*" "$out" + + # Prevent a retained dependency on gcc-wrapper. + substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld + + if [ -z "''${dontDisableStatic:-}" ]; then + # Remove static libraries in case dynamic are available. + for i in $out/lib/*.a $lib/lib/*.a; do + name="$(basename "$i")" + ext="${stdenv'.hostPlatform.extensions.sharedLibrary}" + if [ -e "$lib/lib/''${name%.a}$ext" ] || [ -e "''${i%.a}$ext" ]; then + rm "$i" + fi + done + fi + '' + lib.optionalString jitSupport '' + # Move the bitcode and libllvmjit.so library out of $lib; otherwise, every client that + # depends on libpq.so will also have libLLVM.so in its closure too, bloating it + moveToOutput "lib/bitcode" "$out" + moveToOutput "lib/llvmjit*" "$out" + + # In the case of JIT support, prevent a retained dependency on clang-wrapper + substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/clang clang + nuke-refs $out/lib/llvmjit_types.bc $(find $out/lib/bitcode -type f) + + # Stop out depending on the default output of llvm + substituteInPlace $out/lib/pgxs/src/Makefile.global \ + --replace ${llvmPackages.llvm.out}/bin "" \ + --replace '$(LLVM_BINPATH)/' "" + + # Stop out depending on the -dev output of llvm + substituteInPlace $out/lib/pgxs/src/Makefile.global \ + --replace ${llvmPackages.llvm.dev}/bin/llvm-config llvm-config \ + --replace -I${llvmPackages.llvm.dev}/include "" + + ${lib.optionalString (!stdenv'.isDarwin) '' + # Stop lib depending on the -dev output of llvm + rpath=$(patchelf --print-rpath $out/lib/llvmjit.so) + nuke-refs -e $out $out/lib/llvmjit.so + # Restore the correct rpath + patchelf $out/lib/llvmjit.so --set-rpath "$rpath" + ''} + ''; + + postFixup = lib.optionalString (!stdenv'.isDarwin && stdenv'.hostPlatform.libc == "glibc") + '' + # initdb needs access to "locale" command from glibc. + wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin + ''; + + doCheck = !stdenv'.isDarwin; + # autodetection doesn't seem to able to find this, but it's there. + checkTarget = "check"; + + disallowedReferences = [ stdenv'.cc ]; + + passthru = + let + this = self.callPackage generic args; + jitToggle = this.override { + jitSupport = !jitSupport; + }; + in + { + psqlSchema = lib.versions.major version; + + withJIT = if jitSupport then this else jitToggle; + withoutJIT = if jitSupport then jitToggle else this; + + dlSuffix = if olderThan "16" then ".so" else stdenv.hostPlatform.extensions.sharedLibrary; + + pkgs = + let + scope = { + inherit jitSupport; + inherit (llvmPackages) llvm; + postgresql = this; + stdenv = stdenv'; + }; + newSelf = self // scope; + newSuper = { callPackage = newScope (scope // this.pkgs); }; + in + import ./ext newSelf newSuper; + + withPackages = postgresqlWithPackages + { + inherit makeWrapper buildEnv; + postgresql = this; + } + this.pkgs; + + tests = { + postgresql-wal-receiver = import ../../../../nixos/tests/postgresql-wal-receiver.nix { + inherit (stdenv) system; + pkgs = self; + package = this; + }; + pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; + } // lib.optionalAttrs jitSupport { + postgresql-jit = import ../../../../nixos/tests/postgresql-jit.nix { + inherit (stdenv) system; + pkgs = self; + package = this; + }; + }; }; + + meta = with lib; { + homepage = "https://www.postgresql.org"; + description = "Powerful, open source object-relational database system"; + license = licenses.postgresql; + changelog = "https://www.postgresql.org/docs/release/${finalAttrs.version}/"; + maintainers = with maintainers; [ thoughtpolice danbst globin ivan ma27 wolfgangwalther ]; + pkgConfigModules = [ "libecpg" "libecpg_compat" "libpgtypes" "libpq" ]; + platforms = platforms.unix; + + # JIT support doesn't work with cross-compilation. It is attempted to build LLVM-bytecode + # (`%.bc` is the corresponding `make(1)`-rule) for each sub-directory in `backend/` for + # the JIT apparently, but with a $(CLANG) that can produce binaries for the build, not the + # host-platform. + # + # I managed to get a cross-build with JIT support working with + # `depsBuildBuild = [ llvmPackages.clang ] ++ buildInputs`, but considering that the + # resulting LLVM IR isn't platform-independent this doesn't give you much. + # In fact, I tried to test the result in a VM-test, but as soon as JIT was used to optimize + # a query, postgres would coredump with `Illegal instruction`. + broken = (jitSupport && stdenv.hostPlatform != stdenv.buildPlatform) + # Allmost all tests fail FATAL errors for v12 and v13 + || (jitSupport && stdenv.hostPlatform.isMusl && olderThan "14"); }; - }; - - meta = with lib; { - homepage = "https://www.postgresql.org"; - description = "Powerful, open source object-relational database system"; - license = licenses.postgresql; - changelog = "https://www.postgresql.org/docs/release/${finalAttrs.version}/"; - maintainers = with maintainers; [ thoughtpolice danbst globin ivan ma27 wolfgangwalther ]; - pkgConfigModules = [ "libecpg" "libecpg_compat" "libpgtypes" "libpq" ]; - platforms = platforms.unix; - - # JIT support doesn't work with cross-compilation. It is attempted to build LLVM-bytecode - # (`%.bc` is the corresponding `make(1)`-rule) for each sub-directory in `backend/` for - # the JIT apparently, but with a $(CLANG) that can produce binaries for the build, not the - # host-platform. - # - # I managed to get a cross-build with JIT support working with - # `depsBuildBuild = [ llvmPackages.clang ] ++ buildInputs`, but considering that the - # resulting LLVM IR isn't platform-independent this doesn't give you much. - # In fact, I tried to test the result in a VM-test, but as soon as JIT was used to optimize - # a query, postgres would coredump with `Illegal instruction`. - broken = (jitSupport && stdenv.hostPlatform != stdenv.buildPlatform) - # Allmost all tests fail FATAL errors for v12 and v13 - || (jitSupport && stdenv.hostPlatform.isMusl && olderThan "14"); - }; - }); + }); postgresqlWithPackages = { postgresql, makeWrapper, buildEnv }: pkgs: f: buildEnv { name = "postgresql-and-plugins-${postgresql.version}"; paths = f pkgs ++ [ - postgresql - postgresql.lib - #TODO RM postgresql.man # in case user installs this into environment + postgresql + postgresql.lib + #TODO RM postgresql.man # in case user installs this into environment ]; nativeBuildInputs = [ makeWrapper ]; @@ -296,7 +338,7 @@ let # We include /bin to ensure the $out/bin directory is created, which is # needed because we'll be removing the files from that directory in postBuild # below. See #22653 - pathsToLink = ["/" "/bin"]; + pathsToLink = [ "/" "/bin" ]; # Note: the duplication of executables is about 4MB size. # So a nicer solution was patching postgresql to allow setting the diff --git a/nix/supabase-groonga.nix b/nix/supabase-groonga.nix index 5035f369f..ef6afcabe 100644 --- a/nix/supabase-groonga.nix +++ b/nix/supabase-groonga.nix @@ -1,7 +1,28 @@ -{ lib, stdenv, cmake, fetchurl, kytea, msgpack-c, mecab, pkg-config, rapidjson -, testers, xxHash, zstd, postgresqlPackages, makeWrapper, suggestSupport ? false -, zeromq, libevent, openssl, lz4Support ? false, lz4, zlibSupport ? true, zlib -, writeShellScriptBin, callPackage }: +{ lib +, stdenv +, cmake +, fetchurl +, kytea +, msgpack-c +, mecab +, pkg-config +, rapidjson +, testers +, xxHash +, zstd +, postgresqlPackages +, makeWrapper +, suggestSupport ? false +, zeromq +, libevent +, openssl +, lz4Support ? false +, lz4 +, zlibSupport ? true +, zlib +, writeShellScriptBin +, callPackage +}: let mecab-naist-jdic = callPackage ./ext/mecab-naist-jdic { }; in stdenv.mkDerivation (finalAttrs: { pname = "supabase-groonga"; From 15311a9346e4ab2b4c372033da8a084f1bd696d7 Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Fri, 20 Jun 2025 14:15:36 +0200 Subject: [PATCH 3/3] chore: add docs on how to setup a `pre-commit` hook for `treefmt` --- nix/docs/contributing.md | 13 +++++++++++++ nix/docs/start-here.md | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 nix/docs/contributing.md diff --git a/nix/docs/contributing.md b/nix/docs/contributing.md new file mode 100644 index 000000000..ca3a4fc4f --- /dev/null +++ b/nix/docs/contributing.md @@ -0,0 +1,13 @@ +# Contributing + +Welcome! Here are some tips to help you get started, especially if you're new to Nix: + +- Always run `treefmt` (or `nix fmt`, which is an alias) before committing your files. This ensures your code is properly formatted (otherwise, the CI will complain). + +- You can automate formatting checks locally by installing a git pre-commit hook with `pre-commit install`. + +- The default Nix devshell provides `pre-commit`, `treefmt`, and `nixpkgs-fmt`. Enter the devshell with `nix develop` to have these binaries in your PATH. + +- You can automate load/unloading the devshell when entering/leaving the project directory using [`direnv`](./direnv.md). + +For more details on the development process, check out [./development-workflow.md](./development-workflow.md). diff --git a/nix/docs/start-here.md b/nix/docs/start-here.md index acc315830..eb165f4c5 100644 --- a/nix/docs/start-here.md +++ b/nix/docs/start-here.md @@ -68,3 +68,5 @@ examples: - **A.1**: `nix profile install nixpkgs#ripgrep` - **A.2**: `nix profile install nixpkgs#bat` - **A.3**: And yes, you also have exa, fd, hyperfine, and more! + +Next you might want to setup a developer environment for this project by reading the [contributing guide](./contributing.md)!