Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e0c35ce
ci(ami): pass postgres env store path to packer via var
brainrake Oct 16, 2026
7482ddc
ci(ami): drop separate realise step
brainrake Oct 16, 2026
98cb0ff
ci(ami): pass all stage 2 nix store paths to packer via var
brainrake Oct 19, 2026
04927e2
Merge remote-tracking branch 'origin/develop' into ci/pass-nix-store-…
brainrake Oct 19, 2026
7ddc4be
ci(qemu): pass nix store paths to packer via var
brainrake Oct 19, 2026
5f66a29
ci(ami): pass nix store paths via vars file
brainrake Oct 19, 2026
040357d
ci(ami): define stage 2 store paths in the flake
brainrake Oct 20, 2026
d24b033
ci(ami): rename store paths attribute
brainrake Oct 20, 2026
637d961
Merge branch 'develop' into ci/pass-nix-store-paths-via-vars
brainrake Oct 20, 2026
92a898a
ci(ami): pass nix store paths via PKR_VAR env
brainrake Oct 20, 2026
9bd00c6
Merge remote-tracking branch 'origin/develop' into ci/pass-nix-store-…
brainrake Oct 20, 2026
f60fd68
Merge remote-tracking branch 'origin/ci/pass-nix-store-paths-via-vars…
brainrake Oct 20, 2026
ae1592c
Merge remote-tracking branch 'origin/develop' into ci/pass-nix-store-…
brainrake Oct 21, 2026
5cf4174
ci(ami): build nix store paths on the runner
brainrake Oct 21, 2026
b16726c
ci(ami): use become_user and -var for nix store paths
brainrake Oct 21, 2026
7b24d0d
ci(ami): pass nix store paths via provisioner env
brainrake Oct 21, 2026
e2d6e79
ci(ami): drop unused git_sha packer var
brainrake Oct 21, 2026
c0f15f3
ci(ami): drop remaining sudo in stage 2 postgres tasks
brainrake Oct 21, 2026
0a17486
ci(ami): build the extra-vars json in packer
brainrake Oct 22, 2026
4f445b6
Merge remote-tracking branch 'origin/develop' into ci/pass-nix-store-…
brainrake Oct 22, 2026
89dfb50
ci(qemu): push nix build outputs to the binary cache
brainrake Oct 22, 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
4 changes: 4 additions & 0 deletions .github/workflows/qemu-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ jobs:

- name: Install Nix
uses: $/.github/actions/install-nix
with:
push-to-cache: true
nix-signing-key: ${{ secrets.NIX_SIGN_SECRET_KEY }}
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}

- name: Run checks if triggered manually
if: ${{ github.event_name == 'workflow_dispatch' && matrix.arch == 'arm64' }}
Expand Down
2 changes: 1 addition & 1 deletion ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
when: stage2
shell: >-
baseline={{ 'ami' if not qemu else 'qemu' }}-build-{{ platform }}
nix shell github:supabase/postgres/{{ git_commit_sha }}#supascan --command
nix shell {{ nix_store_paths['supascan'] }} --command
/tmp/ansible-playbook/ansible/files/supascan_ami.sh
/tmp/ansible-playbook/audit-specs/baselines/$baseline

Expand Down
2 changes: 1 addition & 1 deletion ansible/tasks/setup-pgbackrest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
- name: Install pgBackRest
when: stage2
ansible.builtin.shell: |
sudo -u pgbackrest bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#pg-backrest"
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install {{ nix_store_paths['pg-backrest'] }}
become: true
become_user: pgbackrest
changed_when: true
Expand Down
3 changes: 2 additions & 1 deletion ansible/tasks/setup-pgbouncer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
- name: Install PgBouncer from nix binary cache
when: stage2
ansible.builtin.shell:
cmd: sudo -u pgbouncer bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#pgbouncer"
cmd: . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install {{ nix_store_paths['pgbouncer'] }}
become: true
become_user: pgbouncer

- name: Link PgBouncer into /usr/local/bin
when: stage2
Expand Down
5 changes: 3 additions & 2 deletions ansible/tasks/setup-wal-g.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@
block:
- name: Install wal-g 2 from nix binary cache
ansible.builtin.shell:
cmd: sudo -u wal-g bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#wal-g-2"
cmd: . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install {{ nix_store_paths['wal-g-2'] }}
become: true
become_user: wal-g

# Installed alongside v2 (INDATA-904). The /usr/local/bin/wal-g symlink below
# only points at v3 on orioledb builds; v2 remains the default everywhere else.
- name: Install wal-g 3 from nix binary cache
ansible.builtin.shell:
cmd: . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#wal-g-3
cmd: . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install {{ nix_store_paths['wal-g-3'] }}
become: true
become_user: wal-g

