Skip to content

Conversation

@jfroche
Copy link
Collaborator

@jfroche jfroche commented Dec 11, 2025

The current development shell include a large number of packages which
leads to a very large closure size (5 Gb) and slow startup times.
To improve the situation we defer installing large packages to devshell
commands which only get installed when needed.
We introduce the use of devshell to define the commands in a
declarative way as well as to improve the overall developer experience.
The closure of the default devshell is now down to 2 Gb (which still could be improved later on).

Included changes:

  • Add organized command menu with categories (check, ami, extension, postgres)
  • Add watch command using watchexec + nix-fast-build for continuous checking
  • Expose common tasks as named commands: fmt, check, lint, watch
  • Add aws-vault to development tools

Summary by CodeRabbit

  • Chores
    • Development shell infrastructure updated with new available commands: fmt, check, lint, watch, cleanup-ami, build-test-ami, sync-exts-versions, and database/PostgreSQL management utilities
    • Database tooling and migration functionality refactored
    • Development environment setup streamlined

✏️ Tip: You can customize this high-level summary in your review settings.

@jfroche jfroche requested review from a team as code owners December 11, 2025 22:47
@yvan-sraka yvan-sraka requested a review from a team as a code owner December 12, 2025 09:06
@yvan-sraka yvan-sraka force-pushed the update-nixpkgs branch 2 times, most recently from b48e4c3 to 3df6c4a Compare December 12, 2025 10:07
Copy link
Collaborator

@samrose samrose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's hold off on this one until we complete nixpkgs update and some of our other critical items. We can definitely try to do this one, but we may need adjust a few things, and document it a bit more as well

@samrose samrose force-pushed the update-nixpkgs branch 3 times, most recently from 771718f to 4e32d5b Compare December 17, 2025 19:36
Base automatically changed from update-nixpkgs to develop January 16, 2026 00:23
The current development shell include a large number of packages which
leads to a very large closure size (5 Gb) and slow startup times.
To improve the situation we defer installing large packages to devshell
commands which only get installed when needed.
We introduce the use of devshell to define the commands in a
declarative way as well as to improve the overall developer experience.

Included changes:

- Add organized command menu with categories (check, ami, extension, postgres)
- Add watch command using watchexec + nix-fast-build for continuous checking
- Expose common tasks as named commands: fmt, check, lint, watch
- Add aws-vault to development tools
`writeShellApplication` avoids substitute commands, provides the correct
package metadata and make sure that all scripts are shellcheked.
We don't need to maintain our own packer package anymore since we are
using a recently updated nixpkgs that includes packer.
@jfroche jfroche force-pushed the fix/default-devshell branch from 2188ce0 to efc2e26 Compare January 16, 2026 20:05
@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

Walkthrough

This PR refactors the Nix development environment by adopting the devshell package, migrating shell script derivations from runCommand to writeShellApplication, consolidating template files into inline Nix expressions, and removing the packer package in favor of inlined dependencies.

Changes

Cohort / File(s) Summary
Flake Configuration
flake.nix, nix/nixpkgs.nix
Adds devshell input and integrates devshell overlay into nixpkgs configuration
Development Shell & Apps
nix/devShells.nix, nix/apps.nix, nix/checks.nix
Migrates default dev shell from mkShell to devshell.mkShell with structured command definitions; refactors app definitions with simplified mkApp signature; adds devShell attribute to checks
Package Refactoring: writeShellApplication Migration
nix/packages/build-test-ami.nix, nix/packages/cleanup-ami.nix, nix/packages/dbmate-tool.nix, nix/packages/migrate-tool.nix, nix/packages/start-client.nix, nix/packages/start-replica.nix, nix/packages/sync-exts-versions.nix
Converts derivations from runCommand-based shell scripts to writeShellApplication with explicit runtimeInputs and inline text; consolidates logic previously in template files
Package Removal & Updates
nix/packages/packer.nix, nix/packages/default.nix
Removes packer buildGoModule derivation entirely; updates build-ami to remove packer argument
Removed Template Scripts
nix/tools/dbmate-tool.sh.in, nix/tools/migrate-tool.sh.in, nix/tools/run-client.sh.in, nix/packages/start-replica.sh.in
Eliminates template files as their logic is now inlined into Nix expressions via writeShellApplication
Script Runtime Updates
nix/tools/sync-exts-versions.sh.in
Replaces environment variable placeholders with dynamic runtime command invocations (yq, jq, nix-editor, nix) and improves quoting consistency

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Suggested reviewers

  • samrose
  • hunleyd

