|
5 | 5 | postgresql, |
6 | 6 | postgresqlTestHook, |
7 | 7 | testers, |
| 8 | + buildEnv, |
8 | 9 | }: |
9 | | - |
10 | | -stdenv.mkDerivation (finalAttrs: { |
| 10 | +let |
11 | 11 | pname = "pg_repack"; |
12 | | - version = "1.5.2"; |
13 | 12 |
|
14 | | - buildInputs = postgresql.buildInputs ++ [ postgresql ]; |
| 13 | + # Load version configuration from external file |
| 14 | + allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname}; |
15 | 15 |
|
16 | | - src = fetchFromGitHub { |
17 | | - owner = "reorg"; |
18 | | - repo = "pg_repack"; |
19 | | - rev = "ver_${finalAttrs.version}"; |
20 | | - hash = "sha256-wfjiLkx+S3zVrAynisX1GdazueVJ3EOwQEPcgUQt7eA="; |
21 | | - }; |
| 16 | + # Filter versions compatible with current PostgreSQL version |
| 17 | + supportedVersions = lib.filterAttrs ( |
| 18 | + _: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql |
| 19 | + ) allVersions; |
22 | 20 |
|
23 | | - installPhase = '' |
24 | | - install -D bin/pg_repack -t $out/bin/ |
25 | | - install -D lib/pg_repack${postgresql.dlSuffix} -t $out/lib/ |
26 | | - install -D lib/{pg_repack--${finalAttrs.version}.sql,pg_repack.control} -t $out/share/postgresql/extension |
27 | | - ''; |
| 21 | + # Derived version information |
| 22 | + versions = lib.naturalSort (lib.attrNames supportedVersions); |
| 23 | + latestVersion = lib.last versions; |
| 24 | + numberOfVersions = builtins.length versions; |
| 25 | + packages = builtins.attrValues ( |
| 26 | + lib.mapAttrs (name: value: build name value.hash) supportedVersions |
| 27 | + ); |
| 28 | + |
| 29 | + # Build function for individual versions |
| 30 | + build = |
| 31 | + version: hash: |
| 32 | + stdenv.mkDerivation (finalAttrs: { |
| 33 | + inherit pname version; |
| 34 | + |
| 35 | + buildInputs = postgresql.buildInputs ++ [ postgresql ]; |
| 36 | + |
| 37 | + src = fetchFromGitHub { |
| 38 | + owner = "reorg"; |
| 39 | + repo = "pg_repack"; |
| 40 | + rev = "ver_${finalAttrs.version}"; |
| 41 | + inherit hash; |
| 42 | + }; |
| 43 | + |
| 44 | + installPhase = '' |
| 45 | + mkdir -p $out/{lib,share/postgresql/extension,bin} |
| 46 | +
|
| 47 | + mv bin/${pname} $out/bin/${pname}-${version} |
| 48 | +
|
| 49 | + # Install shared library with version suffix |
| 50 | + mv lib/${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix} |
28 | 51 |
|
29 | | - passthru.tests = { |
30 | | - version = testers.testVersion { package = finalAttrs.finalPackage; }; |
31 | | - extension = stdenv.mkDerivation { |
32 | | - name = "plpgsql-check-test"; |
33 | | - dontUnpack = true; |
34 | | - doCheck = true; |
35 | | - buildInputs = [ postgresqlTestHook ]; |
36 | | - nativeCheckInputs = [ (postgresql.withPackages (ps: [ ps.pg_repack ])) ]; |
37 | | - postgresqlTestUserOptions = "LOGIN SUPERUSER"; |
38 | | - failureHook = "postgresqlStop"; |
39 | | - checkPhase = '' |
40 | | - runHook preCheck |
41 | | - psql -a -v ON_ERROR_STOP=1 -c "CREATE EXTENSION pg_repack;" |
42 | | - runHook postCheck |
| 52 | + # Create version-specific control file |
| 53 | + sed -e "/^default_version =/d" \ |
| 54 | + -e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}-${version}'|" \ |
| 55 | + lib/${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control |
| 56 | +
|
| 57 | + # Copy SQL install script |
| 58 | + cp lib/${pname}--${version}.sql $out/share/postgresql/extension |
| 59 | +
|
| 60 | + # For the latest version, create default control file and symlink and copy SQL upgrade scripts |
| 61 | + if [[ "${version}" == "${latestVersion}" ]]; then |
| 62 | + { |
| 63 | + echo "default_version = '${version}'" |
| 64 | + cat $out/share/postgresql/extension/${pname}--${version}.control |
| 65 | + } > $out/share/postgresql/extension/${pname}.control |
| 66 | + ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix} |
| 67 | + ln -sfn $out/bin/${pname}-${latestVersion} $out/bin/${pname} |
| 68 | + fi |
| 69 | + #install -D bin/pg_repack -t $out/bin/ |
| 70 | + #install -D lib/pg_repack${postgresql.dlSuffix} -t $out/lib/ |
| 71 | + #install -D lib/{pg_repack--${finalAttrs.version}.sql,pg_repack.control} -t $out/share/postgresql/extension |
43 | 72 | ''; |
44 | | - installPhase = "touch $out"; |
45 | | - }; |
46 | | - }; |
47 | 73 |
|
48 | | - meta = with lib; { |
49 | | - description = "Reorganize tables in PostgreSQL databases with minimal locks"; |
50 | | - longDescription = '' |
51 | | - pg_repack is a PostgreSQL extension which lets you remove bloat from tables and indexes, and optionally restore |
52 | | - the physical order of clustered indexes. Unlike CLUSTER and VACUUM FULL it works online, without holding an |
53 | | - exclusive lock on the processed tables during processing. pg_repack is efficient to boot, |
54 | | - with performance comparable to using CLUSTER directly. |
55 | | - ''; |
56 | | - homepage = "https://github.com/reorg/pg_repack"; |
57 | | - license = licenses.bsd3; |
58 | | - inherit (postgresql.meta) platforms; |
59 | | - mainProgram = "pg_repack"; |
| 74 | + passthru.tests = { |
| 75 | + version = testers.testVersion { package = finalAttrs.finalPackage; }; |
| 76 | + extension = stdenv.mkDerivation { |
| 77 | + name = "plpgsql-check-test"; |
| 78 | + dontUnpack = true; |
| 79 | + doCheck = true; |
| 80 | + buildInputs = [ postgresqlTestHook ]; |
| 81 | + nativeCheckInputs = [ (postgresql.withPackages (ps: [ ps.pg_repack ])) ]; |
| 82 | + postgresqlTestUserOptions = "LOGIN SUPERUSER"; |
| 83 | + failureHook = "postgresqlStop"; |
| 84 | + checkPhase = '' |
| 85 | + runHook preCheck |
| 86 | + psql -a -v ON_ERROR_STOP=1 -c "CREATE EXTENSION pg_repack;" |
| 87 | + runHook postCheck |
| 88 | + ''; |
| 89 | + installPhase = "touch $out"; |
| 90 | + }; |
| 91 | + }; |
| 92 | + |
| 93 | + meta = with lib; { |
| 94 | + description = "Reorganize tables in PostgreSQL databases with minimal locks"; |
| 95 | + longDescription = '' |
| 96 | + pg_repack is a PostgreSQL extension which lets you remove bloat from tables and indexes, and optionally restore |
| 97 | + the physical order of clustered indexes. Unlike CLUSTER and VACUUM FULL it works online, without holding an |
| 98 | + exclusive lock on the processed tables during processing. pg_repack is efficient to boot, |
| 99 | + with performance comparable to using CLUSTER directly. |
| 100 | + ''; |
| 101 | + homepage = "https://github.com/reorg/pg_repack"; |
| 102 | + license = licenses.bsd3; |
| 103 | + inherit (postgresql.meta) platforms; |
| 104 | + mainProgram = "pg_repack"; |
| 105 | + }; |
| 106 | + }); |
| 107 | +in |
| 108 | +buildEnv { |
| 109 | + name = pname; |
| 110 | + paths = packages; |
| 111 | + |
| 112 | + pathsToLink = [ |
| 113 | + "/bin" |
| 114 | + "/lib" |
| 115 | + "/share/postgresql/extension" |
| 116 | + ]; |
| 117 | + |
| 118 | + postBuild = '' |
| 119 | + # Verify all expected library files are present |
| 120 | + expectedFiles=${toString (numberOfVersions + 1)} |
| 121 | + actualFiles=$(ls -l $out/lib/${pname}*${postgresql.dlSuffix} | wc -l) |
| 122 | +
|
| 123 | + if [[ "$actualFiles" != "$expectedFiles" ]]; then |
| 124 | + echo "Error: Expected $expectedFiles library files, found $actualFiles" |
| 125 | + echo "Files found:" |
| 126 | + ls -la $out/lib/*${postgresql.dlSuffix} || true |
| 127 | + exit 1 |
| 128 | + fi |
| 129 | + ''; |
| 130 | + |
| 131 | + passthru = { |
| 132 | + inherit versions numberOfVersions; |
| 133 | + pname = "${pname}-all"; |
| 134 | + version = |
| 135 | + "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions); |
60 | 136 | }; |
61 | | -}) |
| 137 | +} |
0 commit comments