Skip to content
2 changes: 2 additions & 0 deletions .github/actions/nix-install-ephemeral/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ runs:
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
${{ inputs.push-to-cache == 'true' && 'post-build-hook = /etc/nix/upload-to-cache.sh' || '' }}
extra-experimental-features = auto-allocate-uids cgroups
auto-allocate-uids = true
max-jobs = 4
extra-system-features = kvm
- name: Setup KVM permissions
Expand Down
6 changes: 5 additions & 1 deletion ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@
tags:
- install-supabase-internal
when: debpkg_mode or nixpkg_mode


- name: deploy system-manager
import_tasks: tasks/setup-system-manager.yml
when: debpkg_mode or stage2_nix

- name: Enhance fail2ban
import_tasks: tasks/setup-fail2ban.yml
when: debpkg_mode or nixpkg_mode
Expand Down
11 changes: 11 additions & 0 deletions ansible/tasks/setup-nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Check if nix is installed
ansible.builtin.command: which nix
register: nix_installed
failed_when: nix_installed.rc != 0
ignore_errors: true

- name: Install nix
ansible.builtin.shell: curl --proto '=https' --tlsv1.2 -sSf -L https://artifacts.nixos.org/experimental-installer | sh -s -- install --no-confirm --extra-conf 'substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com' --extra-conf 'trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY='
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The trusted-public-keys value contains an extra % character (...YleiaLI=% ...), which does not match the key used elsewhere in the repo and will likely break Nix’s signature verification / nix.conf parsing. Please remove the % so the key remains exactly ...YleiaLI=.

Suggested change
ansible.builtin.shell: curl --proto '=https' --tlsv1.2 -sSf -L https://artifacts.nixos.org/experimental-installer | sh -s -- install --no-confirm --extra-conf 'substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com' --extra-conf 'trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY='
ansible.builtin.shell: curl --proto '=https' --tlsv1.2 -sSf -L https://artifacts.nixos.org/experimental-installer | sh -s -- install --no-confirm --extra-conf 'substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com' --extra-conf 'trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY='

Copilot uses AI. Check for mistakes.
when: nix_installed.rc != 0
become: true
Comment on lines +2 to +11
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This new setup-nix.yml task file is not referenced by any playbook/import in the repo (no import_tasks: tasks/setup-nix.yml), so it will never run and may drift out of sync. Either wire it into the appropriate playbook/stage or remove it to avoid dead code.

Suggested change
- name: Check if nix is installed
ansible.builtin.command: which nix
register: nix_installed
failed_when: nix_installed.rc != 0
ignore_errors: true
- name: Install nix
ansible.builtin.shell: curl --proto '=https' --tlsv1.2 -sSf -L https://artifacts.nixos.org/experimental-installer | sh -s -- install --no-confirm --extra-conf 'substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com' --extra-conf 'trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY='
when: nix_installed.rc != 0
become: true
# This file previously contained Nix setup tasks but was never referenced
# by any playbook/import, so the tasks were dead code and could drift out
# of sync. It has been intentionally left empty to avoid unused tasks.

Copilot uses AI. Check for mistakes.
14 changes: 14 additions & 0 deletions ansible/tasks/setup-system-manager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Install system-manager from binary cache
ansible.builtin.shell: |
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
nix profile add --accept-flake-config "github:supabase/postgres/{{ git_commit_sha }}#system-manager"
become: true

- name: Build and activate system-manager config
ansible.builtin.shell: |
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
STORE_PATH=$(nix build --accept-flake-config --no-link --print-out-paths "github:supabase/postgres/{{ git_commit_sha }}#systemConfigs.$(nix eval --raw nixpkgs#system).default")
system-manager register --store-path "$STORE_PATH" --sudo
system-manager activate --store-path "$STORE_PATH" --sudo
Comment on lines +12 to +13
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

These tasks run with become: true (root) but pass --sudo to system-manager. Per system-manager docs, --sudo causes it to invoke the sudo binary and is unnecessary (and can fail if sudo is unavailable) when already running as root. Please drop --sudo and rely on Ansible privilege escalation.

Suggested change
system-manager register --store-path "$STORE_PATH" --sudo
system-manager activate --store-path "$STORE_PATH" --sudo
system-manager register --store-path "$STORE_PATH"
system-manager activate --store-path "$STORE_PATH"