Poem

🐰 Shell scripts now nest in Nix so clean,
writeShellApplication reigns supreme!
Devshell commands dance with flair,
Templates inlined with elegant care,
A refactored warren—our dev tools glare! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly summarizes the main objective: refactoring the devshell to improve developer experience by reducing closure size and deferring large packages to commands.
Description check ✅ Passed The PR description explains the problem (large closure size, slow startup), the solution (deferring packages to commands, using devshell declaratively), and lists specific improvements (command menu, watch command, named commands, aws-vault).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
nix/tools/sync-exts-versions.sh.in (1)

105-118: Missing error handling when nix build succeeds but expected to fail.

The update_cargo_vendor_hash function intentionally sets cargoHash to empty to trigger a build failure and scrape the correct hash. However, if the build unexpectedly succeeds (line 116), the function silently continues without updating the hash. This might leave the Nix file in an inconsistent state with an empty cargoHash.

Consider restoring the original hash or erroring out if the build succeeds unexpectedly after clearing the hash.

nix/packages/build-test-ami.nix (3)

118-124: Chain traps so EC2 cleanup still runs.

The second trap overrides the earlier one, so cleanup_instances may never execute.

🐛 Proposed fix
-    trap 'rm -rf "$VENV_DIR"' EXIT HUP INT QUIT TERM
+    trap 'cleanup_instances; rm -rf "$VENV_DIR"' EXIT HUP INT QUIT TERM

68-77: Validate postgres-version before using it.

Without a required argument (or if it’s unknown), PG_VERSION can be empty/null and the Packer build will fail later.

🐛 Proposed fix
     POSTGRES_VERSION="$1"
+    if [ -z "$POSTGRES_VERSION" ]; then
+      echo "Error: postgres-version argument is required"
+      exit 1
+    fi
@@
-    PG_VERSION=$(yq -r ".postgres_release[\"postgres$POSTGRES_VERSION\"]" ansible/vars.yml)
+    PG_VERSION=$(yq -r ".postgres_release[\"postgres$POSTGRES_VERSION\"]" ansible/vars.yml)
+    if [ -z "$PG_VERSION" ] || [ "$PG_VERSION" = "null" ]; then
+      echo "Error: unknown postgres-version '$POSTGRES_VERSION'"
+      exit 1
+    fi

61-65: Use the correct AWS Vault profile variable.

The script validates AWS_VAULT (line 62) but then tries to use the undefined AWS_VAULT_PROFILE when running tests. Since the script expects AWS_VAULT to contain the profile name, use that variable consistently.

🐛 Proposed fix
-    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
+    echo "Running tests for AMI: $RANDOM_STRING using AWS Vault profile: $AWS_VAULT"
+    aws-vault exec "$AWS_VAULT" -- pytest -vv -s testinfra/test_ami_nix.py
🤖 Fix all issues with AI agents
In `@nix/apps.nix`:
- Line 30: The app declaration uses the old two-argument form of mkApp; update
the supascan entry to call mkApp with a single argument (remove the second
"supascan" argument) so it matches the refactored signature of mkApp and returns
the expected attribute set (i.e., change the line referencing mkApp "supascan"
"supascan" to a single-argument call to mkApp "supascan").

