|
1 |
| -{ stdenv, lib, makeWrapper, fetchurl, writeShellScriptBin, findutils, entr, callPackage, lcov, pidFileName, gnused, python3 } : |
| 1 | +{ fetchFromGitHub } : |
2 | 2 | let
|
3 |
| - prefix = "nxpg"; |
4 |
| - ourPg = callPackage ./postgresql { |
5 |
| - inherit lib; |
6 |
| - inherit stdenv; |
7 |
| - inherit fetchurl; |
8 |
| - inherit makeWrapper; |
9 |
| - inherit callPackage; |
| 3 | + nxpg = fetchFromGitHub { |
| 4 | + owner = "steve-chavez"; |
| 5 | + repo = "nxpg"; |
| 6 | + rev = "v1.1"; |
| 7 | + sha256 = "sha256-R0Z2vDjFtkrFgetL1L/N1iWN0Bh+TWBZ7VZLDARJ3pY="; |
10 | 8 | };
|
11 |
| - supportedPgs = [ |
12 |
| - ourPg.postgresql_17 |
13 |
| - ourPg.postgresql_16 |
14 |
| - ourPg.postgresql_15 |
15 |
| - ourPg.postgresql_14 |
16 |
| - ourPg.postgresql_13 |
17 |
| - ourPg.postgresql_12 |
18 |
| - ]; |
19 |
| - build = |
20 |
| - writeShellScriptBin "${prefix}-build" '' |
21 |
| - set -euo pipefail |
22 |
| -
|
23 |
| - make clean |
24 |
| - make |
25 |
| - ''; |
26 |
| - buildCov = |
27 |
| - writeShellScriptBin "${prefix}-build-cov" '' |
28 |
| - set -euo pipefail |
29 |
| -
|
30 |
| - make clean |
31 |
| - make COVERAGE=1 |
32 |
| - ''; |
33 |
| - test = |
34 |
| - writeShellScriptBin "${prefix}-test" '' |
35 |
| - set -euo pipefail |
36 |
| -
|
37 |
| - ${python3}/bin/python -m pytest -vv "$@" |
38 |
| - ''; |
39 |
| - cov = |
40 |
| - writeShellScriptBin "${prefix}-coverage" '' |
41 |
| - set -euo pipefail |
42 |
| -
|
43 |
| - info_file="coverage.info" |
44 |
| - out_dir="coverage_html" |
45 |
| -
|
46 |
| - ${python3}/bin/python -m pytest -vv "$@" |
47 |
| -
|
48 |
| - ${lcov}/bin/lcov --capture --directory . --output-file "$info_file" |
49 |
| -
|
50 |
| - # remove postgres headers on the nix store, otherwise they show on the output |
51 |
| - ${lcov}/bin/lcov --remove "$info_file" '/nix/*' --output-file "$info_file" || true |
52 |
| -
|
53 |
| - ${lcov}/bin/lcov --list coverage.info |
54 |
| - ${lcov}/bin/genhtml "$info_file" --output-directory "$out_dir" |
55 |
| -
|
56 |
| - echo "${prefix}-coverage: To see the results, visit file://$(pwd)/$out_dir/index.html on your browser" |
57 |
| - ''; |
58 |
| - watch = |
59 |
| - writeShellScriptBin "${prefix}-watch" '' |
60 |
| - set -euo pipefail |
61 |
| -
|
62 |
| - ${findutils}/bin/find . -type f \( -name '*.c' -o -name '*.h' \) | ${entr}/bin/entr -dr "$@" |
63 |
| - ''; |
64 |
| - |
65 |
| - tmpDb = |
66 |
| - writeShellScriptBin "${prefix}-tmp" '' |
67 |
| - set -euo pipefail |
68 |
| -
|
69 |
| - export tmpdir="$(mktemp -d)" |
70 |
| -
|
71 |
| - export PGDATA="$tmpdir" |
72 |
| - export PGHOST="$tmpdir" |
73 |
| - export PGUSER=postgres |
74 |
| - export PGDATABASE=postgres |
75 |
| -
|
76 |
| - trap 'pg_ctl stop -m i && rm -rf "$tmpdir" && rm ${pidFileName}' sigint sigterm exit |
77 |
| -
|
78 |
| - PGTZ=UTC initdb --no-locale --encoding=UTF8 --nosync -U "$PGUSER" |
79 |
| -
|
80 |
| - # pg versions older than 16 don't support adding "-c" to initdb to add these options |
81 |
| - # so we just modify the resulting postgresql.conf to avoid an error |
82 |
| - echo "dynamic_library_path='\$libdir:$(pwd)'" >> $PGDATA/postgresql.conf |
83 |
| - echo "extension_control_path='\$system:$(pwd)'" >> $PGDATA/postgresql.conf |
84 |
| -
|
85 |
| - options="-F -c listen_addresses=\"\" -c log_min_messages=\"''${LOG_MIN_MESSAGES:-INFO}\" -k $PGDATA" |
86 |
| -
|
87 |
| - ext_options="-c shared_preload_libraries=\"pg_net\"" |
88 |
| -
|
89 |
| - pg_ctl start -o "$options" -o "$ext_options" |
90 |
| -
|
91 |
| - psql -v ON_ERROR_STOP=1 -c "create database pre_existing" -d postgres |
92 |
| -
|
93 |
| - psql -v ON_ERROR_STOP=1 -c "create role pre_existing nosuperuser login" -d postgres |
94 |
| -
|
95 |
| - psql -v ON_ERROR_STOP=1 -c "create extension pg_net" -d postgres |
96 |
| -
|
97 |
| - psql -t -c "\o ${pidFileName}" -c "select pid from pg_stat_activity where backend_type ilike '%pg_net%'" |
98 |
| -
|
99 |
| - ${gnused}/bin/sed '/^''$/d;s/[[:blank:]]//g' -i ${pidFileName} |
100 |
| -
|
101 |
| - psql -f ${./bench.sql} |
102 |
| -
|
103 |
| - "$@" |
104 |
| - ''; |
105 |
| - allPgPaths = map (pg: |
106 |
| - let |
107 |
| - ver = builtins.head (builtins.splitVersion pg.version); |
108 |
| - script = '' |
109 |
| - set -euo pipefail |
110 |
| -
|
111 |
| - export PATH=${pg}/bin:"$PATH" |
112 |
| -
|
113 |
| - "$@" |
114 |
| - ''; |
115 |
| - in |
116 |
| - writeShellScriptBin "${prefix}-${ver}" script |
117 |
| - ) supportedPgs; |
118 |
| - |
119 |
| - netWith = map (pg: |
120 |
| - let |
121 |
| - ver = builtins.head (builtins.splitVersion pg.version); |
122 |
| - script = '' |
123 |
| - set -euo pipefail |
124 |
| - export PATH=${pg}/bin:"$PATH" |
125 |
| - ${buildCov}/bin/${prefix}-build-cov |
126 |
| - ${tmpDb}/bin/${prefix}-tmp "$@" |
127 |
| - ''; |
128 |
| - in |
129 |
| - writeShellScriptBin "net-with-pg-${ver}" script |
130 |
| - ) supportedPgs; |
| 9 | + script = import nxpg; |
131 | 10 | in
|
132 |
| -[ |
133 |
| - build |
134 |
| - buildCov |
135 |
| - test |
136 |
| - cov |
137 |
| - watch |
138 |
| - tmpDb |
139 |
| - allPgPaths |
140 |
| - netWith |
141 |
| -] |
| 11 | +script |
0 commit comments