|
4 | 4 | fetchFromGitHub, |
5 | 5 | postgresql, |
6 | 6 | postgresqlTestHook, |
| 7 | + buildEnv, |
7 | 8 | }: |
| 9 | +let |
| 10 | + pname = "plpgsql_check"; |
8 | 11 |
|
9 | | -stdenv.mkDerivation rec { |
10 | | - pname = "plpgsql-check"; |
11 | | - version = "2.7.11"; |
| 12 | + # Load version configuration from external file |
| 13 | + allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname}; |
12 | 14 |
|
13 | | - src = fetchFromGitHub { |
14 | | - owner = "okbob"; |
15 | | - repo = "plpgsql_check"; |
16 | | - rev = "v${version}"; |
17 | | - hash = "sha256-vR3MvfmUP2QEAtXFpq0NCCKck3wZPD+H3QleHtyVQJs="; |
18 | | - }; |
| 15 | + # Filter versions compatible with current PostgreSQL version |
| 16 | + supportedVersions = lib.filterAttrs ( |
| 17 | + _: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql |
| 18 | + ) allVersions; |
19 | 19 |
|
20 | | - buildInputs = [ postgresql ]; |
| 20 | + # Derived version information |
| 21 | + versions = lib.naturalSort (lib.attrNames supportedVersions); |
| 22 | + latestVersion = lib.last versions; |
| 23 | + numberOfVersions = builtins.length versions; |
| 24 | + packages = builtins.attrValues ( |
| 25 | + lib.mapAttrs (name: value: build name value.hash value.revision) supportedVersions |
| 26 | + ); |
21 | 27 |
|
22 | | - installPhase = '' |
23 | | - install -D -t $out/lib *${postgresql.dlSuffix} |
24 | | - install -D -t $out/share/postgresql/extension *.sql |
25 | | - install -D -t $out/share/postgresql/extension *.control |
26 | | - ''; |
| 28 | + # Build function for individual versions |
| 29 | + build = |
| 30 | + version: hash: revision: |
| 31 | + stdenv.mkDerivation rec { |
| 32 | + inherit pname version; |
27 | 33 |
|
28 | | - passthru.tests.extension = stdenv.mkDerivation { |
29 | | - name = "plpgsql-check-test"; |
30 | | - dontUnpack = true; |
31 | | - doCheck = true; |
32 | | - buildInputs = [ postgresqlTestHook ]; |
33 | | - nativeCheckInputs = [ (postgresql.withPackages (ps: [ ps.plpgsql_check ])) ]; |
34 | | - postgresqlTestUserOptions = "LOGIN SUPERUSER"; |
35 | | - failureHook = "postgresqlStop"; |
36 | | - checkPhase = '' |
37 | | - runHook preCheck |
38 | | - psql -a -v ON_ERROR_STOP=1 -c "CREATE EXTENSION plpgsql_check;" |
39 | | - runHook postCheck |
40 | | - ''; |
41 | | - installPhase = "touch $out"; |
42 | | - }; |
| 34 | + src = fetchFromGitHub { |
| 35 | + owner = "okbob"; |
| 36 | + repo = "plpgsql_check"; |
| 37 | + rev = "v${revision}"; |
| 38 | + inherit hash; |
| 39 | + }; |
| 40 | + |
| 41 | + buildInputs = [ postgresql ]; |
| 42 | + |
| 43 | + installPhase = '' |
| 44 | + mkdir -p $out/{lib,share/postgresql/extension} |
| 45 | +
|
| 46 | + # Install shared library with version suffix |
| 47 | + mv ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix} |
| 48 | +
|
| 49 | + # Create version-specific control file |
| 50 | + sed -e "/^default_version =/d" \ |
| 51 | + -e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}-${version}'|" \ |
| 52 | + ${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control |
| 53 | +
|
| 54 | + # For the latest version, create default control file and symlink and copy SQL upgrade scripts |
| 55 | + if [[ "${version}" == "${latestVersion}" ]]; then |
| 56 | + { |
| 57 | + echo "default_version = '${version}'" |
| 58 | + cat $out/share/postgresql/extension/${pname}--${version}.control |
| 59 | + } > $out/share/postgresql/extension/${pname}.control |
| 60 | + ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix} |
| 61 | + cp *.sql $out/share/postgresql/extension |
| 62 | + else |
| 63 | + mv ./${pname}--${version}.sql $out/share/postgresql/extension/${pname}--${version}.sql |
| 64 | + fi |
| 65 | + ''; |
| 66 | + |
| 67 | + passthru.tests.extension = stdenv.mkDerivation { |
| 68 | + name = "plpgsql-check-test"; |
| 69 | + dontUnpack = true; |
| 70 | + doCheck = true; |
| 71 | + buildInputs = [ postgresqlTestHook ]; |
| 72 | + nativeCheckInputs = [ (postgresql.withPackages (ps: [ ps.plpgsql_check ])) ]; |
| 73 | + postgresqlTestUserOptions = "LOGIN SUPERUSER"; |
| 74 | + failureHook = "postgresqlStop"; |
| 75 | + checkPhase = '' |
| 76 | + runHook preCheck |
| 77 | + psql -a -v ON_ERROR_STOP=1 -c "CREATE EXTENSION plpgsql_check;" |
| 78 | + runHook postCheck |
| 79 | + ''; |
| 80 | + installPhase = "touch $out"; |
| 81 | + }; |
| 82 | + |
| 83 | + meta = with lib; { |
| 84 | + description = "Linter tool for language PL/pgSQL"; |
| 85 | + homepage = "https://github.com/okbob/plpgsql_check"; |
| 86 | + changelog = "https://github.com/okbob/plpgsql_check/releases/tag/v${version}"; |
| 87 | + license = licenses.mit; |
| 88 | + maintainers = [ maintainers.marsam ]; |
| 89 | + inherit (postgresql.meta) platforms; |
| 90 | + }; |
| 91 | + }; |
| 92 | +in |
| 93 | +buildEnv { |
| 94 | + name = pname; |
| 95 | + paths = packages; |
| 96 | + |
| 97 | + pathsToLink = [ |
| 98 | + "/lib" |
| 99 | + "/share/postgresql/extension" |
| 100 | + ]; |
| 101 | + |
| 102 | + postBuild = '' |
| 103 | + # Verify all expected library files are present |
| 104 | + expectedFiles=${toString (numberOfVersions + 1)} |
| 105 | + actualFiles=$(ls -l $out/lib/${pname}*${postgresql.dlSuffix} | wc -l) |
| 106 | +
|
| 107 | + if [[ "$actualFiles" != "$expectedFiles" ]]; then |
| 108 | + echo "Error: Expected $expectedFiles library files, found $actualFiles" |
| 109 | + echo "Files found:" |
| 110 | + ls -la $out/lib/*${postgresql.dlSuffix} || true |
| 111 | + exit 1 |
| 112 | + fi |
| 113 | + ''; |
43 | 114 |
|
44 | | - meta = with lib; { |
45 | | - description = "Linter tool for language PL/pgSQL"; |
46 | | - homepage = "https://github.com/okbob/plpgsql_check"; |
47 | | - changelog = "https://github.com/okbob/plpgsql_check/releases/tag/v${version}"; |
48 | | - platforms = postgresql.meta.platforms; |
49 | | - license = licenses.mit; |
50 | | - maintainers = [ maintainers.marsam ]; |
| 115 | + passthru = { |
| 116 | + inherit versions numberOfVersions; |
| 117 | + pname = "${pname}-all"; |
| 118 | + version = |
| 119 | + "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions); |
51 | 120 | }; |
52 | 121 | } |
0 commit comments