In `@nix/packages/dbmate-tool.nix`:
- Around line 27-29: The default PSQL_VERSION is set to "ALL" but the build
logic expects "all"; change the default to PSQL_VERSION="all" (and update the
other occurrences of PSQL_VERSION="ALL" at the other default block referenced)
so path checks and the psql_${PSQL_VERSION} branch match the lowercase "all"
branch; leave PORTNO="${defaults.port}" as-is.
- Around line 290-291: The script currently ignores failures from perform_dump
which can leave a missing/partial schema; update the call after echo "Running
dbmate dump with $PSQLBIN" to check perform_dump's exit status and fail fast
(e.g., run perform_dump && true || { echo "dbmate dump failed"; exit 1; } or
simply if ! perform_dump; then echo "perform_dump failed" >&2; exit 1; fi),
ensuring any non-zero return from perform_dump causes the script to exit with
error; reference perform_dump and the surrounding echo "Running dbmate dump with
$PSQLBIN" to locate where to add this check.
- Around line 56-57: The cleanup function currently calls pg_ctl without a
versioned path which can pick up a mismatched system binary; change cleanup to
invoke the pg_ctl from the selected Postgres bindir (use PSQLBIN so it runs as
"$PSQLBIN/pg_ctl" with DATDIR) and ensure PSQLBIN is exported or set as a global
variable before any call to migrate_version(); alternatively, move cleanup to be
a nested function inside migrate_version() so it closes over the correct
PSQLBIN—update references to the cleanup and migrate_version functions and
ensure PSQLBIN is initialized prior to their use.

