|
15 | 15 | extraSubstitutions ? { },
|
16 | 16 | }:
|
17 | 17 | let
|
18 |
| - paths = { |
19 |
| - migrationsDir = builtins.path { |
20 |
| - name = "migrations"; |
21 |
| - path = ../../migrations/db; |
22 |
| - }; |
23 |
| - postgresqlSchemaSql = builtins.path { |
24 |
| - name = "postgresql-schema"; |
25 |
| - path = ../tools/postgresql_schema.sql; |
26 |
| - }; |
27 |
| - pgbouncerAuthSchemaSql = builtins.path { |
28 |
| - name = "pgbouncer-auth-schema"; |
29 |
| - path = ../../ansible/files/pgbouncer_config/pgbouncer_auth_schema.sql; |
30 |
| - }; |
31 |
| - statExtensionSql = builtins.path { |
32 |
| - name = "stat-extension"; |
33 |
| - path = ../../ansible/files/stat_extension.sql; |
34 |
| - }; |
35 |
| - pgconfigFile = builtins.path { |
36 |
| - name = "postgresql.conf"; |
37 |
| - path = ../../ansible/files/postgresql_config/postgresql.conf.j2; |
38 |
| - }; |
39 |
| - supautilsConfigFile = builtins.path { |
40 |
| - name = "supautils.conf"; |
41 |
| - path = ../../ansible/files/postgresql_config/supautils.conf.j2; |
42 |
| - }; |
43 |
| - loggingConfigFile = builtins.path { |
44 |
| - name = "logging.conf"; |
45 |
| - path = ../../ansible/files/postgresql_config/postgresql-csvlog.conf; |
46 |
| - }; |
47 |
| - readReplicaConfigFile = builtins.path { |
48 |
| - name = "readreplica.conf"; |
49 |
| - path = ../../ansible/files/postgresql_config/custom_read_replica.conf.j2; |
50 |
| - }; |
51 |
| - pgHbaConfigFile = |
52 |
| - if pkgs == psql_15 then |
53 |
| - builtins.path { |
54 |
| - name = "pg_hba.conf"; |
55 |
| - path = ../../ansible/files/postgresql_config/pg_hba.conf_15.j2; |
56 |
| - } |
57 |
| - else |
58 |
| - builtins.path { |
59 |
| - name = "pg_hba.conf"; |
60 |
| - path = ../../ansible/files/postgresql_config/pg_hba.conf.j2; |
61 |
| - }; |
62 |
| - pgHbaUsersPublicConfigFile = |
63 |
| - if pkgs != psql_15 then |
64 |
| - builtins.path { |
65 |
| - name = "pg_hba_users_public.conf"; |
66 |
| - path = ../../ansible/files/postgresql_config/pg_hba_users_public.conf.j2; |
| 18 | + inherit (lib) versions getVersion; |
| 19 | + pgVersion = versions.major (getVersion postgresPkg); |
| 20 | + |
| 21 | + paths = |
| 22 | + { |
| 23 | + migrationsDir = builtins.path { |
| 24 | + name = "migrations"; |
| 25 | + path = ../../migrations/db; |
| 26 | + }; |
| 27 | + postgresqlSchemaSql = builtins.path { |
| 28 | + name = "postgresql-schema"; |
| 29 | + path = ../tools/postgresql_schema.sql; |
| 30 | + }; |
| 31 | + pgbouncerAuthSchemaSql = builtins.path { |
| 32 | + name = "pgbouncer-auth-schema"; |
| 33 | + path = ../../ansible/files/pgbouncer_config/pgbouncer_auth_schema.sql; |
| 34 | + }; |
| 35 | + statExtensionSql = builtins.path { |
| 36 | + name = "stat-extension"; |
| 37 | + path = ../../ansible/files/stat_extension.sql; |
| 38 | + }; |
| 39 | + pgconfigFile = builtins.path { |
| 40 | + name = "postgresql.conf"; |
| 41 | + path = ../../ansible/files/postgresql_config/postgresql.conf.j2; |
| 42 | + }; |
| 43 | + supautilsConfigFile = builtins.path { |
| 44 | + name = "supautils.conf"; |
| 45 | + path = ../../ansible/files/postgresql_config/supautils.conf.j2; |
| 46 | + }; |
| 47 | + loggingConfigFile = builtins.path { |
| 48 | + name = "logging.conf"; |
| 49 | + path = ../../ansible/files/postgresql_config/postgresql-csvlog.conf; |
| 50 | + }; |
| 51 | + readReplicaConfigFile = builtins.path { |
| 52 | + name = "readreplica.conf"; |
| 53 | + path = ../../ansible/files/postgresql_config/custom_read_replica.conf.j2; |
| 54 | + }; |
| 55 | + pgIdentConfigFile = builtins.path { |
| 56 | + name = "pg_ident.conf"; |
| 57 | + path = ../../ansible/files/postgresql_config/pg_ident.conf.j2; |
| 58 | + }; |
| 59 | + postgresqlExtensionCustomScriptsPath = builtins.path { |
| 60 | + name = "extension-custom-scripts"; |
| 61 | + path = ../../ansible/files/postgresql_extension_custom_scripts; |
| 62 | + }; |
| 63 | + getkeyScript = builtins.path { |
| 64 | + name = "pgsodium_getkey.sh"; |
| 65 | + path = ../tests/util/pgsodium_getkey.sh; |
| 66 | + }; |
| 67 | + } |
| 68 | + // ( |
| 69 | + if pgVersion == "15" then |
| 70 | + { |
| 71 | + pgHbaConfigFile = builtins.path { |
| 72 | + name = "pg_hba.conf"; |
| 73 | + path = ../../ansible/files/postgresql_config/pg_hba.conf_15.j2; |
| 74 | + }; |
67 | 75 | }
|
68 | 76 | else
|
69 |
| - null; |
70 |
| - pgHbaPublicConfigFile = |
71 |
| - if pkgs != psql_15 then |
72 |
| - builtins.path { |
73 |
| - name = "pg_hba_public.conf"; |
74 |
| - path = ../../ansible/files/postgresql_config/pg_hba_public.conf.j2; |
| 77 | + { |
| 78 | + pgHbaConfigFile = builtins.path { |
| 79 | + name = "pg_hba.conf"; |
| 80 | + path = ../../ansible/files/postgresql_config/pg_hba.conf.j2; |
| 81 | + }; |
| 82 | + pgHbaUsersPublicConfigFile = builtins.path { |
| 83 | + name = "pg_hba_users_public.conf"; |
| 84 | + path = ../../ansible/files/postgresql_config/pg_hba_users_public.conf.j2; |
| 85 | + }; |
| 86 | + pgHbaPublicConfigFile = builtins.path { |
| 87 | + name = "pg_hba_public.conf"; |
| 88 | + path = ../../ansible/files/postgresql_config/pg_hba_public.conf.j2; |
| 89 | + }; |
75 | 90 | }
|
76 |
| - else |
77 |
| - null; |
78 |
| - pgIdentConfigFile = builtins.path { |
79 |
| - name = "pg_ident.conf"; |
80 |
| - path = ../../ansible/files/postgresql_config/pg_ident.conf.j2; |
81 |
| - }; |
82 |
| - postgresqlExtensionCustomScriptsPath = builtins.path { |
83 |
| - name = "extension-custom-scripts"; |
84 |
| - path = ../../ansible/files/postgresql_extension_custom_scripts; |
85 |
| - }; |
86 |
| - getkeyScript = builtins.path { |
87 |
| - name = "pgsodium_getkey.sh"; |
88 |
| - path = ../tests/util/pgsodium_getkey.sh; |
89 |
| - }; |
90 |
| - }; |
| 91 | + ); |
91 | 92 |
|
92 | 93 | localeArchive =
|
93 | 94 | if pkgs.stdenv.isDarwin then
|
|
130 | 131 | ;
|
131 | 132 | }
|
132 | 133 | ''
|
133 |
| - mkdir -p $out/bin $out/etc/postgresql-custom $out/etc/postgresql $out/extension-custom-scripts |
| 134 | + mkdir -p $out/bin $out/etc/postgresql-custom $out/etc/postgresql $out/extension-custom-scripts |
134 | 135 |
|
135 |
| - # Copy config files with error handling |
136 |
| - cp ${paths.supautilsConfigFile} $out/etc/postgresql-custom/supautils.conf || { echo "Failed to copy supautils.conf"; exit 1; } |
137 |
| - cp ${paths.pgconfigFile} $out/etc/postgresql/postgresql.conf || { echo "Failed to copy postgresql.conf"; exit 1; } |
138 |
| - cp ${paths.loggingConfigFile} $out/etc/postgresql-custom/logging.conf || { echo "Failed to copy logging.conf"; exit 1; } |
139 |
| - cp ${paths.readReplicaConfigFile} $out/etc/postgresql-custom/read-replica.conf || { echo "Failed to copy read-replica.conf"; exit 1; } |
140 |
| - cp ${paths.pgHbaConfigFile} $out/etc/postgresql/pg_hba.conf || { echo "Failed to copy pg_hba.conf"; exit 1; } |
| 136 | + # Copy config files with error handling |
| 137 | + cp ${paths.supautilsConfigFile} $out/etc/postgresql-custom/supautils.conf || { echo "Failed to copy supautils.conf"; exit 1; } |
| 138 | + cp ${paths.pgconfigFile} $out/etc/postgresql/postgresql.conf || { echo "Failed to copy postgresql.conf"; exit 1; } |
| 139 | + cp ${paths.loggingConfigFile} $out/etc/postgresql-custom/logging.conf || { echo "Failed to copy logging.conf"; exit 1; } |
| 140 | + cp ${paths.readReplicaConfigFile} $out/etc/postgresql-custom/read-replica.conf || { echo "Failed to copy read-replica.conf"; exit 1; } |
| 141 | + cp ${paths.pgHbaConfigFile} $out/etc/postgresql/pg_hba.conf || { echo "Failed to copy pg_hba.conf"; exit 1; } |
141 | 142 |
|
142 |
| - # these shouldn't exist on psql_15 |
143 |
| - if [ -n "${toString paths.pgHbaUsersPublicConfigFile}" ]; then |
| 143 | + # these shouldn't exist on psql_15 |
| 144 | + ${lib.optionalString (paths ? pgHbaUsersPublicConfigFile) '' |
144 | 145 | cp ${paths.pgHbaUsersPublicConfigFile} $out/etc/postgresql/pg_hba_users_public.conf || { echo "Failed to copy pg_hba_users_public.conf"; exit 1; }
|
145 |
| - fi |
146 |
| - if [ -n "${toString paths.pgHbaPublicConfigFile}" ]; then |
147 |
| - cp ${paths.pgHbaPublicConfigFile} $out/etc/postgresql/pg_hba_public.conf || { echo "Failed to copy pg_hba_public.conf"; exit 1; } |
148 |
| - fi |
149 |
| - cp ${paths.pgIdentConfigFile} $out/etc/postgresql/pg_ident.conf || { echo "Failed to copy pg_ident.conf"; exit 1; } |
150 |
| - cp -r ${paths.postgresqlExtensionCustomScriptsPath}/* $out/extension-custom-scripts/ || { echo "Failed to copy custom scripts"; exit 1; } |
| 146 | + ''} |
| 147 | + ${ |
| 148 | + lib.optionalString (paths ? pgHbaPublicConfigFile) '' |
| 149 | + cp ${paths.pgHbaPublicConfigFile} $out/etc/postgresql/pg_hba_public.conf || { echo "Failed to copy pg_hba_public.conf"; exit 1; } |
| 150 | + '' |
| 151 | + } |
| 152 | + cp ${paths.pgIdentConfigFile} $out/etc/postgresql/pg_ident.conf || { echo "Failed to copy pg_ident.conf"; exit 1; } |
| 153 | + cp -r ${paths.postgresqlExtensionCustomScriptsPath}/* $out/extension-custom-scripts/ || { echo "Failed to copy custom scripts"; exit 1; } |
151 | 154 |
|
152 |
| - echo "Copy operation completed" |
153 |
| - chmod 644 $out/etc/postgresql-custom/supautils.conf |
154 |
| - chmod 644 $out/etc/postgresql/postgresql.conf |
155 |
| - chmod 644 $out/etc/postgresql-custom/logging.conf |
156 |
| - chmod 644 $out/etc/postgresql/pg_hba.conf |
| 155 | + echo "Copy operation completed" |
| 156 | + chmod 644 $out/etc/postgresql-custom/supautils.conf |
| 157 | + chmod 644 $out/etc/postgresql/postgresql.conf |
| 158 | + chmod 644 $out/etc/postgresql-custom/logging.conf |
| 159 | + chmod 644 $out/etc/postgresql/pg_hba.conf |
157 | 160 |
|
158 |
| - if [ -n "${toString paths.pgHbaUsersPublicConfigFile}" ]; then |
159 |
| - chmod 644 $out/etc/postgresql/pg_hba_users_public.conf |
160 |
| - fi |
161 |
| - if [ -n "${toString paths.pgHbaPublicConfigFile}" ]; then |
162 |
| - chmod 644 $out/etc/postgresql/pg_hba_public.conf |
163 |
| - fi |
| 161 | + ${ |
| 162 | + lib.optionalString (paths ? pgHbaUsersPublicConfigFile) '' |
| 163 | + chmod 644 $out/etc/postgresql/pg_hba_users_public.conf |
| 164 | + '' |
| 165 | + } |
| 166 | + ${ |
| 167 | + lib.optionalString (paths ? pgHbaPublicConfigFile) '' |
| 168 | + chmod 644 $out/etc/postgresql/pg_hba_public.conf |
| 169 | + '' |
| 170 | + } |
164 | 171 |
|
165 |
| - substitute ${../tools/run-server.sh.in} $out/bin/start-postgres-server \ |
166 |
| - ${ |
167 |
| - builtins.concatStringsSep " " ( |
168 |
| - builtins.attrValues ( |
169 |
| - builtins.mapAttrs (name: value: "--subst-var-by '${name}' '${value}'") substitutions |
170 |
| - ) |
171 |
| - ) |
172 |
| - } |
173 |
| - chmod +x $out/bin/start-postgres-server |
| 172 | + substitute ${../tools/run-server.sh.in} $out/bin/start-postgres-server \ |
| 173 | + ${ |
| 174 | + builtins.concatStringsSep " " ( |
| 175 | + builtins.attrValues ( |
| 176 | + builtins.mapAttrs (name: value: "--subst-var-by '${name}' '${value}'") substitutions |
| 177 | + ) |
| 178 | + ) |
| 179 | + } |
| 180 | + chmod +x $out/bin/start-postgres-server |
174 | 181 | '';
|
175 | 182 | }
|
0 commit comments