|
1 |
| -{ lib, stdenv, fetchFromGitHub, postgresql }: |
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + fetchFromGitHub, |
| 5 | + postgresql, |
| 6 | + runCommand |
| 7 | +}: |
2 | 8 |
|
3 | 9 | let
|
4 |
| - allVersions = { |
5 |
| - "1.3.1" = { |
6 |
| - rev = "v1.3.1"; |
7 |
| - hash = "sha256-rXotNOtQNmA55ErNxGoNSKZ0pP1uxEVlDGITFHuqGG4="; |
8 |
| - patches = [ ./pg_cron-1.3.1-pg15.patch ]; |
9 |
| - }; |
10 |
| - "1.4.2" = { |
11 |
| - rev = "v1.4.2"; |
12 |
| - hash = "sha256-P0Fd10Q1p+KrExb35G6otHpc6pD61WnMll45H2jkevM="; |
13 |
| - }; |
14 |
| - "1.6.4" = { |
15 |
| - rev = "v1.6.4"; |
16 |
| - hash = "sha256-t1DpFkPiSfdoGG2NgNT7g1lkvSooZoRoUrix6cBID40="; |
17 |
| - }; |
18 |
| - "1.5.2" = { |
19 |
| - rev = "v1.5.2"; |
20 |
| - hash = "sha256-+quVWbKJy6wXpL/zwTk5FF7sYwHA7I97WhWmPO/HSZ4="; |
21 |
| - }; |
22 |
| - }; |
23 |
| - |
24 |
| - # Simple version string that concatenates all versions with dashes |
25 |
| - versionString = "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings ["."] ["-"] v) (lib.attrNames allVersions)); |
26 |
| - |
27 |
| - mkPgCron = pgCronVersion: { rev, hash, patches ? [] }: stdenv.mkDerivation { |
28 |
| - pname = "pg_cron"; |
29 |
| - version = "${pgCronVersion}-pg${lib.versions.major postgresql.version}"; |
| 10 | + pname = "pg_cron"; |
30 | 11 |
|
31 |
| - buildInputs = [ postgresql ]; |
32 |
| - inherit patches; |
33 |
| - |
34 |
| - src = fetchFromGitHub { |
35 |
| - owner = "citusdata"; |
36 |
| - repo = "pg_cron"; |
37 |
| - inherit rev hash; |
38 |
| - }; |
| 12 | + meta = with lib; { |
| 13 | + description = "Run Cron jobs through PostgreSQL (multi-version compatible)"; |
| 14 | + homepage = "https://github.com/citusdata/${pname}"; |
| 15 | + inherit (postgresql.meta) platforms; |
| 16 | + license = licenses.postgresql; |
| 17 | + }; |
39 | 18 |
|
40 |
| - buildPhase = '' |
41 |
| - make PG_CONFIG=${postgresql}/bin/pg_config |
42 |
| - |
43 |
| - # Create version-specific SQL file |
44 |
| - cp pg_cron.sql pg_cron--${pgCronVersion}.sql |
45 |
| -
|
46 |
| - # Create versioned control file with modified module path |
47 |
| - sed -e "/^default_version =/d" \ |
48 |
| - -e "s|^module_pathname = .*|module_pathname = '\$libdir/pg_cron'|" \ |
49 |
| - pg_cron.control > pg_cron--${pgCronVersion}.control |
50 |
| - ''; |
51 |
| - |
52 |
| - installPhase = '' |
53 |
| - mkdir -p $out/{lib,share/postgresql/extension,bin} |
54 |
| - |
55 |
| - # Install versioned library |
56 |
| - install -Dm755 pg_cron${postgresql.dlSuffix} $out/lib/pg_cron-${pgCronVersion}${postgresql.dlSuffix} |
57 |
| - |
58 |
| - # Install version-specific files |
59 |
| - install -Dm644 pg_cron--${pgCronVersion}.sql $out/share/postgresql/extension/ |
60 |
| - install -Dm644 pg_cron--${pgCronVersion}.control $out/share/postgresql/extension/ |
61 |
| - |
62 |
| - # Install upgrade scripts |
63 |
| - find . -name 'pg_cron--*--*.sql' -exec install -Dm644 {} $out/share/postgresql/extension/ \; |
64 |
| - ''; |
| 19 | + allVersions = { |
| 20 | + "1.6.4" = "sha256-t1DpFkPiSfdoGG2NgNT7g1lkvSooZoRoUrix6cBID40="; |
| 21 | + "1.5.2" = "sha256-+quVWbKJy6wXpL/zwTk5FF7sYwHA7I97WhWmPO/HSZ4="; |
| 22 | + "1.4.2" = "sha256-P0Fd10Q1p+KrExb35G6otHpc6pD61WnMll45H2jkevM="; |
65 | 23 | };
|
66 | 24 |
|
67 | 25 | getVersions = pg:
|
68 | 26 | if lib.versionAtLeast pg.version "17"
|
69 | 27 | then { "1.6.4" = allVersions."1.6.4"; }
|
70 | 28 | else allVersions;
|
71 | 29 |
|
72 |
| - allVersionsForPg = lib.mapAttrs mkPgCron (getVersions postgresql); |
| 30 | + mkPackage = version: hash: |
| 31 | + stdenv.mkDerivation (finalAttrs: { |
| 32 | + inherit pname meta; |
| 33 | + version = "${version}-pg${lib.versions.major postgresql.version}"; |
73 | 34 |
|
74 |
| -in |
75 |
| -stdenv.mkDerivation { |
76 |
| - pname = "pg_cron-all"; |
77 |
| - version = versionString; |
| 35 | + src = fetchFromGitHub { |
| 36 | + owner = "citusdata"; |
| 37 | + repo = pname; |
| 38 | + rev = "refs/tags/v${version}"; |
| 39 | + inherit hash; |
| 40 | + }; |
| 41 | + |
| 42 | + buildInputs = [ postgresql ]; |
78 | 43 |
|
79 |
| - buildInputs = lib.attrValues allVersionsForPg; |
| 44 | + buildPhase = '' |
| 45 | + make PG_CONFIG=${postgresql}/bin/pg_config |
| 46 | + |
| 47 | + # Create version-specific SQL file |
| 48 | + cp pg_cron.sql pg_cron--${version}.sql |
| 49 | +
|
| 50 | + # Create versioned control file with modified module path |
| 51 | + sed -e "/^default_version =/d" \ |
| 52 | + -e "s|^module_pathname = .*|module_pathname = '\$libdir/pg_cron'|" \ |
| 53 | + pg_cron.control > pg_cron--${version}.control |
| 54 | + ''; |
| 55 | + |
| 56 | + installPhase = '' |
| 57 | + mkdir -p $out/{lib,share/postgresql/extension} |
| 58 | + |
| 59 | + # Install versioned library |
| 60 | + install -Dm755 pg_cron${postgresql.dlSuffix} $out/lib/pg_cron-${version}${postgresql.dlSuffix} |
| 61 | + |
| 62 | + # Install version-specific files |
| 63 | + install -Dm644 pg_cron--${version}.sql $out/share/postgresql/extension/ |
| 64 | + install -Dm644 pg_cron--${version}.control $out/share/postgresql/extension/ |
| 65 | + |
| 66 | + # Install upgrade scripts |
| 67 | + find . -name 'pg_cron--*--*.sql' -exec install -Dm644 {} $out/share/postgresql/extension/ \; |
| 68 | + ''; |
| 69 | + }); |
| 70 | + |
| 71 | + packages = lib.listToAttrs ( |
| 72 | + lib.attrValues ( |
| 73 | + lib.mapAttrs (version: hash: lib.nameValuePair "v${version}" (mkPackage version hash)) (getVersions postgresql) |
| 74 | + ) |
| 75 | + ); |
| 76 | + |
| 77 | +in |
| 78 | +runCommand "${pname}-all" |
| 79 | + { |
| 80 | + inherit pname meta; |
| 81 | + version = "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings ["."] ["-"] v) (lib.attrNames (getVersions postgresql))); |
80 | 82 |
|
81 |
| - dontUnpack = true; |
82 |
| - dontConfigure = true; |
83 |
| - dontBuild = true; |
| 83 | + buildInputs = lib.attrValues packages; |
84 | 84 |
|
85 |
| - installPhase = '' |
| 85 | + passthru = { |
| 86 | + inherit packages; |
| 87 | + }; |
| 88 | + } |
| 89 | + '' |
86 | 90 | mkdir -p $out/{lib,share/postgresql/extension,bin}
|
87 | 91 |
|
88 | 92 | # Install all versions
|
89 |
| - for drv in ${lib.concatStringsSep " " (lib.attrValues allVersionsForPg)}; do |
| 93 | + for drv in ''${buildInputs[@]}; do |
90 | 94 | ln -sv $drv/lib/* $out/lib/
|
91 | 95 | cp -v --no-clobber $drv/share/postgresql/extension/* $out/share/postgresql/extension/ || true
|
92 | 96 | done
|
@@ -136,12 +140,4 @@ stdenv.mkDerivation {
|
136 | 140 | EOF
|
137 | 141 |
|
138 | 142 | chmod +x $out/bin/switch_pg_cron_version
|
139 |
| - ''; |
140 |
| - |
141 |
| - meta = with lib; { |
142 |
| - description = "Run Cron jobs through PostgreSQL (multi-version compatible)"; |
143 |
| - homepage = "https://github.com/citusdata/pg_cron"; |
144 |
| - inherit (postgresql.meta) platforms; |
145 |
| - license = licenses.postgresql; |
146 |
| - }; |
147 |
| -} |
| 143 | + '' |
0 commit comments