In `@nix/packages/migrate-tool.nix`:
- Around line 30-33: The error message inside the conditional that checks if [[
$2 == /nix/store* ]] incorrectly references $1; update the echo to reference $2
so the reported path matches the validated value (i.e., change the message in
the block that checks for "$2/receipt.json" to echo "ERROR: $2 does not look
like a valid Postgres install" and keep the exit 1).

In `@nix/packages/start-replica.nix`:
- Line 36: Fix the typo in the user-facing message: locate the echo statement
that reads echo "NOTE: runing pg_basebackup for server on port $MASTER_PORTNO"
and correct "runing" to "running" so the message becomes "NOTE: running
pg_basebackup for server on port $MASTER_PORTNO".

In `@nix/tools/sync-exts-versions.sh.in`:
- Around line 188-192: The case pattern "ptap_release" in the case statement
doesn't match the variable name varname="pgtap_release", so the pgtap extension
branch never runs; update the case label from "ptap_release" to "pgtap_release"
to match the ansible var key and ensure the branch calls run_sync "$varname"
"$package_name" for pgtap_release.
- Around line 44-49: The echo uses an undefined variable $key inside the
run_sync scope; replace $key with the existing $varname (or if $key was
intended, add $key as a parameter to run_sync). Locate the block around run_sync
where version is computed (look for version=$(echo "$ansible_vars" | jq -r
".$varname")), change the echo to reference $varname (echo "$varname: $version")
so the correct variable is printed, or alternatively update the function
signature to accept $key and use that consistently when calling sync_version
"$package_name" "$version" "$hash".
- Around line 94-99: The echo in run_sync_fetchurl references an undefined $key
(same bug as run_sync); update the function to either derive key or simply echo
the package identifier already in scope—replace the use of $key with
$package_name (or set key="$package_name" before use) so that the line echo
"$key: $version" becomes valid; touch the run_sync_fetchurl function and ensure
other uses in that block (version, package_name, url, hash,
sync_version_fetchurl) remain unchanged.
🧹 Nitpick comments (6)
nix/tools/sync-exts-versions.sh.in (1)

7-26: Consider consolidating nearly identical functions.

fetch_source_url and fetchurl_source_url are almost identical — the only difference is that fetch_source_url uses --unpack flag while fetchurl_source_url doesn't. Similarly, sync_version vs sync_version_fetchurl differ only in the attribute path (src.hash vs src.sha256), and run_sync vs run_sync_fetchurl differ only in which helper functions they call.

Consider parameterizing these functions to reduce duplication and maintenance burden.

♻️ Example consolidation for fetch functions
+fetch_source_url_impl() {
+    local source_url=${1//\"/}
+    source_url=${source_url//\'/}
+    local unpack_flag=${2:-""}
+    
+    if [ -z "$source_url" ]; then
+        echo "Usage: fetch_source_url_impl <source_url> [--unpack]"
+        return 1
+    fi
+    
+    echo "$source_url"
+    local initial_hash
+    initial_hash=$(nix-prefetch-url --type sha256 "$source_url" $unpack_flag | cut -d ' ' -f 2)
+    local final_hash
+    final_hash=$(nix hash to-sri --type sha256 "$initial_hash")
+    echo "$final_hash"
+}
+
 fetch_source_url() {
-    # ... full implementation
+    fetch_source_url_impl "$1" "--unpack"
 }
+
 fetchurl_source_url() {
-    # ... full implementation
+    fetch_source_url_impl "$1" ""
 }

Also applies to: 56-75

nix/packages/start-replica.nix (2)

33-34: Redundant mkdir -p after mktemp -d.

mktemp -d already creates the directory, so the subsequent mkdir -p "$DATDIR" is unnecessary.

♻️ Proposed fix
     REPLICA_SLOT="replica_$RANDOM"
     DATDIR=$(mktemp -d)
-    mkdir -p "$DATDIR"

11-25: Consider simplifying version handling or adding support for other versions.

Versions 16 and orioledb-16 are handled but immediately error out. If these versions are not intended to be supported, consider either:

  1. Removing these branches and letting the else clause handle unknown versions
  2. Adding TODO comments indicating future support plans
  3. Actually implementing support (the function signature only receives psql_15)

Currently, the explicit error messages are more helpful than a generic "invalid version" message, so this is a minor observation.

nix/packages/start-client.nix (1)

95-101: Consider removing unused environment variables.

POSTGRES_DB and POSTGRES_HOST are exported but the psql command on line 101 uses explicit arguments (-h localhost and positional postgres). These exports appear unused unless intended for other tooling.

🔧 Suggested cleanup
     # Set up environment for psql
     export PATH="$BINDIR/bin:$PATH"
-    export POSTGRES_DB=postgres
-    export POSTGRES_HOST=localhost

     # Start interactive psql session
     exec psql -U "$PSQL_USER" -p "$PORTNO" -h localhost postgres
nix/packages/cleanup-ami.nix (1)

27-38: Consider making the region configurable.

The region is hardcoded to ap-southeast-1. If AMIs need to be cleaned up in other regions, consider adding an optional --region flag or defaulting to AWS_DEFAULT_REGION if set.

🔧 Suggested enhancement
     AMI_NAME="$1"
-    REGION="ap-southeast-1"
+    REGION="''${AWS_DEFAULT_REGION:-ap-southeast-1}"

     # Deregister AMIs
nix/packages/migrate-tool.nix (1)

1-10: Include coreutils/gnused in runtimeInputs for hermetic execution.

The script relies on external utilities (mktemp/sed/cat/rm). Adding explicit runtime inputs avoids host PATH coupling.

♻️ Suggested update
@@
-{ writeShellApplication, psql_15 }:
+{ writeShellApplication, psql_15, coreutils, gnused }:
@@
-  runtimeInputs = [ ];
+  runtimeInputs = [ coreutils gnused ];

run-testinfra = mkApp "run-testinfra";
cleanup-ami = mkApp "cleanup-ami";
trigger-nix-build = mkApp "trigger-nix-build";
supascan = mkApp "supascan" "supascan";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix the supascan app declaration - still using old two-argument form.

The mkApp helper was refactored to accept only one argument, but supascan still uses the old two-argument form. This will cause a Nix evaluation error because the result of mkApp "supascan" is an attribute set, which cannot be called as a function with the second "supascan" argument.

🐛 Proposed fix
-        supascan = mkApp "supascan" "supascan";
+        supascan = mkApp "supascan";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
supascan = mkApp "supascan" "supascan";
supascan = mkApp "supascan";
🤖 Prompt for AI Agents
In `@nix/apps.nix` at line 30, The app declaration uses the old two-argument form
of mkApp; update the supascan entry to call mkApp with a single argument (remove
the second "supascan" argument) so it matches the refactored signature of mkApp
and returns the expected attribute set (i.e., change the line referencing mkApp
"supascan" "supascan" to a single-argument call to mkApp "supascan").

Comment on lines +27 to +29
# Default values
PSQL_VERSION="ALL"
PORTNO="${defaults.port}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Default PSQL_VERSION should match the “all” branch.

With PSQL_VERSION="ALL", the default path won’t match the all check and will attempt to build psql_ALL.

🐛 Proposed fix
-    PSQL_VERSION="ALL"
+    PSQL_VERSION="all"

Also applies to: 315-316

🤖 Prompt for AI Agents
In `@nix/packages/dbmate-tool.nix` around lines 27 - 29, The default PSQL_VERSION
is set to "ALL" but the build logic expects "all"; change the default to
PSQL_VERSION="all" (and update the other occurrences of PSQL_VERSION="ALL" at
the other default block referenced) so path checks and the psql_${PSQL_VERSION}
branch match the lowercase "all" branch; leave PORTNO="${defaults.port}" as-is.

Comment on lines +56 to +57
# Use pg_ctl to stop PostgreSQL
pg_ctl -D "$DATDIR" stop
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

cat -n nix/packages/dbmate-tool.nix

Repository: supabase/postgres

Length of output: 14235


Fix pg_ctl version mismatch in cleanup function.

The cleanup function uses pg_ctl without a versioned path. It may run before PATH is updated (line 241) or after migrate_version() returns (lines 321, 326), potentially picking a mismatched or system pg_ctl.

Consider exporting PSQLBIN as a global variable before calling migrate_version(), or wrapping cleanup() as a nested function inside migrate_version() to access its scope.

🤖 Prompt for AI Agents
In `@nix/packages/dbmate-tool.nix` around lines 56 - 57, The cleanup function
currently calls pg_ctl without a versioned path which can pick up a mismatched
system binary; change cleanup to invoke the pg_ctl from the selected Postgres
bindir (use PSQLBIN so it runs as "$PSQLBIN/pg_ctl" with DATDIR) and ensure
PSQLBIN is exported or set as a global variable before any call to
migrate_version(); alternatively, move cleanup to be a nested function inside
migrate_version() so it closes over the correct PSQLBIN—update references to the
cleanup and migrate_version functions and ensure PSQLBIN is initialized prior to
their use.

Comment on lines +290 to +291
echo "Running dbmate dump with $PSQLBIN"
perform_dump
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fail fast when pg_dump retries exhaust.

perform_dump failure is ignored, which can propagate a missing/partial schema file.

🐛 Proposed fix
-        perform_dump
+        if ! perform_dump; then
+            echo "Error: pg_dump failed"
+            exit 1
+        fi
🤖 Prompt for AI Agents
In `@nix/packages/dbmate-tool.nix` around lines 290 - 291, The script currently
ignores failures from perform_dump which can leave a missing/partial schema;
update the call after echo "Running dbmate dump with $PSQLBIN" to check
perform_dump's exit status and fail fast (e.g., run perform_dump && true || {
echo "dbmate dump failed"; exit 1; } or simply if ! perform_dump; then echo
"perform_dump failed" >&2; exit 1; fi), ensuring any non-zero return from
perform_dump causes the script to exit with error; reference perform_dump and
the surrounding echo "Running dbmate dump with $PSQLBIN" to locate where to add
this check.

Comment on lines +30 to +33
if [[ $2 == /nix/store* ]]; then
if [ ! -L "$2/receipt.json" ] || [ ! -e "$2/receipt.json" ]; then
echo "ERROR: $1 does not look like a valid Postgres install"
exit 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix the new-version validation error message.

The error currently references $1, so invalid $2 paths are misreported.

🐛 Proposed fix
-            echo "ERROR: $1 does not look like a valid Postgres install"
+            echo "ERROR: $2 does not look like a valid Postgres install"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ $2 == /nix/store* ]]; then
if [ ! -L "$2/receipt.json" ] || [ ! -e "$2/receipt.json" ]; then
echo "ERROR: $1 does not look like a valid Postgres install"
exit 1
if [[ $2 == /nix/store* ]]; then
if [ ! -L "$2/receipt.json" ] || [ ! -e "$2/receipt.json" ]; then
echo "ERROR: $2 does not look like a valid Postgres install"
exit 1
🤖 Prompt for AI Agents
In `@nix/packages/migrate-tool.nix` around lines 30 - 33, The error message inside
the conditional that checks if [[ $2 == /nix/store* ]] incorrectly references
$1; update the echo to reference $2 so the reported path matches the validated
value (i.e., change the message in the block that checks for "$2/receipt.json"
to echo "ERROR: $2 does not look like a valid Postgres install" and keep the
exit 1).