Copilot uses AI. Check for mistakes.
become: true
6 changes: 3 additions & 3 deletions ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ postgres_major:

# Full version strings for each major version
postgres_release:
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

postgres_release values now include suffixes (e.g. -sysmg-2 and -orioledb-sysmg-2). This will fail the merge requirements check in .github/workflows/ci.yml which rejects any suffix after the semver (and any text after -orioledb). Please remove these suffixes or move this metadata to a different variable that CI does not validate.

Suggested change
postgres_release:
postgres_release:
postgresorioledb-17: "17.6.0.053-orioledb"
postgres17: "17.6.1.096"
postgres15: "15.14.1.096"
postgres_release_full:

Copilot uses AI. Check for mistakes.
postgresorioledb-17: "17.6.0.061-orioledb"
postgres17: "17.6.1.104"
postgres15: "15.14.1.104"
postgresorioledb-17: "17.6.0.053-orioledb-sysmg-2"
postgres17: "17.6.1.096-sysmg-2"
postgres15: "15.14.1.096-sysmg-2"

# Non Postgres Extensions
pgbouncer_release: 1.25.1
Expand Down
4 changes: 2 additions & 2 deletions audit-specs/baselines/ami-build/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ user:
root:
exists: true
home: /root
shell: /bin/bash
shell: /run/system-manager/sw/bin/bash
ubuntu:
exists: true
home: /home/ubuntu
shell: /bin/bash
nobody:
exists: true
shell: /usr/sbin/nologin
shell: /run/system-manager/sw/bin/nologin

# PostgreSQL ecosystem
postgres:
Expand Down
152 changes: 152 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
rust-overlay.url = "github:oxalica/rust-overlay";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
system-manager.inputs.nixpkgs.follows = "nixpkgs";
system-manager.url = "github:numtide/system-manager";
};

outputs =
Expand All @@ -55,6 +57,8 @@
nix/nixpkgs.nix
nix/packages
nix/overlays
nix/systemModules
nix/systemConfigs.nix
];
});
}
1 change: 1 addition & 0 deletions nix/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ learn how to play with `postgres` in the [build guide](./build-postgres.md).
- **[Start Client/Server](./start-client-server.md)** - Running PostgreSQL client and server
- **[Docker](./docker.md)** - Docker integration and usage
- **[Docker Image Size Analyzer](./image-size-analyzer-usage.md)** - Tool to analyze the Docker image sizes
- **[System Manager](./system-manager.md)** - Declarative system configuration with system-manager
- **[Use direnv](./use-direnv.md)** - Development environment with direnv
- **[Pre-commit Hooks](./pre-commit-hooks.md)** - Automatic formatting and code checks before commits
- **[Nix Formatter](./nix-formatter.md)** - Code formatting with treefmt
Expand Down
18 changes: 17 additions & 1 deletion nix/docs/nix-directory-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ nix/
├── ext/ # PostgreSQL extensions
├── overlays/ # Nixpkgs overlays
├── packages/ # Custom packages
└── postgresql/ # PostgreSQL packages
├── postgresql/ # PostgreSQL packages
├── systemConfigs.nix # system-manager configuration definitions
└── systemModules/ # system-manager service modules
```

## Module Descriptions
Expand Down Expand Up @@ -150,6 +152,20 @@ Nixpkgs overlays for package customization:
- `cargo-pgrx-0-11-3.nix` - PGRX toolchain overlay
- `psql_16-oriole.nix` - OrioleDB PostgreSQL variant

#### `nix/systemConfigs.nix`

System configuration definitions for [system-manager](https://github.com/numtide/system-manager).
Calls `system-manager.lib.makeSystemConfig` to produce a configuration for each supported architecture (`aarch64-linux`, `x86_64-linux`) from the enabled modules.
See [System manager](./system-manager.md) for details.

#### `nix/systemModules/`

Service module definitions managed by system-manager:

- `default.nix` - Module registry that exports modules under `flake.systemModules`
- Individual `.nix` files - Service modules (e.g. nginx) loaded via `flake-parts-lib.importApply`
- `tests/default.nix` - Container-based tests using `makeContainerTest`

#### `nix/cargo-pgrx/`

Rust-based PostgreSQL extension building:
Expand Down
Loading
Loading