Expand Down
24 changes: 9 additions & 15 deletions ansible/tasks/stage2-setup-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,17 @@
when: stage2
become: true
block:
- name: Resolve postgres env store path
ansible.builtin.shell: |
sudo -u postgres bash -c "
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh &&
nix build --no-link --print-out-paths github:supabase/postgres/{{ git_commit_sha }}#postgres-env-{{ postgres_major_version }}
"
register: postgres_env_path

- name: Install postgres env from nix binary cache
ansible.builtin.shell: |
sudo -u postgres bash -c "
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh &&
nix-env --set {{ postgres_env_path.stdout }}
Comment thread
brainrake marked this conversation as resolved.
"
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh &&
nix-env --quiet --set {{ nix_store_paths['postgres-env'] }}
become: true
become_user: postgres

- name: Install and activate 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 }} &&
nix-env --profile /nix/var/nix/profiles/site --set {{ nix_store_paths['site-env'] }} &&
/nix/var/nix/profiles/site/bin/activate

- name: Set ownership and permissions for file and dirs
Expand Down Expand Up @@ -126,11 +118,13 @@
- name: Create symbolic link for linux-pam to find pam_jit_pg.so
become: yes
shell: |
sudo ln -s /var/lib/postgresql/.nix-profile/lib/security/pam_jit_pg.so $(find /nix/store -type d -path "/nix/store/*-linux-pam-*/lib/security" -print -quit)/pam_jit_pg.so
ln -s /var/lib/postgresql/.nix-profile/lib/security/pam_jit_pg.so $(find /nix/store -type d -path "/nix/store/*-linux-pam-*/lib/security" -print -quit)/pam_jit_pg.so

- name: Get gatekeeper version
ansible.builtin.shell: |
sudo -u postgres bash -c "/nix/var/nix/profiles/default/bin/nix-store -q --requisites ~/.nix-profile | awk -F- '/gatekeeper/{print \$NF}'"
/nix/var/nix/profiles/default/bin/nix-store -q --requisites /var/lib/postgresql/.nix-profile | awk -F- '/gatekeeper/{print $NF}'
become: true
become_user: postgres
register: gatekeeper_version

- name: Write version file
Expand Down
5 changes: 2 additions & 3 deletions nix/packages/build-ami/build-ami.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ input_hash=${input_hash#/nix/store/}
input_hash=${input_hash%%-*}

# must run before the cd otherwise we get an error like `error: installable '/nix/store/...-amiSources' does not correspond to a Nix language value`
site_env_path=$(nix eval --raw "github:supabase/postgres/$packages_git_sha#packages.$system.site-env-$postgres_major_version.outPath")
nix_store_paths=$(cat "$(nix build --no-link --print-out-paths "github:supabase/postgres/$packages_git_sha#packages.$system.nix-store-paths-$postgres_major_version")")

cd @amiSources@

Expand Down Expand Up @@ -139,8 +139,7 @@ echo "::group::AMI Build: Stage 2"

packer build "${common_packer_args[@]}" \
-var "ami_name=$ami_name" \
-var "packages_git_sha=$packages_git_sha" \
-var "site_env_path=$site_env_path" \
-var "nix_store_paths=$nix_store_paths" \
-var "source_ami=$stage1_ami_id" \
packer/stage2-nix.pkr.hcl

Expand Down
5 changes: 2 additions & 3 deletions nix/packages/build-qemu-image/build-qemu-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,21 @@ install --mode 644 "$vars" "$workdir/ovmf_vars.fd" # qemu writes to the vars pfl

git_sha=${GIT_SHA:-$(git rev-parse HEAD)}
system=$([[ $arch == arm64 ]] && echo aarch64-linux || echo x86_64-linux)
site_env_path=$(nix eval --raw "github:supabase/postgres/$git_sha#packages.$system.site-env-$postgres_major_version.outPath")
postgres_version=$(yq -er ".postgres_release.postgres$postgres_major_version" ansible/postgres_release.yml)

# Build the cloud-init seed ISO before invoking packer.
cloud-localds "$workdir/seeds-cloudimg.iso" user-data-cloudimg meta-data

nix_store_paths=$(cat "$(nix build --no-link --print-out-paths "github:supabase/postgres/$git_sha#packages.$system.nix-store-paths-$postgres_major_version")")
export LC_ALL=C.UTF-8
export TZ=UTC
packer init packer/qemu.pkr.hcl
PACKER_LOG=${PACKER_LOG:-1} packer build \
-var "arch=$arch" \
-var "cpu=$cpu" \
-var "git_sha=$git_sha" \
-var "machine=$machine" \
-var "nix_store_paths=$nix_store_paths" \
-var "postgres-version=$postgres_version" \
-var "site_env_path=$site_env_path" \
-var "postgres_major_version=$postgres_major_version" \
-var "qemu_binary=$qemu" \
-var "workdir=$workdir" \
Expand Down
19 changes: 19 additions & 0 deletions nix/packages/postgres-env.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,31 @@
self'.legacyPackages."psql_${version}".exts.orioledb.debug
];
};

makeNixStorePaths =
version:
pkgs.writeText "nix-store-paths-${version}.json" (
builtins.toJSON {
inherit (self'.packages)
supascan
pgbouncer
pg-backrest
wal-g-2
wal-g-3
;
postgres-env = self'.packages."postgres-env-${version}";
site-env = self'.packages."site-env-${version}";
}
);
in
{
packages = {
postgres-env-15 = makePostgresEnv "15";
postgres-env-17 = makePostgresEnv "17";
postgres-env-orioledb-17 = makePostgresEnv "orioledb-17";
nix-store-paths-15 = makeNixStorePaths "15";
nix-store-paths-17 = makeNixStorePaths "17";
nix-store-paths-orioledb-17 = makeNixStorePaths "orioledb-17";
};
};
}
11 changes: 2 additions & 9 deletions packer/qemu.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
variable "git_sha" {
type = string
}

variable "site_env_path" {
type = string
}
variable "nix_store_paths" { type = map(string) }

variable "postgres-version" {
type = string
Expand Down Expand Up @@ -112,8 +106,7 @@ build {

provisioner "shell" {
environment_vars = [
"GIT_SHA=${var.git_sha}",
"SITE_ENV_PATH=${var.site_env_path}",
"NIX_STORE_PATHS=${jsonencode({ nix_store_paths = var.nix_store_paths })}",
"POSTGRES_MAJOR_VERSION=${var.postgres_major_version}"
]
use_env_var_file = true
Expand Down
4 changes: 1 addition & 3 deletions packer/scripts/nix-provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ function install_nix() {

function execute_stage2_playbook {
echo "POSTGRES_MAJOR_VERSION: $POSTGRES_MAJOR_VERSION"
echo "GIT_SHA: $GIT_SHA"
mkdir -p /etc/ansible
tee /etc/ansible/ansible.cfg <<-EOF
[defaults]
Expand All @@ -64,8 +63,7 @@ function execute_stage2_playbook {

ansible-playbook /tmp/ansible-playbook/ansible/playbook.yml \
--extra-vars '{"stage2":true, "qemu":false}' \
--extra-vars "git_commit_sha=$GIT_SHA" \
--extra-vars "site_env_path=$SITE_ENV_PATH" \
--extra-vars "$NIX_STORE_PATHS" \
--extra-vars "psql_version=psql_$POSTGRES_MAJOR_VERSION" \
--extra-vars "postgresql_version=postgresql_$POSTGRES_MAJOR_VERSION" \
--extra-vars "postgres_major_version=$POSTGRES_MAJOR_VERSION"
Expand Down
3 changes: 1 addition & 2 deletions packer/scripts/qemu-bootstrap-nix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ function execute_stage2_playbook {
export ANSIBLE_LOG_PATH=/tmp/ansible.log && export ANSIBLE_REMOTE_TEMP=/tmp
ansible-playbook ./ansible/playbook.yml \
--extra-vars '{"stage2": true, "qemu": true}' \
--extra-vars "git_commit_sha=$GIT_SHA" \
--extra-vars "site_env_path=$SITE_ENV_PATH" \
--extra-vars "$NIX_STORE_PATHS" \
--extra-vars "postgresql_version=postgresql_$POSTGRES_MAJOR_VERSION" \
--extra-vars "postgres_major_version=$POSTGRES_MAJOR_VERSION" \
--extra-vars "psql_version=psql_$POSTGRES_MAJOR_VERSION" \
Expand Down
11 changes: 2 additions & 9 deletions packer/stage2-nix.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ variable "git-head-version" {
type = string
}

variable "packages_git_sha" {
type = string
}

variable "packer-execution-id" {
type = string
}

variable "site_env_path" {
type = string
}
variable "nix_store_paths" { type = map(string) }

variable "postgres_major_version" {
type = string
Expand Down Expand Up @@ -150,8 +144,7 @@ build {

provisioner "shell" {
environment_vars = [
"GIT_SHA=${var.packages_git_sha}",
"SITE_ENV_PATH=${var.site_env_path}",
"NIX_STORE_PATHS=${jsonencode({ nix_store_paths = var.nix_store_paths })}",
"POSTGRES_MAJOR_VERSION=${var.postgres_major_version}"
]
use_env_var_file = true
Expand Down
Loading