DATDIR=$(mktemp -d)
mkdir -p "$DATDIR"
echo "NOTE: runing pg_basebackup for server on port $MASTER_PORTNO"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Typo: "runing" should be "running".

Minor typo in user-facing message.

📝 Proposed fix
-    echo "NOTE: runing pg_basebackup for server on port $MASTER_PORTNO"
+    echo "NOTE: running pg_basebackup for server on port $MASTER_PORTNO"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
echo "NOTE: runing pg_basebackup for server on port $MASTER_PORTNO"
echo "NOTE: running pg_basebackup for server on port $MASTER_PORTNO"
🤖 Prompt for AI Agents
In `@nix/packages/start-replica.nix` at line 36, Fix the typo in the user-facing
message: locate the echo statement that reads echo "NOTE: runing pg_basebackup
for server on port $MASTER_PORTNO" and correct "runing" to "running" so the
message becomes "NOTE: running pg_basebackup for server on port $MASTER_PORTNO".

Comment on lines +44 to 49
version=$(echo "$ansible_vars" | jq -r ".$varname")
echo "$key: $version"
url=$($_nix eval .#psql_15/exts/$package_name.src.url)
hash=$(fetch_source_url $url | tail -n 1)
$(sync_version $package_name $version $hash)
url=$(nix eval ".#psql_15/exts/$package_name.src.url")
hash=$(fetch_source_url "$url" | tail -n 1)
sync_version "$package_name" "$version" "$hash"
echo "synced $package_name to version $version with hash $hash"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Undefined variable $key used instead of $varname.

On line 45, $key is referenced but it's not defined in the run_sync function scope. This will output an empty or incorrect value. The variable should likely be $varname or the function should receive $key as a parameter.

🐛 Proposed fix
 run_sync() {
     local varname=$1
     local package_name=$2

     version=$(echo "$ansible_vars" |  jq -r ".$varname")
-    echo "$key: $version"
+    echo "$varname: $version"
     url=$(nix eval ".#psql_15/exts/$package_name.src.url")
     hash=$(fetch_source_url "$url" | tail -n 1)
     sync_version "$package_name" "$version" "$hash"
     echo "synced $package_name to version $version with hash $hash"
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
version=$(echo "$ansible_vars" | jq -r ".$varname")
echo "$key: $version"
url=$($_nix eval .#psql_15/exts/$package_name.src.url)
hash=$(fetch_source_url $url | tail -n 1)
$(sync_version $package_name $version $hash)
url=$(nix eval ".#psql_15/exts/$package_name.src.url")
hash=$(fetch_source_url "$url" | tail -n 1)
sync_version "$package_name" "$version" "$hash"
echo "synced $package_name to version $version with hash $hash"
version=$(echo "$ansible_vars" | jq -r ".$varname")
echo "$varname: $version"
url=$(nix eval ".#psql_15/exts/$package_name.src.url")
hash=$(fetch_source_url "$url" | tail -n 1)
sync_version "$package_name" "$version" "$hash"
echo "synced $package_name to version $version with hash $hash"
🤖 Prompt for AI Agents
In `@nix/tools/sync-exts-versions.sh.in` around lines 44 - 49, The echo uses an
undefined variable $key inside the run_sync scope; replace $key with the
existing $varname (or if $key was intended, add $key as a parameter to
run_sync). Locate the block around run_sync where version is computed (look for
version=$(echo "$ansible_vars" | jq -r ".$varname")), change the echo to
reference $varname (echo "$varname: $version") so the correct variable is
printed, or alternatively update the function signature to accept $key and use
that consistently when calling sync_version "$package_name" "$version" "$hash".

Comment on lines +94 to 99
version=$(echo "$ansible_vars" | jq -r ".$varname")
echo "$key: $version"
url=$($_nix eval .#psql_15/exts/$package_name.src.url)
hash=$(fetchurl_source_url $url | tail -n 1)
$(sync_version_fetchurl $package_name $version $hash)
url=$(nix eval ".#psql_15/exts/$package_name.src.url")
hash=$(fetchurl_source_url "$url" | tail -n 1)
sync_version_fetchurl "$package_name" "$version" "$hash"
echo "synced $package_name to version $version with hash $hash"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Same undefined variable issue in run_sync_fetchurl.

Line 95 has the same problem as run_sync$key is not defined in this function's scope.

🐛 Proposed fix
 run_sync_fetchurl() {
     local varname=$1
     local package_name=$2

     version=$(echo "$ansible_vars" |  jq -r ".$varname")
-    echo "$key: $version"
+    echo "$varname: $version"
     url=$(nix eval ".#psql_15/exts/$package_name.src.url")
     hash=$(fetchurl_source_url "$url" | tail -n 1)
     sync_version_fetchurl "$package_name" "$version" "$hash"
     echo "synced $package_name to version $version with hash $hash"
 }
🤖 Prompt for AI Agents
In `@nix/tools/sync-exts-versions.sh.in` around lines 94 - 99, The echo in
run_sync_fetchurl references an undefined $key (same bug as run_sync); update
the function to either derive key or simply echo the package identifier already
in scope—replace the use of $key with $package_name (or set key="$package_name"
before use) so that the line echo "$key: $version" becomes valid; touch the
run_sync_fetchurl function and ensure other uses in that block (version,
package_name, url, hash, sync_version_fetchurl) remain unchanged.

Comment on lines 188 to 192
"ptap_release")
varname="pgtap_release"
package_name="pgtap"
run_sync $varname $package_name
run_sync "$varname" "$package_name"
;;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Typo in case pattern: ptap_release should be pgtap_release.

The case pattern on line 188 is "ptap_release" but the varname on line 189 is "pgtap_release". This mismatch means the pgtap extension will never be synced since the case pattern won't match the ansible var key.

🐛 Proposed fix
-        "ptap_release")
+        "pgtap_release")
             varname="pgtap_release"
             package_name="pgtap"
             run_sync "$varname" "$package_name"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"ptap_release")
varname="pgtap_release"
package_name="pgtap"
run_sync $varname $package_name
run_sync "$varname" "$package_name"
;;
"pgtap_release")
varname="pgtap_release"
package_name="pgtap"
run_sync "$varname" "$package_name"
;;
🤖 Prompt for AI Agents
In `@nix/tools/sync-exts-versions.sh.in` around lines 188 - 192, The case pattern
"ptap_release" in the case statement doesn't match the variable name
varname="pgtap_release", so the pgtap extension branch never runs; update the
case label from "ptap_release" to "pgtap_release" to match the ansible var key
and ensure the branch calls run_sync "$varname" "$package_name" for
pgtap_release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants