1- { lib , stdenv , fetchFromGitHub , postgresql , perl , perlPackages , which } :
2-
3- stdenv . mkDerivation rec {
1+ {
2+ lib ,
3+ stdenv ,
4+ fetchFromGitHub ,
5+ postgresql ,
6+ perl ,
7+ perlPackages ,
8+ which ,
9+ runCommand ,
10+ } :
11+ let
412 pname = "pgtap" ;
5- version = "1.2.0" ;
6-
7- src = fetchFromGitHub {
8- owner = "theory" ;
9- repo = "pgtap" ;
10- rev = "v${ version } " ;
11- hash = "sha256-lb0PRffwo6J5a6Hqw1ggvn0cW7gPZ02OEcLPi9ineI8=" ;
12- } ;
13-
14- nativeBuildInputs = [ postgresql perl perlPackages . TAPParserSourceHandlerpgTAP which ] ;
15-
16- installPhase = ''
17- install -D {sql/pgtap--${ version } .sql,pgtap.control} -t $out/share/postgresql/extension
18- '' ;
1913
20- meta = with lib ; {
14+ meta = {
2115 description = "A unit testing framework for PostgreSQL" ;
2216 longDescription = ''
2317 pgTAP is a unit testing framework for PostgreSQL written in PL/pgSQL and PL/SQL.
@@ -27,6 +21,79 @@ stdenv.mkDerivation rec {
2721 '' ;
2822 homepage = "https://pgtap.org" ;
2923 inherit ( postgresql . meta ) platforms ;
30- license = licenses . mit ;
24+ license = lib . licenses . mit ;
3125 } ;
32- }
26+
27+ versions = {
28+ "1.3.3" = "sha256-YgvfLGF7pLVcCKD66NnWAydDxtoYHH1DpLiYTEKHJ0E=" ;
29+ "1.3.2" = "sha256-jPfYp94mZenKctCW+3tyyvdgVKW6TDsG1/dbBlHK3vE=" ;
30+ "1.3.1" = "sha256-HOgCb1CCfsfbMbMMWuzFJ4B8CfVm9b0sI2zBY3/kqyI=" ;
31+ "1.3.0" = "sha256-RaafUnrMRbvyf2m2Z+tK6XxVXDGnaOkYkSMxIJLnf6A=" ;
32+ "1.2.0" = "sha256-lb0PRffwo6J5a6Hqw1ggvn0cW7gPZ02OEcLPi9ineI8=" ;
33+ } ;
34+
35+ mkPackage =
36+ version : hash :
37+ stdenv . mkDerivation ( finalAttrs : {
38+ inherit pname version meta ;
39+
40+ src = fetchFromGitHub {
41+ owner = "theory" ;
42+ repo = "pgtap" ;
43+ rev = "refs/tags/v${ version } " ;
44+ inherit hash ;
45+ } ;
46+
47+ nativeBuildInputs = [
48+ postgresql
49+ perl
50+ perlPackages . TAPParserSourceHandlerpgTAP
51+ which
52+ ] ;
53+
54+ postBuild = ''
55+ sed -e "/^default_version =/d" \
56+ -e "s|^module_pathname = .*|module_pathname = '\$libdir/pgtap'|" \
57+ pgtap.control > pgtap--$version.control
58+ '' ;
59+
60+ installPhase = ''
61+ mkdir -p $out/share/postgresql/extension
62+
63+ install -Dm644 sql/pgtap--$version.sql $out/share/postgresql/extension
64+ install -Dm644 pgtap--$version.control $out/share/postgresql/extension
65+ '' ;
66+ } ) ;
67+
68+ packages = lib . listToAttrs (
69+ lib . attrValues (
70+ lib . mapAttrs ( version : hash : lib . nameValuePair "v${ version } " ( mkPackage version hash ) ) versions
71+ )
72+ ) ;
73+ in
74+ runCommand "${ pname } -all"
75+ {
76+ inherit pname meta ;
77+ buildInputs = lib . attrValues packages ;
78+
79+ passthru = {
80+ inherit packages ;
81+ } ;
82+ }
83+ ''
84+ mkdir -p $out/{lib,share/postgresql/extension,bin}
85+
86+ # Install all versions
87+ for drv in '' ${buildInputs[@]}; do
88+ ls $drv/share/postgresql/extension/
89+ cp -v --no-clobber $drv/share/postgresql/extension/* $out/share/postgresql/extension/ || true
90+ done
91+
92+ # Create default symlinks
93+ latest_control=$(ls -v $out/share/postgresql/extension/pgtap--*.control | tail -n1)
94+ latest_version=$(basename "$latest_control" | sed -E 's/pgtap--([0-9.]+).control/\1/')
95+
96+ # Create main control file with default_version
97+ echo "default_version = '$latest_version'" > $out/share/postgresql/extension/pgtap.control
98+ cat "$latest_control" >> $out/share/postgresql/extension/pgtap.control
99+ ''
0 commit comments