From 76fc95b4317ebd456a8e684295332c08f74a7276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Roche?= Date: Mon, 10 Nov 2025 16:20:29 +0100 Subject: [PATCH 1/2] refactor: DRY NixOS test configurations Extract common NixOS test node configuration into common.nix to eliminate duplication across extension tests. Tests with custom requirements use lib.mkMerge to override defaults. This helps us to see at a glance why a test deviates from the standard setup. --- nix/ext/plpgsql-check.nix | 6 -- nix/ext/tests/default.nix | 116 ++++------------------- nix/ext/tests/http.nix | 73 ++------------ nix/ext/tests/lib.nix | 140 +++++++++++++++++++++++++++ nix/ext/tests/pg_repack.nix | 90 ++---------------- nix/ext/tests/pgmq.nix | 69 ++------------ nix/ext/tests/pgroonga.nix | 96 ++++--------------- nix/ext/tests/pgrouting.nix | 163 +++++++++++--------------------- nix/ext/tests/pgsodium.nix | 97 +++++++------------ nix/ext/tests/plpgsql_check.nix | 83 +--------------- nix/ext/tests/plv8.nix | 40 ++------ nix/ext/tests/postgis.nix | 73 ++------------ nix/ext/tests/timescaledb.nix | 44 ++++----- nix/ext/tests/vault.nix | 119 ++++++++--------------- 14 files changed, 361 insertions(+), 848 deletions(-) create mode 100644 nix/ext/tests/lib.nix diff --git a/nix/ext/plpgsql-check.nix b/nix/ext/plpgsql-check.nix index faf918c67..37a978bb4 100644 --- a/nix/ext/plpgsql-check.nix +++ b/nix/ext/plpgsql-check.nix @@ -135,12 +135,6 @@ buildEnv { passthru = { inherit versions numberOfVersions switch-ext-version; hasBackgroundWorker = true; - defaultSettings = { - shared_preload_libraries = [ - "plpgsql" - "plpgsql_check" - ]; - }; version = "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions); }; diff --git a/nix/ext/tests/default.nix b/nix/ext/tests/default.nix index cf4518f60..be278e577 100644 --- a/nix/ext/tests/default.nix +++ b/nix/ext/tests/default.nix @@ -3,19 +3,14 @@ let testsDir = ./.; testFiles = builtins.attrNames (builtins.readDir testsDir); nixFiles = builtins.filter ( - name: builtins.match ".*\\.nix$" name != null && name != "default.nix" + name: builtins.match ".*\\.nix$" name != null && name != "default.nix" && name != "lib.nix" ) testFiles; extTest = extension_name: let pname = extension_name; inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; + versions = postgresqlMajorVersion: (testLib.installedExtension postgresqlMajorVersion).versions; postgresqlWithExtension = postgresql: let @@ -25,7 +20,7 @@ let paths = [ postgresql postgresql.lib - (installedExtension majorVersion) + (testLib.installedExtension majorVersion) ]; passthru = { inherit (postgresql) version psqlSchema; @@ -33,7 +28,7 @@ let withPackages = _: pkg; withJIT = pkg; withoutJIT = pkg; - installedExtensions = [ (installedExtension majorVersion) ]; + installedExtensions = [ (testLib.installedExtension majorVersion) ]; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ @@ -49,97 +44,17 @@ let }; in pkg; - psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = extension_name; + }; + psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; + psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; - nodes.server = - { config, ... }: - { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - services.openssh = { - enable = true; - }; - - services.postgresql = { - enable = true; - package = psql_15; - enableTCPIP = true; - authentication = '' - local all postgres peer map=postgres - local all all peer map=root - ''; - identMap = '' - root root supabase_admin - postgres postgres postgres - ''; - ensureUsers = [ - { - name = "supabase_admin"; - ensureClauses.superuser = true; - } - ]; - settings = (installedExtension "15").defaultSettings or { }; - }; - - networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ]; - - specialisation.postgresql17.configuration = { - services.postgresql = { - package = lib.mkForce psql_17; - settings = (installedExtension "17").defaultSettings or { }; - }; - - systemd.services.postgresql-migrate = { - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - User = "postgres"; - Group = "postgres"; - StateDirectory = "postgresql"; - WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; - }; - script = - let - oldPostgresql = psql_15; - newPostgresql = psql_17; - oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; - newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; - in - '' - if [[ ! -d ${newDataDir} ]]; then - install -d -m 0700 -o postgres -g postgres "${newDataDir}" - ${newPostgresql}/bin/initdb -D "${newDataDir}" - ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ - --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" \ - ${ - if config.services.postgresql.settings.shared_preload_libraries != null then - " --old-options='-c shared_preload_libraries=${config.services.postgresql.settings.shared_preload_libraries}' --new-options='-c shared_preload_libraries=${config.services.postgresql.settings.shared_preload_libraries}'" - else - "" - } - else - echo "${newDataDir} already exists" - fi - ''; - }; - - systemd.services.postgresql = { - after = [ "postgresql-migrate.service" ]; - requires = [ "postgresql-migrate.service" ]; - }; - }; - }; + nodes.server = { config, ... }: testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }; testScript = { nodes, ... }: let @@ -155,12 +70,13 @@ let support_upgrade = True pg17_configuration = "${pg17-configuration}" ext_has_background_worker = ${ - if (installedExtension "15") ? hasBackgroundWorker then "True" else "False" + if (testLib.installedExtension "15") ? hasBackgroundWorker then "True" else "False" } sql_test_directory = Path("${../../tests}") - pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}" - ext_schema = "${(installedExtension "15").defaultSchema or "public"}" - lib_name = "${(installedExtension "15").libName or pname}" + + pg_regress_test_name = "${(testLib.installedExtension "15").pgRegressTestName or pname}" + ext_schema = "${(testLib.installedExtension "15").defaultSchema or "public"}" + lib_name = "${(testLib.installedExtension "15").libName or pname}" print(f"Running tests for extension: {lib_name}") ${builtins.readFile ./lib.py} diff --git a/nix/ext/tests/http.nix b/nix/ext/tests/http.nix index fab6a0d20..e7818ff39 100644 --- a/nix/ext/tests/http.nix +++ b/nix/ext/tests/http.nix @@ -41,76 +41,17 @@ let }; in pkg; + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = pname; + }; + psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; + psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; - nodes.server = - { config, ... }: - { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - services.openssh = { - enable = true; - }; - - services.postgresql = { - enable = true; - package = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - }; - - specialisation.postgresql17.configuration = { - services.postgresql = { - package = lib.mkForce ( - postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17 - ); - }; - - systemd.services.postgresql-migrate = { - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - User = "postgres"; - Group = "postgres"; - StateDirectory = "postgresql"; - WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; - }; - script = - let - oldPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - newPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; - oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; - newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; - in - '' - if [[ ! -d ${newDataDir} ]]; then - install -d -m 0700 -o postgres -g postgres "${newDataDir}" - ${newPostgresql}/bin/initdb -D "${newDataDir}" - ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ - --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" - else - echo "${newDataDir} already exists" - fi - ''; - }; - - systemd.services.postgresql = { - after = [ "postgresql-migrate.service" ]; - requires = [ "postgresql-migrate.service" ]; - }; - }; - }; + nodes.server = { config, ... }: testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }; testScript = { nodes, ... }: let diff --git a/nix/ext/tests/lib.nix b/nix/ext/tests/lib.nix new file mode 100644 index 000000000..f32fa4e38 --- /dev/null +++ b/nix/ext/tests/lib.nix @@ -0,0 +1,140 @@ +# lib.nix +# +# Common utilities and configuration builders for PostgreSQL extension tests. +# +# This module provides reusable functions to create NixOS test nodes with +# standard PostgreSQL configurations, reducing duplication across extension +# test files. +# +# ## Exports +# +# - `installedExtension`: Function to get the installed extension package for a PostgreSQL version +# - `mkDefaultNixosTestNode`: Creates a NixOS test node with standard PostgreSQL setup +# +# ## Examples +# +# See existing test files for real-world examples: +# - Simple tests: postgis.nix, http.nix, plpgsql_check.nix +# - With custom settings: vault.nix, pgsodium.nix +# - With environment variables: pgroonga.nix +# - Complex specialisations: pgrouting.nix +{ + self, + pkgs, + testedExtensionName, +}: +rec { + # Get the installed extension package for a specific PostgreSQL major version. + # + # Type: installedExtension :: String -> Derivation + # + # Example: + # installedExtension "15" => derivation + installedExtension = + postgresMajorVersion: + self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ + testedExtensionName + }"; + + # Create a default NixOS test node with PostgreSQL configured for extension testing. + # + # When psql_17 is null, the postgresql17 specialisation is disabled. + # This is useful for extensions that only support PostgreSQL 15. + # + # Override or extend configuration using lib.mkMerge: + # Example: + # lib.mkMerge [ + # (mkDefaultNixosTestNode { inherit config psql_15 psql_17; }) + # { services.postgresql.settings.shared_preload_libraries = lib.mkForce "my_ext"; } + # ] + mkDefaultNixosTestNode = + { + config, # The node's config attribute + psql_15, # PostgreSQL 15 package with extension + psql_17 ? null, # PostgreSQL 17 package with extension (optional) + ... + }: + { + virtualisation = { + forwardPorts = [ + { + from = "host"; + host.port = 13022; + guest.port = 22; + } + ]; + }; + services.openssh = { + enable = true; + }; + + services.postgresql = { + enable = true; + package = psql_15; + enableTCPIP = true; + authentication = '' + local all postgres peer map=postgres + local all all peer map=root + ''; + identMap = '' + root root supabase_admin + postgres postgres postgres + ''; + ensureUsers = [ + { + name = "supabase_admin"; + ensureClauses.superuser = true; + } + ]; + settings = (installedExtension "15").defaultSettings or { }; + }; + + networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ]; + + specialisation.postgresql17.configuration = pkgs.lib.mkIf (psql_17 != null) { + services.postgresql = { + package = pkgs.lib.mkForce psql_17; + settings = (installedExtension "17").defaultSettings or { }; + }; + + systemd.services.postgresql-migrate = { + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + User = "postgres"; + Group = "postgres"; + StateDirectory = "postgresql"; + WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; + }; + script = + let + oldPostgresql = psql_15; + newPostgresql = psql_17; + oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; + newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; + in + '' + if [[ ! -d ${newDataDir} ]]; then + install -d -m 0700 -o postgres -g postgres "${newDataDir}" + ${newPostgresql}/bin/initdb -D "${newDataDir}" + ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ + --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" \ + ${ + if config.services.postgresql.settings.shared_preload_libraries != null then + " --old-options='-c shared_preload_libraries=${config.services.postgresql.settings.shared_preload_libraries}' --new-options='-c shared_preload_libraries=${config.services.postgresql.settings.shared_preload_libraries}'" + else + "" + } + else + echo "${newDataDir} already exists" + fi + ''; + }; + + systemd.services.postgresql = { + after = [ "postgresql-migrate.service" ]; + requires = [ "postgresql-migrate.service" ]; + }; + }; + }; +} diff --git a/nix/ext/tests/pg_repack.nix b/nix/ext/tests/pg_repack.nix index 7a1605838..8de108012 100644 --- a/nix/ext/tests/pg_repack.nix +++ b/nix/ext/tests/pg_repack.nix @@ -41,93 +41,17 @@ let }; in pkg; + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = pname; + }; + psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; + psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; - nodes.server = - { config, ... }: - { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - services.openssh = { - enable = true; - }; - - services.postgresql = { - enable = true; - package = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - enableTCPIP = true; - authentication = '' - local all postgres peer map=postgres - local all all peer map=root - ''; - identMap = '' - root root supabase_admin - postgres postgres postgres - ''; - ensureUsers = [ - { - name = "supabase_admin"; - ensureClauses.superuser = true; - } - ]; - }; - - networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ]; - - specialisation.postgresql17.configuration = { - services.postgresql = { - package = lib.mkForce ( - postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17 - ); - }; - - systemd.services.postgresql-migrate = { - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - User = "postgres"; - Group = "postgres"; - StateDirectory = "postgresql"; - WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; - }; - script = - let - oldPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - newPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; - oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; - newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; - in - '' - if [[ ! -d ${newDataDir} ]]; then - install -d -m 0700 -o postgres -g postgres "${newDataDir}" - ${newPostgresql}/bin/initdb -D "${newDataDir}" - ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ - --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" - else - echo "${newDataDir} already exists" - fi - ''; - }; - - systemd.services.postgresql = { - after = [ "postgresql-migrate.service" ]; - requires = [ "postgresql-migrate.service" ]; - }; - }; - }; + nodes.server = { config, ... }: testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }; testScript = { nodes, ... }: let diff --git a/nix/ext/tests/pgmq.nix b/nix/ext/tests/pgmq.nix index 3e2dc7f91..98e210325 100644 --- a/nix/ext/tests/pgmq.nix +++ b/nix/ext/tests/pgmq.nix @@ -41,74 +41,17 @@ let }; in pkg; + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = pname; + }; psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; in self.inputs.nixpkgs.lib.nixos.runTest { - name = "timescaledb"; + name = pname; hostPkgs = pkgs; - nodes.server = - { config, ... }: - { - services.postgresql = { - enable = true; - package = (postgresqlWithExtension psql_15); - authentication = '' - local all postgres peer map=postgres - local all all peer map=root - ''; - identMap = '' - root root supabase_admin - postgres postgres postgres - ''; - ensureUsers = [ - { - name = "supabase_admin"; - ensureClauses.superuser = true; - } - ]; - settings = (installedExtension "15").defaultSettings or { }; - }; - - specialisation.postgresql17.configuration = { - services.postgresql = { - package = lib.mkForce psql_17; - }; - - systemd.services.postgresql-migrate = { - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - User = "postgres"; - Group = "postgres"; - StateDirectory = "postgresql"; - WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; - }; - script = - let - oldPostgresql = psql_15; - newPostgresql = psql_17; - oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; - newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; - in - '' - if [[ ! -d ${newDataDir} ]]; then - install -d -m 0700 -o postgres -g postgres "${newDataDir}" - ${newPostgresql}/bin/initdb -D "${newDataDir}" - ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ - --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" - else - echo "${newDataDir} already exists" - fi - ''; - }; - - systemd.services.postgresql = { - after = [ "postgresql-migrate.service" ]; - requires = [ "postgresql-migrate.service" ]; - }; - }; - }; + nodes.server = { config, ... }: testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }; testScript = { nodes, ... }: let diff --git a/nix/ext/tests/pgroonga.nix b/nix/ext/tests/pgroonga.nix index 4316d4a72..ded25b311 100644 --- a/nix/ext/tests/pgroonga.nix +++ b/nix/ext/tests/pgroonga.nix @@ -43,92 +43,30 @@ let pkg; psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = pname; + }; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; nodes.server = { config, ... }: - { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - services.openssh = { - enable = true; - }; - - services.postgresql = { - enable = true; - package = psql_15; - enableTCPIP = true; - authentication = '' - local all postgres peer map=postgres - local all all peer map=root - ''; - identMap = '' - root root supabase_admin - postgres postgres postgres - ''; - ensureUsers = [ - { - name = "supabase_admin"; - ensureClauses.superuser = true; - } - ]; - }; - systemd.services.postgresql.environment.MECAB_DICDIR = "${ - self.packages.${pkgs.stdenv.hostPlatform.system}.mecab-naist-jdic - }/lib/mecab/dic/naist-jdic"; - systemd.services.postgresql.environment.MECAB_CONFIG = "${pkgs.mecab}/bin/mecab-config"; - systemd.services.postgresql.environment.GRN_PLUGINS_DIR = "${ - self.packages.${pkgs.stdenv.hostPlatform.system}.supabase-groonga - }/lib/groonga/plugins"; - - specialisation.postgresql17.configuration = { - services.postgresql = { - package = lib.mkForce psql_17; - }; - - systemd.services.postgresql-migrate = { - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - User = "postgres"; - Group = "postgres"; - StateDirectory = "postgresql"; - WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; - }; - script = - let - oldPostgresql = psql_15; - newPostgresql = psql_17; - oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; - newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; - in - '' - if [[ ! -d ${newDataDir} ]]; then - install -d -m 0700 -o postgres -g postgres "${newDataDir}" - ${newPostgresql}/bin/initdb -D "${newDataDir}" - ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ - --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" - else - echo "${newDataDir} already exists" - fi - ''; + lib.mkMerge [ + (testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }) + { + systemd.services.postgresql.environment = { + MECAB_DICDIR = "${ + self.packages.${pkgs.stdenv.hostPlatform.system}.mecab-naist-jdic + }/lib/mecab/dic/naist-jdic"; + MECAB_CONFIG = "${pkgs.mecab}/bin/mecab-config"; + GRN_PLUGINS_DIR = "${ + self.packages.${pkgs.stdenv.hostPlatform.system}.supabase-groonga + }/lib/groonga/plugins"; }; - - systemd.services.postgresql = { - after = [ "postgresql-migrate.service" ]; - requires = [ "postgresql-migrate.service" ]; - }; - }; - }; + } + ]; testScript = { nodes, ... }: let diff --git a/nix/ext/tests/pgrouting.nix b/nix/ext/tests/pgrouting.nix index 15fac76c5..d43c21813 100644 --- a/nix/ext/tests/pgrouting.nix +++ b/nix/ext/tests/pgrouting.nix @@ -48,128 +48,71 @@ let pg_regress = pkgs.callPackage ../pg_regress.nix { postgresql = self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; }; + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = pname; + }; + psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; + psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; nodes.server = { config, ... }: - { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - services.openssh = { - enable = true; - }; - users.users.root.openssh.authorizedKeys.keys = [ - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIo+ulCUfJjnCVgfM4946Ih5Nm8DeZZiayYeABHGPEl7 jfroche" - ]; - - services.postgresql = { - enable = true; - package = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - }; - - specialisation.postgresql17.configuration = { - services.postgresql = { - package = lib.mkForce ( - postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17 - ); - }; - - systemd.services.postgresql-migrate = { - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - User = "postgres"; - Group = "postgres"; - StateDirectory = "postgresql"; - WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; - }; - script = - let - oldPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - newPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; - oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; - newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; - in - '' - if [[ ! -d ${newDataDir} ]]; then - install -d -m 0700 -o postgres -g postgres "${newDataDir}" - ${newPostgresql}/bin/initdb -D "${newDataDir}" - ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ - --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" - else - echo "${newDataDir} already exists" - fi + lib.mkMerge [ + (testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }) + { + specialisation.orioledb17.configuration = { + services.postgresql = { + package = lib.mkForce ( + postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17 + ); + settings = { + shared_preload_libraries = "orioledb"; + default_table_access_method = "orioledb"; + }; + initdbArgs = [ + "--allow-group-access" + "--locale-provider=icu" + "--encoding=UTF-8" + "--icu-locale=en_US.UTF-8" + ]; + initialScript = pkgs.writeText "init-postgres-with-orioledb" '' + CREATE EXTENSION orioledb CASCADE; ''; - }; - - systemd.services.postgresql = { - after = [ "postgresql-migrate.service" ]; - requires = [ "postgresql-migrate.service" ]; - }; - }; - - specialisation.orioledb17.configuration = { - services.postgresql = { - package = lib.mkForce ( - postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17 - ); - settings = { - shared_preload_libraries = "orioledb"; - default_table_access_method = "orioledb"; }; - initdbArgs = [ - "--allow-group-access" - "--locale-provider=icu" - "--encoding=UTF-8" - "--icu-locale=en_US.UTF-8" - ]; - initialScript = pkgs.writeText "init-postgres-with-orioledb" '' - CREATE EXTENSION orioledb CASCADE; - ''; - }; - systemd.services.postgresql-migrate = { - # we don't support migrating from postgresql 17 to orioledb-17 so we just reinit the datadir - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - User = "postgres"; - Group = "postgres"; - StateDirectory = "postgresql"; - WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; + systemd.services.postgresql-migrate = { + # we don't support migrating from postgresql 17 to orioledb-17 so we just reinit the datadir + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + User = "postgres"; + Group = "postgres"; + StateDirectory = "postgresql"; + WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; + }; + script = + let + newPostgresql = + postgresqlWithExtension + self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17; + in + '' + set -x + systemctl cat postgresql.service + rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema} + ''; }; - script = - let - newPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17; - in - '' - set -x - systemctl cat postgresql.service - rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema} - ''; - }; - systemd.services.postgresql = { - after = [ "postgresql-migrate.service" ]; - requires = [ "postgresql-migrate.service" ]; + systemd.services.postgresql = { + after = [ "postgresql-migrate.service" ]; + requires = [ "postgresql-migrate.service" ]; + }; }; - }; - }; + } + ]; testScript = { nodes, ... }: let diff --git a/nix/ext/tests/pgsodium.nix b/nix/ext/tests/pgsodium.nix index 00a2bf44f..82eaefd2c 100644 --- a/nix/ext/tests/pgsodium.nix +++ b/nix/ext/tests/pgsodium.nix @@ -47,79 +47,52 @@ let echo 0000000000000000000000000000000000000000000000000000000000000000 '' ); + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = pname; + }; + psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; + psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; nodes.server = { config, ... }: - { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - - services.postgresql = { - enable = true; - package = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - settings = { - "shared_preload_libraries" = pname; + lib.mkMerge [ + (testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }) + { + services.postgresql.settings = { + "shared_preload_libraries" = lib.mkForce pname; "pgsodium.getkey_script" = pgsodiumGetKey; }; - }; - - specialisation.postgresql17.configuration = { - services.postgresql = { - package = lib.mkForce ( - postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17 - ); - }; - systemd.services.postgresql-migrate = { - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - User = "postgres"; - Group = "postgres"; - StateDirectory = "postgresql"; - WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; + specialisation.postgresql17.configuration = { + systemd.services.postgresql-migrate = { + script = lib.mkForce ( + let + oldPostgresql = psql_15; + newPostgresql = psql_17; + oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; + newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; + in + '' + if [[ ! -d ${newDataDir} ]]; then + install -d -m 0700 -o postgres -g postgres "${newDataDir}" + ${newPostgresql}/bin/initdb -D "${newDataDir}" + echo "shared_preload_libraries = '${pname}'" >> "${newDataDir}/postgresql.conf" + echo "pgsodium.getkey_script = '${pgsodiumGetKey}'" >> "${newDataDir}/postgresql.conf"; + ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ + --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" + else + echo "${newDataDir} already exists" + fi + '' + ); }; - script = - let - oldPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - newPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; - oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; - newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; - in - '' - if [[ ! -d ${newDataDir} ]]; then - install -d -m 0700 -o postgres -g postgres "${newDataDir}" - ${newPostgresql}/bin/initdb -D "${newDataDir}" - echo "shared_preload_libraries = '${pname}'" >> "${newDataDir}/postgresql.conf" - echo "pgsodium.getkey_script = '${pgsodiumGetKey}'" >> "${newDataDir}/postgresql.conf"; - ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ - --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" - else - echo "${newDataDir} already exists" - fi - ''; - }; - - systemd.services.postgresql = { - after = [ "postgresql-migrate.service" ]; - requires = [ "postgresql-migrate.service" ]; }; - }; - }; + } + ]; testScript = { nodes, ... }: let diff --git a/nix/ext/tests/plpgsql_check.nix b/nix/ext/tests/plpgsql_check.nix index 3beac0c72..242967382 100644 --- a/nix/ext/tests/plpgsql_check.nix +++ b/nix/ext/tests/plpgsql_check.nix @@ -43,88 +43,15 @@ let pkg; psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = pname; + }; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; - nodes.server = - { config, ... }: - { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - services.openssh = { - enable = true; - }; - - services.postgresql = { - enable = true; - package = psql_15; - enableTCPIP = true; - authentication = '' - local all postgres peer map=postgres - local all all peer map=root - ''; - identMap = '' - root root supabase_admin - postgres postgres postgres - ''; - ensureUsers = [ - { - name = "supabase_admin"; - ensureClauses.superuser = true; - } - ]; - settings = (installedExtension "15").defaultSettings or { }; - }; - - networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ]; - - specialisation.postgresql17.configuration = { - services.postgresql = { - package = lib.mkForce psql_17; - }; - - systemd.services.postgresql-migrate = { - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - User = "postgres"; - Group = "postgres"; - StateDirectory = "postgresql"; - WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; - }; - script = - let - oldPostgresql = psql_15; - newPostgresql = psql_17; - oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; - newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; - in - '' - if [[ ! -d ${newDataDir} ]]; then - install -d -m 0700 -o postgres -g postgres "${newDataDir}" - ${newPostgresql}/bin/initdb -D "${newDataDir}" - ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ - --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" - else - echo "${newDataDir} already exists" - fi - ''; - }; - - systemd.services.postgresql = { - after = [ "postgresql-migrate.service" ]; - requires = [ "postgresql-migrate.service" ]; - }; - }; - }; + nodes.server = { config, ... }: testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }; testScript = { nodes, ... }: let diff --git a/nix/ext/tests/plv8.nix b/nix/ext/tests/plv8.nix index 91d7d29d1..eaf074c7f 100644 --- a/nix/ext/tests/plv8.nix +++ b/nix/ext/tests/plv8.nix @@ -43,44 +43,18 @@ let in pkg; psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = pname; + }; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; nodes.server = - { ... }: - { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - services.openssh = { - enable = true; - }; - - services.postgresql = { - enable = true; - package = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - authentication = '' - local all postgres peer map=postgres - local all all peer map=root - ''; - identMap = '' - root root supabase_admin - postgres postgres postgres - ''; - ensureUsers = [ - { - name = "supabase_admin"; - ensureClauses.superuser = true; - } - ]; - }; + { config, ... }: + testLib.mkDefaultNixosTestNode { + inherit config psql_15; }; testScript = { ... }: diff --git a/nix/ext/tests/postgis.nix b/nix/ext/tests/postgis.nix index 7599ab7c9..7b9604904 100644 --- a/nix/ext/tests/postgis.nix +++ b/nix/ext/tests/postgis.nix @@ -41,76 +41,17 @@ let }; in pkg; + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = pname; + }; + psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; + psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; - nodes.server = - { config, ... }: - { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - services.openssh = { - enable = true; - }; - - services.postgresql = { - enable = true; - package = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - }; - - specialisation.postgresql17.configuration = { - services.postgresql = { - package = lib.mkForce ( - postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17 - ); - }; - - systemd.services.postgresql-migrate = { - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - User = "postgres"; - Group = "postgres"; - StateDirectory = "postgresql"; - WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; - }; - script = - let - oldPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - newPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; - oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; - newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; - in - '' - if [[ ! -d ${newDataDir} ]]; then - install -d -m 0700 -o postgres -g postgres "${newDataDir}" - ${newPostgresql}/bin/initdb -D "${newDataDir}" - ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ - --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" - else - echo "${newDataDir} already exists" - fi - ''; - }; - - systemd.services.postgresql = { - after = [ "postgresql-migrate.service" ]; - requires = [ "postgresql-migrate.service" ]; - }; - }; - }; + nodes.server = { config, ... }: testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }; testScript = { nodes, ... }: let diff --git a/nix/ext/tests/timescaledb.nix b/nix/ext/tests/timescaledb.nix index a98d1f5eb..e4ef66cb3 100644 --- a/nix/ext/tests/timescaledb.nix +++ b/nix/ext/tests/timescaledb.nix @@ -42,37 +42,31 @@ let in pkg; psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = pname; + }; in self.inputs.nixpkgs.lib.nixos.runTest { name = "timescaledb"; hostPkgs = pkgs; nodes.server = - { ... }: - { - services.postgresql = { - enable = true; - package = (postgresqlWithExtension psql_15); - authentication = '' - local all postgres peer map=postgres - local all all peer map=root - ''; - identMap = '' - root root supabase_admin - postgres postgres postgres - ''; - ensureUsers = [ - { - name = "supabase_admin"; - ensureClauses.superuser = true; - } - { name = "service_role"; } - ]; - - settings = { - shared_preload_libraries = "timescaledb"; + { config, ... }: + lib.mkMerge [ + (testLib.mkDefaultNixosTestNode { + inherit config psql_15; + }) + { + services.postgresql = { + ensureUsers = [ + { name = "service_role"; } + ]; + settings = { + shared_preload_libraries = lib.mkForce "timescaledb"; + }; }; - }; - }; + } + ]; testScript = { ... }: '' diff --git a/nix/ext/tests/vault.nix b/nix/ext/tests/vault.nix index 42fafacab..7df432121 100644 --- a/nix/ext/tests/vault.nix +++ b/nix/ext/tests/vault.nix @@ -49,94 +49,59 @@ let ); psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; + testLib = import ./lib.nix { + inherit self pkgs; + testedExtensionName = pname; + }; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; nodes.server = { config, ... }: - { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - - services.postgresql = { - enable = true; - package = psql_15; - authentication = '' - local all postgres peer map=postgres - local all all peer map=root - ''; - identMap = '' - root root supabase_admin - postgres postgres postgres - ''; - initialScript = pkgs.writeText "vault-init.sql" '' - CREATE SCHEMA vault; - ''; - ensureUsers = [ - { - name = "supabase_admin"; - ensureClauses.superuser = true; - } - { name = "service_role"; } - ]; - settings = { - "shared_preload_libraries" = "${pname},pgsodium"; - "pgsodium.getkey_script" = vaultGetKey; - "search_path" = "\"$user\", public, auth, extensions"; - "vault.getkey_script" = vaultGetKey; - }; - }; - - specialisation.postgresql17.configuration = { + lib.mkMerge [ + (testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }) + { services.postgresql = { - package = lib.mkForce psql_17; - }; - - systemd.services.postgresql-migrate = { - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - User = "postgres"; - Group = "postgres"; - StateDirectory = "postgresql"; - WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; + initialScript = pkgs.writeText "vault-init.sql" '' + CREATE SCHEMA vault; + ''; + ensureUsers = [ { name = "service_role"; } ]; + settings = { + "shared_preload_libraries" = lib.mkForce "${pname},pgsodium"; + "pgsodium.getkey_script" = vaultGetKey; + "vault.getkey_script" = vaultGetKey; + "search_path" = "\"$user\", public, auth, extensions"; }; - script = - let - oldPostgresql = psql_15; - newPostgresql = psql_17; - oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; - newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; - in - '' - if [[ ! -d ${newDataDir} ]]; then - install -d -m 0700 -o postgres -g postgres "${newDataDir}" - ${newPostgresql}/bin/initdb -D "${newDataDir}" - echo "shared_preload_libraries = '${pname},pgsodium'" >> "${newDataDir}/postgresql.conf" - echo "vault.getkey_script = '${vaultGetKey}'" >> "${newDataDir}/postgresql.conf"; - echo "pgsodium.getkey_script = '${vaultGetKey}'" >> "${newDataDir}/postgresql.conf"; - ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ - --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" - else - echo "${newDataDir} already exists" - fi - ''; }; - systemd.services.postgresql = { - after = [ "postgresql-migrate.service" ]; - requires = [ "postgresql-migrate.service" ]; + specialisation.postgresql17.configuration = { + systemd.services.postgresql-migrate = { + script = lib.mkForce ( + let + oldPostgresql = psql_15; + newPostgresql = psql_17; + oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; + newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; + in + '' + if [[ ! -d ${newDataDir} ]]; then + install -d -m 0700 -o postgres -g postgres "${newDataDir}" + ${newPostgresql}/bin/initdb -D "${newDataDir}" + echo "shared_preload_libraries = '${pname},pgsodium'" >> "${newDataDir}/postgresql.conf" + echo "vault.getkey_script = '${vaultGetKey}'" >> "${newDataDir}/postgresql.conf"; + echo "pgsodium.getkey_script = '${vaultGetKey}'" >> "${newDataDir}/postgresql.conf"; + ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ + --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" + else + echo "${newDataDir} already exists" + fi + '' + ); + }; }; - }; - }; + } + ]; testScript = { nodes, ... }: let From b520cc5dd8720063e3f0db757e8dcd27667f8049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Roche?= Date: Tue, 11 Nov 2025 11:01:24 +0100 Subject: [PATCH 2/2] refactor: move more generic functions to test lib Move `postgresqlWithExtension` and `versions` to the test lib to reduce code duplication across extension tests. --- nix/ext/tests/default.nix | 52 +++++----------------- nix/ext/tests/http.nix | 49 ++------------------ nix/ext/tests/lib.nix | 76 +++++++++++++++++++++++++------ nix/ext/tests/orioledb.nix | 13 ------ nix/ext/tests/pg_repack.nix | 47 ++------------------ nix/ext/tests/pgjwt.nix | 10 ----- nix/ext/tests/pgmq.nix | 52 ++++------------------ nix/ext/tests/pgroonga.nix | 54 ++++------------------ nix/ext/tests/pgrouting.nix | 75 ++++++++----------------------- nix/ext/tests/pgsodium.nix | 79 ++++++++++----------------------- nix/ext/tests/plpgsql_check.nix | 52 ++++------------------ nix/ext/tests/plv8.nix | 50 ++------------------- nix/ext/tests/postgis.nix | 47 ++------------------ nix/ext/tests/timescaledb.nix | 57 +++--------------------- nix/ext/tests/vault.nix | 76 +++++++++---------------------- 15 files changed, 183 insertions(+), 606 deletions(-) diff --git a/nix/ext/tests/default.nix b/nix/ext/tests/default.nix index be278e577..03bf60c84 100644 --- a/nix/ext/tests/default.nix +++ b/nix/ext/tests/default.nix @@ -9,47 +9,17 @@ let extension_name: let pname = extension_name; - inherit (pkgs) lib; - versions = postgresqlMajorVersion: (testLib.installedExtension postgresqlMajorVersion).versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (testLib.installedExtension majorVersion) - ]; - passthru = { - inherit (postgresql) version psqlSchema; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - installedExtensions = [ (testLib.installedExtension majorVersion) ]; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; testLib = import ./lib.nix { inherit self pkgs; testedExtensionName = extension_name; }; - psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; + inherit (pkgs) lib; + inherit (testLib) + versions + psql_15 + psql_17 + installedExtension + ; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; @@ -70,13 +40,13 @@ let support_upgrade = True pg17_configuration = "${pg17-configuration}" ext_has_background_worker = ${ - if (testLib.installedExtension "15") ? hasBackgroundWorker then "True" else "False" + if (installedExtension "15") ? hasBackgroundWorker then "True" else "False" } sql_test_directory = Path("${../../tests}") - pg_regress_test_name = "${(testLib.installedExtension "15").pgRegressTestName or pname}" - ext_schema = "${(testLib.installedExtension "15").defaultSchema or "public"}" - lib_name = "${(testLib.installedExtension "15").libName or pname}" + pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}" + ext_schema = "${(installedExtension "15").defaultSchema or "public"}" + lib_name = "${(installedExtension "15").libName or pname}" print(f"Running tests for extension: {lib_name}") ${builtins.readFile ./lib.py} diff --git a/nix/ext/tests/http.nix b/nix/ext/tests/http.nix index e7818ff39..b0ddd706f 100644 --- a/nix/ext/tests/http.nix +++ b/nix/ext/tests/http.nix @@ -1,52 +1,11 @@ { self, pkgs }: let pname = "http"; - inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (installedExtension majorVersion) - ]; - passthru = { - inherit (postgresql) version psqlSchema; - installedExtensions = [ (installedExtension majorVersion) ]; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; testLib = import ./lib.nix { inherit self pkgs; testedExtensionName = pname; }; - psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; + inherit (testLib) versions psql_15 psql_17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; @@ -57,12 +16,12 @@ self.inputs.nixpkgs.lib.nixos.runTest { let pg17-configuration = "${nodes.server.system.build.toplevel}/specialisation/postgresql17"; # Convert versions to major.minor format (e.g., "1.5.0" -> "1.5") - toMajorMinor = map (v: lib.versions.majorMinor v); + toMajorMinor = map (v: pkgs.lib.versions.majorMinor v); in '' versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (toMajorMinor (versions "15")))}], - "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (toMajorMinor (versions "17")))}], + "15": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (toMajorMinor (versions "15")))}], + "17": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (toMajorMinor (versions "17")))}], } def run_sql(query): diff --git a/nix/ext/tests/lib.nix b/nix/ext/tests/lib.nix index f32fa4e38..1b6cf45b0 100644 --- a/nix/ext/tests/lib.nix +++ b/nix/ext/tests/lib.nix @@ -10,6 +10,10 @@ # # - `installedExtension`: Function to get the installed extension package for a PostgreSQL version # - `mkDefaultNixosTestNode`: Creates a NixOS test node with standard PostgreSQL setup +# - `psql_15`: PostgreSQL 15 package with the tested extension +# - `psql_17`: PostgreSQL 17 package with the tested extension +# - `versions`: Function to get available extension versions for a PostgreSQL version +# - `mkPostgresqlWithExtensions`: Builds a PostgreSQL package with a list of extensions # # ## Examples # @@ -55,19 +59,6 @@ rec { ... }: { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - services.openssh = { - enable = true; - }; - services.postgresql = { enable = true; package = psql_15; @@ -137,4 +128,63 @@ rec { }; }; }; + + # Build a PostgreSQL package that includes a list of extensions. + # + # The included extension can be accessed via the `testedExtension` attribute. + # + mkPostgresqlWithExtensions = + postgresql: # The PostgreSQL package to extend with the extension + extensions: # A list of extension packages to include, the first will be the testedExtension + let + majorVersion = pkgs.lib.versions.major postgresql.version; + # Build paths for all extensions + extensionPaths = map ( + ext: self.legacyPackages.${pkgs.system}."psql_${majorVersion}".exts."${ext}" + ) extensions; + # Automatically add orioledb if building for OrioleDB + orioledbPaths = + pkgs.lib.optional postgresql.isOrioleDB + self.legacyPackages.${pkgs.system}."psql_orioledb-17".exts.orioledb; + pkg = pkgs.buildEnv { + name = "postgresql-${majorVersion}-${testedExtensionName}"; + paths = [ + postgresql + postgresql.lib + ] + ++ extensionPaths + ++ orioledbPaths; + passthru = { + inherit (postgresql) version psqlSchema; + lib = pkg; + testedExtension = builtins.head extensionPaths; + withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; + installedExtensions = [ (installedExtension majorVersion) ]; + }; + nativeBuildInputs = [ pkgs.makeWrapper ]; + pathsToLink = [ + "/" + "/bin" + "/lib" + ]; + postBuild = '' + wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib + wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib + wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib + ''; + }; + in + pkg; + psql_15 = mkPostgresqlWithExtensions self.packages.${pkgs.system}.postgresql_15 [ + testedExtensionName + ]; + psql_17 = mkPostgresqlWithExtensions self.packages.${pkgs.system}.postgresql_17 [ + testedExtensionName + ]; + # Get available extension versions for a specific PostgreSQL major version. + versions = + postgresqlMajorVersion: # The PostgreSQL major version (e.g., "15", "17") + (installedExtension postgresqlMajorVersion).versions; } diff --git a/nix/ext/tests/orioledb.nix b/nix/ext/tests/orioledb.nix index de50710b5..c40c67014 100644 --- a/nix/ext/tests/orioledb.nix +++ b/nix/ext/tests/orioledb.nix @@ -47,19 +47,6 @@ self.inputs.nixpkgs.lib.nixos.runTest { nodes.server = { ... }: { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - services.openssh = { - enable = true; - }; - services.postgresql = { enable = true; package = psql_orioledb; diff --git a/nix/ext/tests/pg_repack.nix b/nix/ext/tests/pg_repack.nix index 8de108012..7491b8db8 100644 --- a/nix/ext/tests/pg_repack.nix +++ b/nix/ext/tests/pg_repack.nix @@ -1,52 +1,11 @@ { self, pkgs }: let pname = "pg_repack"; - inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (installedExtension majorVersion) - ]; - passthru = { - inherit (postgresql) version psqlSchema; - installedExtensions = [ (installedExtension majorVersion) ]; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; testLib = import ./lib.nix { inherit self pkgs; testedExtensionName = pname; }; - psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; + inherit (testLib) versions psql_15 psql_17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; @@ -60,8 +19,8 @@ self.inputs.nixpkgs.lib.nixos.runTest { '' from pathlib import Path versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], - "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], + "15": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], + "17": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], } extension_name = "${pname}" support_upgrade = False diff --git a/nix/ext/tests/pgjwt.nix b/nix/ext/tests/pgjwt.nix index 2f0cc9efc..da750b288 100644 --- a/nix/ext/tests/pgjwt.nix +++ b/nix/ext/tests/pgjwt.nix @@ -50,16 +50,6 @@ self.inputs.nixpkgs.lib.nixos.runTest { nodes.server = { config, ... }: { - virtualisation = { - forwardPorts = [ - { - from = "host"; - host.port = 13022; - guest.port = 22; - } - ]; - }; - services.postgresql = { enable = true; package = psql_15; diff --git a/nix/ext/tests/pgmq.nix b/nix/ext/tests/pgmq.nix index 98e210325..2e1c1ad4b 100644 --- a/nix/ext/tests/pgmq.nix +++ b/nix/ext/tests/pgmq.nix @@ -1,52 +1,16 @@ { self, pkgs }: let pname = "pgmq"; - inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (installedExtension majorVersion) - ]; - passthru = { - inherit (postgresql) version psqlSchema; - installedExtensions = [ (installedExtension majorVersion) ]; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; testLib = import ./lib.nix { inherit self pkgs; testedExtensionName = pname; }; - psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; + inherit (testLib) + versions + installedExtension + psql_15 + psql_17 + ; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; @@ -60,8 +24,8 @@ self.inputs.nixpkgs.lib.nixos.runTest { '' from pathlib import Path versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], - "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], + "15": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], + "17": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], } extension_name = "${pname}" support_upgrade = True diff --git a/nix/ext/tests/pgroonga.nix b/nix/ext/tests/pgroonga.nix index ded25b311..fc816bed4 100644 --- a/nix/ext/tests/pgroonga.nix +++ b/nix/ext/tests/pgroonga.nix @@ -1,59 +1,23 @@ { self, pkgs }: let pname = "pgroonga"; - inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (installedExtension majorVersion) - ]; - passthru = { - inherit (postgresql) version psqlSchema; - installedExtensions = [ (installedExtension majorVersion) ]; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; - psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; testLib = import ./lib.nix { inherit self pkgs; testedExtensionName = pname; }; + inherit (testLib) + versions + installedExtension + psql_15 + psql_17 + ; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; nodes.server = { config, ... }: - lib.mkMerge [ + pkgs.lib.mkMerge [ (testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }) { systemd.services.postgresql.environment = { @@ -75,8 +39,8 @@ self.inputs.nixpkgs.lib.nixos.runTest { '' from pathlib import Path versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], - "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], + "15": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], + "17": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], } extension_name = "${pname}" pg17_configuration = "${pg17-configuration}" diff --git a/nix/ext/tests/pgrouting.nix b/nix/ext/tests/pgrouting.nix index d43c21813..09c050982 100644 --- a/nix/ext/tests/pgrouting.nix +++ b/nix/ext/tests/pgrouting.nix @@ -1,50 +1,6 @@ { self, pkgs }: let pname = "pgrouting"; - inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (installedExtension majorVersion) - (self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${majorVersion}".exts.postgis) - ] - ++ lib.optional (postgresql.isOrioleDB) ( - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_orioledb-17".exts.orioledb - ); - passthru = { - inherit (postgresql) version psqlSchema; - installedExtensions = [ (installedExtension majorVersion) ]; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; pg_regress = pkgs.callPackage ../pg_regress.nix { postgresql = self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; }; @@ -52,22 +8,31 @@ let inherit self pkgs; testedExtensionName = pname; }; - psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; + inherit (testLib) mkPostgresqlWithExtensions versions; + psql_15 = mkPostgresqlWithExtensions self.packages.${pkgs.system}.postgresql_15 [ + pname + "postgis" + ]; + psql_17 = mkPostgresqlWithExtensions self.packages.${pkgs.system}.postgresql_17 [ + pname + "postgis" + ]; + psql_orioledb_17 = mkPostgresqlWithExtensions self.packages.${pkgs.system}.postgresql_orioledb-17 [ + pname + "postgis" + ]; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; nodes.server = { config, ... }: - lib.mkMerge [ + pkgs.lib.mkMerge [ (testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }) { specialisation.orioledb17.configuration = { services.postgresql = { - package = lib.mkForce ( - postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17 - ); + package = pkgs.lib.mkForce psql_orioledb_17; settings = { shared_preload_libraries = "orioledb"; default_table_access_method = "orioledb"; @@ -95,9 +60,7 @@ self.inputs.nixpkgs.lib.nixos.runTest { }; script = let - newPostgresql = - postgresqlWithExtension - self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17; + newPostgresql = psql_orioledb_17; in '' set -x @@ -121,9 +84,9 @@ self.inputs.nixpkgs.lib.nixos.runTest { in '' versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], - "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], - "orioledb-17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "orioledb-17"))}], + "15": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], + "17": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], + "orioledb-17": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "orioledb-17"))}], } def run_sql(query): diff --git a/nix/ext/tests/pgsodium.nix b/nix/ext/tests/pgsodium.nix index 82eaefd2c..9d1753e49 100644 --- a/nix/ext/tests/pgsodium.nix +++ b/nix/ext/tests/pgsodium.nix @@ -1,75 +1,44 @@ { self, pkgs }: let pname = "pgsodium"; - inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (installedExtension majorVersion) - (self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${majorVersion}".exts.hypopg) - ]; - passthru = { - inherit (postgresql) version psqlSchema; - installedExtensions = [ (installedExtension majorVersion) ]; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; - pgsodiumGetKey = lib.getExe ( - pkgs.writeShellScriptBin "pgsodium-getkey" '' - echo 0000000000000000000000000000000000000000000000000000000000000000 - '' - ); testLib = import ./lib.nix { inherit self pkgs; testedExtensionName = pname; }; - psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; + inherit (testLib) mkPostgresqlWithExtensions versions; + psql_15 = mkPostgresqlWithExtensions self.packages.${pkgs.system}.postgresql_15 [ + pname + "hypopg" + ]; + psql_17 = mkPostgresqlWithExtensions self.packages.${pkgs.system}.postgresql_17 [ + pname + "hypopg" + ]; + + pgsodiumGetKey = pkgs.lib.getExe ( + pkgs.writeShellScriptBin "pgsodium-getkey" '' + echo 0000000000000000000000000000000000000000000000000000000000000000 + '' + ); in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; nodes.server = { config, ... }: - lib.mkMerge [ + pkgs.lib.mkMerge [ (testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }) { - services.postgresql.settings = { - "shared_preload_libraries" = lib.mkForce pname; - "pgsodium.getkey_script" = pgsodiumGetKey; + services.postgresql = { + settings = { + "shared_preload_libraries" = pkgs.lib.mkForce pname; + "pgsodium.getkey_script" = pgsodiumGetKey; + }; }; specialisation.postgresql17.configuration = { systemd.services.postgresql-migrate = { - script = lib.mkForce ( + script = pkgs.lib.mkForce ( let oldPostgresql = psql_15; newPostgresql = psql_17; @@ -100,8 +69,8 @@ self.inputs.nixpkgs.lib.nixos.runTest { in '' versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], - "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], + "15": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], + "17": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], } def run_sql(query): diff --git a/nix/ext/tests/plpgsql_check.nix b/nix/ext/tests/plpgsql_check.nix index 242967382..9f4460fbd 100644 --- a/nix/ext/tests/plpgsql_check.nix +++ b/nix/ext/tests/plpgsql_check.nix @@ -1,52 +1,16 @@ { self, pkgs }: let pname = "plpgsql_check"; - inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (installedExtension majorVersion) - ]; - passthru = { - inherit (postgresql) version psqlSchema; - installedExtensions = [ (installedExtension majorVersion) ]; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; - psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; testLib = import ./lib.nix { inherit self pkgs; testedExtensionName = pname; }; + inherit (testLib) + versions + installedExtension + psql_15 + psql_17 + ; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; @@ -60,8 +24,8 @@ self.inputs.nixpkgs.lib.nixos.runTest { '' from pathlib import Path versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], - "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], + "15": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], + "17": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], } extension_name = "${pname}" support_upgrade = True diff --git a/nix/ext/tests/plv8.nix b/nix/ext/tests/plv8.nix index eaf074c7f..9471ae6f8 100644 --- a/nix/ext/tests/plv8.nix +++ b/nix/ext/tests/plv8.nix @@ -2,66 +2,22 @@ { self, pkgs }: let pname = "plv8"; - inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (installedExtension majorVersion) - ]; - passthru = { - inherit (postgresql) version psqlSchema; - installedExtensions = [ (installedExtension majorVersion) ]; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; - psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; testLib = import ./lib.nix { inherit self pkgs; testedExtensionName = pname; }; + inherit (testLib) versions installedExtension psql_15; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; - nodes.server = - { config, ... }: - testLib.mkDefaultNixosTestNode { - inherit config psql_15; - }; + nodes.server = { config, ... }: testLib.mkDefaultNixosTestNode { inherit config psql_15; }; testScript = { ... }: '' from pathlib import Path versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], + "15": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], } extension_name = "${pname}" support_upgrade = False diff --git a/nix/ext/tests/postgis.nix b/nix/ext/tests/postgis.nix index 7b9604904..ea47a3c37 100644 --- a/nix/ext/tests/postgis.nix +++ b/nix/ext/tests/postgis.nix @@ -1,52 +1,11 @@ { self, pkgs }: let pname = "postgis"; - inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (installedExtension majorVersion) - ]; - passthru = { - inherit (postgresql) version psqlSchema; - installedExtensions = [ (installedExtension majorVersion) ]; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; testLib = import ./lib.nix { inherit self pkgs; testedExtensionName = pname; }; - psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; + inherit (testLib) versions psql_15 psql_17; in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; @@ -59,8 +18,8 @@ self.inputs.nixpkgs.lib.nixos.runTest { in '' versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], - "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], + "15": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], + "17": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], } def run_sql(query): diff --git a/nix/ext/tests/timescaledb.nix b/nix/ext/tests/timescaledb.nix index e4ef66cb3..c5925e43a 100644 --- a/nix/ext/tests/timescaledb.nix +++ b/nix/ext/tests/timescaledb.nix @@ -1,68 +1,25 @@ { self, pkgs }: let pname = "timescaledb"; - inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = (installedExtension "15").versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (installedExtension majorVersion) - ]; - passthru = { - inherit (postgresql) version psqlSchema; - installedExtensions = [ (installedExtension majorVersion) ]; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; - psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; testLib = import ./lib.nix { inherit self pkgs; testedExtensionName = pname; }; + inherit (testLib) psql_15; + versions = (testLib.installedExtension "15").versions; in self.inputs.nixpkgs.lib.nixos.runTest { name = "timescaledb"; hostPkgs = pkgs; nodes.server = { config, ... }: - lib.mkMerge [ - (testLib.mkDefaultNixosTestNode { - inherit config psql_15; - }) + pkgs.lib.mkMerge [ + (testLib.mkDefaultNixosTestNode { inherit config psql_15; }) { services.postgresql = { - ensureUsers = [ - { name = "service_role"; } - ]; + ensureUsers = [ { name = "service_role"; } ]; settings = { - shared_preload_libraries = lib.mkForce "timescaledb"; + shared_preload_libraries = pkgs.lib.mkForce "timescaledb"; }; }; } @@ -78,7 +35,7 @@ self.inputs.nixpkgs.lib.nixos.runTest { server.wait_for_unit("postgresql.service") versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') versions)}], + "15": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') versions)}], } extension_name = "${pname}" support_upgrade = True diff --git a/nix/ext/tests/vault.nix b/nix/ext/tests/vault.nix index 7df432121..3245ac592 100644 --- a/nix/ext/tests/vault.nix +++ b/nix/ext/tests/vault.nix @@ -1,65 +1,31 @@ { self, pkgs }: let pname = "supabase_vault"; - inherit (pkgs) lib; - installedExtension = - postgresMajorVersion: - self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${postgresMajorVersion}".exts."${ - pname - }"; - versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; - postgresqlWithExtension = - postgresql: - let - majorVersion = lib.versions.major postgresql.version; - pkg = pkgs.buildEnv { - name = "postgresql-${majorVersion}-${pname}"; - paths = [ - postgresql - postgresql.lib - (installedExtension majorVersion) - (self.legacyPackages.${pkgs.stdenv.hostPlatform.system}."psql_${majorVersion}".exts.pgsodium) # dependency - ]; - passthru = { - inherit (postgresql) version psqlSchema; - installedExtensions = [ (installedExtension majorVersion) ]; - lib = pkg; - withPackages = _: pkg; - withJIT = pkg; - withoutJIT = pkg; - }; - nativeBuildInputs = [ pkgs.makeWrapper ]; - pathsToLink = [ - "/" - "/bin" - "/lib" - ]; - postBuild = '' - wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib - wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib - ''; - }; - in - pkg; - vaultGetKey = lib.getExe ( - pkgs.writeShellScriptBin "vault-getkey" '' - echo 0000000000000000000000000000000000000000000000000000000000000000 - '' - ); - psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15; - psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17; testLib = import ./lib.nix { inherit self pkgs; testedExtensionName = pname; }; + inherit (testLib) mkPostgresqlWithExtensions versions; + psql_15 = mkPostgresqlWithExtensions self.packages.${pkgs.system}.postgresql_15 [ + pname + "pgsodium" + ]; + psql_17 = mkPostgresqlWithExtensions self.packages.${pkgs.system}.postgresql_17 [ + pname + "pgsodium" + ]; + vaultGetKey = pkgs.lib.getExe ( + pkgs.writeShellScriptBin "vault-getkey" '' + echo 0000000000000000000000000000000000000000000000000000000000000000 + '' + ); in self.inputs.nixpkgs.lib.nixos.runTest { name = pname; hostPkgs = pkgs; nodes.server = { config, ... }: - lib.mkMerge [ + pkgs.lib.mkMerge [ (testLib.mkDefaultNixosTestNode { inherit config psql_15 psql_17; }) { services.postgresql = { @@ -68,7 +34,7 @@ self.inputs.nixpkgs.lib.nixos.runTest { ''; ensureUsers = [ { name = "service_role"; } ]; settings = { - "shared_preload_libraries" = lib.mkForce "${pname},pgsodium"; + "shared_preload_libraries" = pkgs.lib.mkForce "${pname},pgsodium"; "pgsodium.getkey_script" = vaultGetKey; "vault.getkey_script" = vaultGetKey; "search_path" = "\"$user\", public, auth, extensions"; @@ -77,7 +43,7 @@ self.inputs.nixpkgs.lib.nixos.runTest { specialisation.postgresql17.configuration = { systemd.services.postgresql-migrate = { - script = lib.mkForce ( + script = pkgs.lib.mkForce ( let oldPostgresql = psql_15; newPostgresql = psql_17; @@ -110,17 +76,17 @@ self.inputs.nixpkgs.lib.nixos.runTest { '' from pathlib import Path versions = { - "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], - "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], + "15": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], + "17": [${pkgs.lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], } extension_name = "${pname}" support_upgrade = True pg17_configuration = "${pg17-configuration}" ext_has_background_worker = ${ - if (installedExtension "15") ? hasBackgroundWorker then "True" else "False" + if (testLib.installedExtension "15") ? hasBackgroundWorker then "True" else "False" } sql_test_directory = Path("${../../tests}") - pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}" + pg_regress_test_name = "${(testLib.installedExtension "15").pgRegressTestName or pname}" ${builtins.readFile ./lib.py}