From eb96c8dc5b69f2838e3ff8e6ce6ba69956ada02c Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 26 Jan 2025 13:10:53 +0100 Subject: [PATCH] postgresql: refactor `postgresqlVersions` attribute & tests Every postgresql testcase essentially does the following things: * Filter `postgresqlVersions` for server packages * Filter postgresql server packages for suitable ones (i.e. extensions must support the given version) * Generate an attribute-set of testcases The first item became necessary in 7ab1e888334ddc2745b285e3df0b0efd5839d0f8 given that `postgresql/default.nix` now exposes JIT and non-JIT servers AND a `libpq` that is not suitable for the tests here. This changes restructures this a little bit, i.e.: * Having an attribute-set that contains a bunch of postgresql servers and a single client package seems odd (and the sole consumer of `postgresqlVersions` in nixpkgs, the test suite, has to take that into account). Hence, postgresql's default.nix now provides `libpq` (the client) and a `postgresqlVersions` attribute with all supported JIT and non-JIT variants of postgresql. * Each test-case gets a third argument, a function called `genTests`: this function sets `recurseForDerivations = true;` and generates an attribute-set of tests for each postgresql version given a function that returns a testcase or multiple test-cases (`makeTestFor`). The argument to `makeTestFor` is a postgresql server package. This function also accepts a filter predicate that is passed against `filterAttrs` to remove postgresql server packages that are not suitable for the test (e.g. because the version isn't supported by the extension to test). I checked by making sure that the `.drv` doesn't change on staging with this change on top for postgresq, postgresql-jit, postgresql-wal-receiver, postgresql-tls-client-cert, anonymizer, pgjwt, pgvecto-rs, timescaledb, tsja and wal2json. --- nixos/tests/postgresql/anonymizer.nix | 13 +++++------- nixos/tests/postgresql/default.nix | 20 ++++++++++++++++++- nixos/tests/postgresql/pgjwt.nix | 13 +++++------- nixos/tests/postgresql/pgvecto-rs.nix | 13 +++++------- nixos/tests/postgresql/postgresql-jit.nix | 13 +++++------- .../postgresql/postgresql-tls-client-cert.nix | 10 ++-------- .../postgresql/postgresql-wal-receiver.nix | 10 ++-------- nixos/tests/postgresql/postgresql.nix | 10 ++-------- nixos/tests/postgresql/timescaledb.nix | 13 +++++------- nixos/tests/postgresql/tsja.nix | 13 +++++------- nixos/tests/postgresql/wal2json.nix | 13 +++++------- pkgs/servers/sql/postgresql/default.nix | 8 ++++++-- pkgs/top-level/all-packages.nix | 7 ++++--- 13 files changed, 70 insertions(+), 86 deletions(-) diff --git a/nixos/tests/postgresql/anonymizer.nix b/nixos/tests/postgresql/anonymizer.nix index abbcd4890976..d59a26f101e8 100644 --- a/nixos/tests/postgresql/anonymizer.nix +++ b/nixos/tests/postgresql/anonymizer.nix @@ -1,6 +1,7 @@ { pkgs, makeTest, + genTests, }: let @@ -107,11 +108,7 @@ let ''; }; in -lib.recurseIntoAttrs ( - lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( - lib.filterAttrs (_: p: p ? pkgs && !p.pkgs.anonymizer.meta.broken) pkgs.postgresqlVersions - ) - // { - passthru.override = p: makeTestFor p; - } -) +genTests { + inherit makeTestFor; + filter = _: p: !p.pkgs.anonymizer.meta.broken; +} diff --git a/nixos/tests/postgresql/default.nix b/nixos/tests/postgresql/default.nix index 4fe7e7a37e7e..91f7694208b1 100644 --- a/nixos/tests/postgresql/default.nix +++ b/nixos/tests/postgresql/default.nix @@ -7,7 +7,25 @@ with import ../../lib/testing-python.nix { inherit system pkgs; }; let - importWithArgs = path: import path { inherit pkgs makeTest; }; + inherit (pkgs.lib) + recurseIntoAttrs + filterAttrs + mapAttrs + const + ; + genTests = + { + makeTestFor, + filter ? (_: _: true), + }: + recurseIntoAttrs ( + mapAttrs (const makeTestFor) (filterAttrs filter pkgs.postgresqlVersions) + // { + passthru.override = makeTestFor; + } + ); + + importWithArgs = path: import path { inherit pkgs makeTest genTests; }; in { # postgresql diff --git a/nixos/tests/postgresql/pgjwt.nix b/nixos/tests/postgresql/pgjwt.nix index 27033a1383b1..f00d9a939d3d 100644 --- a/nixos/tests/postgresql/pgjwt.nix +++ b/nixos/tests/postgresql/pgjwt.nix @@ -1,6 +1,7 @@ { pkgs, makeTest, + genTests, }: let @@ -48,11 +49,7 @@ let ''; }; in -lib.recurseIntoAttrs ( - lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( - lib.filterAttrs (_: p: p ? pkgs && !p.pkgs.pgjwt.meta.broken) pkgs.postgresqlVersions - ) - // { - passthru.override = p: makeTestFor p; - } -) +genTests { + inherit makeTestFor; + filter = _: p: !p.pkgs.pgjwt.meta.broken; +} diff --git a/nixos/tests/postgresql/pgvecto-rs.nix b/nixos/tests/postgresql/pgvecto-rs.nix index 98241ec48090..300449617e9b 100644 --- a/nixos/tests/postgresql/pgvecto-rs.nix +++ b/nixos/tests/postgresql/pgvecto-rs.nix @@ -1,6 +1,7 @@ { pkgs, makeTest, + genTests, }: let @@ -72,11 +73,7 @@ let ''; }; in -lib.recurseIntoAttrs ( - lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( - lib.filterAttrs (_: p: p ? pkgs && !p.pkgs.pgvecto-rs.meta.broken) pkgs.postgresqlVersions - ) - // { - passthru.override = p: makeTestFor p; - } -) +genTests { + inherit makeTestFor; + filter = _: p: !p.pkgs.pgvecto-rs.meta.broken; +} diff --git a/nixos/tests/postgresql/postgresql-jit.nix b/nixos/tests/postgresql/postgresql-jit.nix index 5d0406062eae..e082ff141327 100644 --- a/nixos/tests/postgresql/postgresql-jit.nix +++ b/nixos/tests/postgresql/postgresql-jit.nix @@ -1,6 +1,7 @@ { pkgs, makeTest, + genTests, }: let @@ -48,11 +49,7 @@ let ''; }; in -lib.recurseIntoAttrs ( - lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( - lib.filterAttrs (n: _: lib.hasSuffix "_jit" n) pkgs.postgresqlVersions - ) - // { - passthru.override = p: makeTestFor p; - } -) +genTests { + inherit makeTestFor; + filter = n: _: lib.hasSuffix "_jit" n; +} diff --git a/nixos/tests/postgresql/postgresql-tls-client-cert.nix b/nixos/tests/postgresql/postgresql-tls-client-cert.nix index 0861416d6c40..117b9b0e24a9 100644 --- a/nixos/tests/postgresql/postgresql-tls-client-cert.nix +++ b/nixos/tests/postgresql/postgresql-tls-client-cert.nix @@ -1,6 +1,7 @@ { pkgs, makeTest, + genTests, }: let @@ -128,11 +129,4 @@ let ''; }; in -lib.recurseIntoAttrs ( - lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( - lib.filterAttrs (_: p: p ? pkgs) pkgs.postgresqlVersions - ) - // { - passthru.override = p: makeTestFor p; - } -) +genTests { inherit makeTestFor; } diff --git a/nixos/tests/postgresql/postgresql-wal-receiver.nix b/nixos/tests/postgresql/postgresql-wal-receiver.nix index eee6c0c14de1..c99c3889c027 100644 --- a/nixos/tests/postgresql/postgresql-wal-receiver.nix +++ b/nixos/tests/postgresql/postgresql-wal-receiver.nix @@ -1,6 +1,7 @@ { pkgs, makeTest, + genTests, }: let @@ -108,11 +109,4 @@ let ''; }; in -lib.recurseIntoAttrs ( - lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( - lib.filterAttrs (_: p: p ? pkgs) pkgs.postgresqlVersions - ) - // { - passthru.override = p: makeTestFor p; - } -) +genTests { inherit makeTestFor; } diff --git a/nixos/tests/postgresql/postgresql.nix b/nixos/tests/postgresql/postgresql.nix index 0aa56330ce01..7741d14808eb 100644 --- a/nixos/tests/postgresql/postgresql.nix +++ b/nixos/tests/postgresql/postgresql.nix @@ -1,6 +1,7 @@ { pkgs, makeTest, + genTests, }: let @@ -262,11 +263,4 @@ let ''; }; in -lib.recurseIntoAttrs ( - lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( - lib.filterAttrs (_: p: p ? pkgs) pkgs.postgresqlVersions - ) - // { - passthru.override = p: makeTestFor p; - } -) +genTests { inherit makeTestFor; } diff --git a/nixos/tests/postgresql/timescaledb.nix b/nixos/tests/postgresql/timescaledb.nix index acfe5ed7ecc6..7ad8b0fcc972 100644 --- a/nixos/tests/postgresql/timescaledb.nix +++ b/nixos/tests/postgresql/timescaledb.nix @@ -1,6 +1,7 @@ { pkgs, makeTest, + genTests, }: let @@ -91,11 +92,7 @@ in # Not run by default, because this requires allowUnfree. # To run these tests: # NIXPKGS_ALLOW_UNFREE=1 nix-build -A nixosTests.postgresql.timescaledb -lib.dontRecurseIntoAttrs ( - lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( - lib.filterAttrs (_: p: p ? pkgs && !p.pkgs.timescaledb.meta.broken) pkgs.postgresqlVersions - ) - // { - passthru.override = p: makeTestFor p; - } -) +lib.dontRecurseIntoAttrs (genTests { + inherit makeTestFor; + filter = _: p: !p.pkgs.timescaledb.meta.broken; +}) diff --git a/nixos/tests/postgresql/tsja.nix b/nixos/tests/postgresql/tsja.nix index 34437068ae67..4cc5bd124139 100644 --- a/nixos/tests/postgresql/tsja.nix +++ b/nixos/tests/postgresql/tsja.nix @@ -1,6 +1,7 @@ { pkgs, makeTest, + genTests, }: let @@ -41,11 +42,7 @@ let ''; }; in -lib.recurseIntoAttrs ( - lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( - lib.filterAttrs (_: p: p ? pkgs && !p.pkgs.tsja.meta.broken) pkgs.postgresqlVersions - ) - // { - passthru.override = p: makeTestFor p; - } -) +genTests { + inherit makeTestFor; + filter = _: p: !p.pkgs.tsja.meta.broken; +} diff --git a/nixos/tests/postgresql/wal2json.nix b/nixos/tests/postgresql/wal2json.nix index 644ade741d83..abfe60673753 100644 --- a/nixos/tests/postgresql/wal2json.nix +++ b/nixos/tests/postgresql/wal2json.nix @@ -1,6 +1,7 @@ { pkgs, makeTest, + genTests, }: let @@ -43,11 +44,7 @@ let ''; }; in -lib.recurseIntoAttrs ( - lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( - lib.filterAttrs (_: p: p ? pkgs && !p.pkgs.wal2json.meta.broken) pkgs.postgresqlVersions - ) - // { - passthru.override = p: makeTestFor p; - } -) +genTests { + inherit makeTestFor; + filter = _: p: !p.pkgs.wal2json.meta.broken; +} diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix index cfff0f4a98b9..c6a47a424959 100644 --- a/pkgs/servers/sql/postgresql/default.nix +++ b/pkgs/servers/sql/postgresql/default.nix @@ -33,5 +33,9 @@ let libpq = self.callPackage ./libpq.nix { }; in -# variations without and with JIT -(mkAttributes false) // (mkAttributes true) // { inherit libpq; } +{ + # variations without and with JIT + postgresqlVersions = mkAttributes false // mkAttributes true; + + inherit libpq; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index abec87a7de8b..2fea98c75cea 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11688,10 +11688,11 @@ with pkgs; asciidoc = asciidoc-full; }; - postgresqlVersions = import ../servers/sql/postgresql pkgs; - inherit (postgresqlVersions) - libpq + inherit (import ../servers/sql/postgresql pkgs) + postgresqlVersions + libpq; + inherit (postgresqlVersions) postgresql_13 postgresql_14 postgresql_15