Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
99ac48b
feat(nix): add site-update tool
brainrake Sep 8, 2026
1b18ce2
ci: publish site-env catalogs, extend release path filter
brainrake Sep 8, 2026
730068b
feat(nix): add site-update tool
brainrake Sep 8, 2026
bcdd996
test(nix): add minimal NixOS VM test for site-update
brainrake Sep 9, 2026
430559e
feat(nix): unify site-update around a generic <env> arg
brainrake Sep 9, 2026
0a4c70b
rename site-update to update-profile, take (profile, sha) not (sha, env)
brainrake Sep 9, 2026
eee3f28
rename site-extensions-update to update-site-extensions, split apply …
brainrake Sep 9, 2026
1421a46
update-profile: make sha optional when UPDATE_PROFILE_CATALOG is set
brainrake Sep 9, 2026
0cd5b68
update-profile: drop pkgs.awscli2, assume aws is provided by the envi…
brainrake Sep 9, 2026
540ec41
inline update-profile-paths back into update-site-extensions
brainrake Sep 12, 2026
4735970
Merge branch 'develop' into martonboros/mpg-12-site-env-update
brainrake Sep 12, 2026
4077c97
update-profile, update-site-extensions: assume nix is on PATH
brainrake Sep 18, 2026
5d7a25b
trim comments
brainrake Sep 18, 2026
cbcc8ab
split update-site (catalog fetch) out of update-profile
brainrake Sep 18, 2026
57dd1e4
site profile: single 'site' profile with self-describing marker
brainrake Sep 18, 2026
05b504d
bake site profile into postgresql.conf, add supautils-load VM test
brainrake Sep 18, 2026
8011d87
site-env catalogs: use public artifacts bucket + curl, drop aws dep
brainrake Sep 18, 2026
95e4d4e
revert site-env catalogs to private bucket + aws
brainrake Sep 18, 2026
5dc5f8f
restore shortened update-site-extensions doc comment
brainrake Sep 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/ami-release-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- flake.lock
- flake.nix
- nix/packages/build-ami.nix
- nix/**
workflow_dispatch:

permissions:
Expand Down Expand Up @@ -203,6 +204,24 @@ jobs:

echo "Catalog uploaded to ${CATALOG_S3}"

- name: Update site-env catalogs
run: |
GIT_SHA="${{ steps.resolve-git-sha.outputs.sha }}"
SYSTEM=$(nix eval --impure --raw --expr 'builtins.currentSystem')

SITE_ENV_NAME="site-env-${POSTGRES_MAJOR_VERSION}"
SITE_ENV_PATH=$(nix eval --raw ".#${SITE_ENV_NAME}.outPath")
jq -n --arg sys "$SYSTEM" --arg path "$SITE_ENV_PATH" '{($sys): $path}' > /tmp/site-env-catalog.json
aws s3 cp /tmp/site-env-catalog.json \
"s3://${{ secrets.SHARED_AWS_ARTIFACTS_BUCKET }}/nix-catalog/${GIT_SHA}-${SITE_ENV_NAME}-${SYSTEM}.json" \
--content-type "application/json"

UPDATE_SITE_PATH=$(nix eval --raw ".#update-site.outPath")
jq -n --arg sys "$SYSTEM" --arg path "$UPDATE_SITE_PATH" '{($sys): $path}' > /tmp/update-site-catalog.json
aws s3 cp /tmp/update-site-catalog.json \
"s3://${{ secrets.SHARED_AWS_ARTIFACTS_BUCKET }}/nix-catalog/${GIT_SHA}-update-site-${SYSTEM}.json" \
--content-type "application/json"

- name: Create release
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
with:
Expand Down
2 changes: 1 addition & 1 deletion ansible/files/postgresql_config/postgresql.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ jit_provider = 'llvmjit' # JIT library to use

# - Other Defaults -

#dynamic_library_path = '$libdir'
dynamic_library_path = '/nix/var/nix/profiles/site/lib:$libdir'
#gin_fuzzy_search_limit = 0

#------------------------------------------------------------------------------
Expand Down
22 changes: 22 additions & 0 deletions ansible/tasks/stage2-setup-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@
nix-env --set {{ postgres_env_path.stdout }}
"

- name: Resolve site env store path
ansible.builtin.shell: |
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh &&
nix build --no-link --print-out-paths github:supabase/postgres/{{ git_commit_sha }}#site-env-{{ postgresql_major_version }}
register: site_env_path

- name: Install site env from nix binary cache
ansible.builtin.shell: |
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh &&
nix-env --profile /nix/var/nix/profiles/site --set {{ site_env_path.stdout }}

- name: Resolve update-site store path
ansible.builtin.shell: |
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh &&
nix build --no-link --print-out-paths github:supabase/postgres/{{ git_commit_sha }}#update-site
register: update_site_path

- name: Install update-site
ansible.builtin.shell: |
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh &&
nix-env --profile /nix/var/nix/profiles/update-site --set {{ update_site_path.stdout }}

- name: Install supascan for baseline validation
ansible.builtin.shell: |
sudo -u ubuntu bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#supascan"
Expand Down
44 changes: 44 additions & 0 deletions nix/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,50 @@
wal-g-3
;
devShell = self'.devShells.default;
site =
let
system = pkgs.pkgsLinux.stdenv.hostPlatform.system;
update-profile = self.packages.${system}.update-profile;
site-env-17 = self.packages.${system}."site-env-17";
psql_17 = self.legacyPackages.${system}."psql_17".bin;
pgConf = pkgs.writeText "postgresql-test.conf" ''
dynamic_library_path = '/nix/var/nix/profiles/site/lib:$libdir'
session_preload_libraries = 'supautils'
listen_addresses = 'localhost'
unix_socket_directories = '/tmp'
'';
in
pkgs.testers.runNixOSTest {
name = "site";
nodes.machine =
{ ... }:
{
environment.systemPackages = [
update-profile
site-env-17
];
users.users.postgres = {
isSystemUser = true;
group = "postgres";
shell = pkgs.bash;
};
users.groups.postgres = { };
};
testScript = ''
machine.succeed("update-profile site ${site-env-17}")
machine.succeed("[ \"$(readlink -f /nix/var/nix/profiles/site)\" = \"${site-env-17}\" ]")

# idempotent
machine.succeed("update-profile site ${site-env-17}")

# postgres can load supautils via the site profile's dynamic_library_path
machine.succeed("install -d -o postgres -g postgres /tmp/pgdata")
machine.succeed("su postgres -c '${psql_17}/bin/initdb -D /tmp/pgdata'")
machine.succeed("install -o postgres -g postgres ${pgConf} /tmp/pgdata/postgresql.conf")
machine.succeed("su postgres -c '${psql_17}/bin/pg_ctl -D /tmp/pgdata -l /tmp/pg.log start'")
machine.succeed("su postgres -c '${psql_17}/bin/psql -h localhost -d postgres -c \"select 1\"'")
'';
};
}
// (import ./ext/tests {
inherit self;
Expand Down
21 changes: 9 additions & 12 deletions nix/packages/extension-catalog.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@
makeWrapper ${self'.packages.site-extensions-resolve}/bin/site-extensions-resolve \
"$out/bin/site-extensions-resolve" \
--set PG_EXTENSIONS_CATALOG "$out/share/pg-extensions-catalog.json"
makeWrapper ${self'.packages.site-extensions-update}/bin/site-extensions-update \
"$out/bin/site-extensions-update" \
makeWrapper ${self'.packages.update-site-extensions}/bin/update-site-extensions \
"$out/bin/update-site-extensions" \
--set PG_EXTENSIONS_CATALOG "$out/share/pg-extensions-catalog.json"
''
)
Expand Down Expand Up @@ -146,19 +146,16 @@
'';
};

# Takes manifest json as argument.
# Downloads paths and installs them as an env into the profile, replacing all existing ones.
site-extensions-update = pkgs.writeShellApplication {
name = "site-extensions-update";
runtimeInputs = [
self'.packages.site-extensions-resolve
pkgs.nix
];
# Downloads the manifest's paths and installs them as the profile's env, replacing all existing ones.
# nix comes from the environment.
update-site-extensions = pkgs.writeShellApplication {
name = "update-site-extensions";
runtimeInputs = [ self'.packages.site-extensions-resolve ];
text = ''
manifest="''${1:?Usage: $0 path-to/pg-extensions.json}"
profile="''${NIX_PROFILE:-/nix/var/nix/profiles/site-extensions}"
profile="/nix/var/nix/profiles/site-extensions"
readarray -t paths < <(site-extensions-resolve "$manifest")
nix-store -r --option stalled-download-timeout 120 "''${paths[@]}" >/dev/null
nix-store --realise --option stalled-download-timeout 120 "''${paths[@]}" >/dev/null
nix-env --profile "$profile" --install "''${paths[@]}" --remove-all
'';
};
Expand Down
47 changes: 44 additions & 3 deletions nix/packages/site-env.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# These are envs (package sets per pg major version) deployed to instances
# at /nix/var/nix/profiles/site and updated regularly.
{
perSystem =
{
Expand All @@ -14,6 +13,7 @@
pkgs.buildEnv {
name = "site-env-${version}";
paths = [ self'.legacyPackages."psql_${version}".exts.supautils ] ++ extraPaths;
postBuild = "echo site-env-${version} > $out/site-env-name";
};

siteEnvs = {
Expand All @@ -28,9 +28,50 @@
lib.optionals pkgs.stdenv.isLinux [ self'.packages.gatekeeper ]
);
};

# Set the named nix profile to the provided nix store path.
# aws and nix come from the environment.
update-profile = pkgs.writeShellApplication {
name = "update-profile";
text = ''
profile_name="''${1:?Usage: $0 <profile> <path>}"
path="''${2:?Usage: $0 <profile> <path>}"
profile_path="/nix/var/nix/profiles/''${profile_name}"

[[ "$(readlink -f "$profile_path")" == "$path" ]] && exit 0
nix-store --realise --option stalled-download-timeout 120 "$path" >/dev/null
nix-env --profile "$profile_path" --set "$path"
'';
};

# Fetch catalog and update site profile from given postgres repo hash.
# aws and nix come from the environment.
update-site = pkgs.writeShellApplication {
name = "update-site";
runtimeInputs = [
pkgs.jq
update-profile
];
text = ''
sha="''${1:?Usage: $0 <git-sha>}"
system="$(uname -m)-linux"
variant="$(cat /nix/var/nix/profiles/site/site-env-name)"
catalog="/tmp/''${variant}-catalog-''${sha}-''${system}.json"

aws s3 cp "s3://supabase-internal-artifacts/nix-catalog/''${sha}-''${variant}-''${system}.json" \
"$catalog" --region ap-southeast-1
path="$(jq -er --arg s "$system" '.[$s]' "$catalog")"

update-profile site "$path"
'';
};
in
{
packages = siteEnvs;
legacyPackages = siteEnvs;
packages = siteEnvs // {
inherit update-profile update-site;
};
legacyPackages = siteEnvs // {
inherit update-profile update-site;
};
};
}
Loading