File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 11
11
services . matrix-synapse = {
12
12
addAdditionalOembedProvider = libS . mkOpinionatedOption "add additional oembed providers from oembed.com" ;
13
13
14
+ configurePostgres = lib . mkOption {
15
+ type = lib . types . bool ;
16
+ default = false ;
17
+ example = true ;
18
+ description = "Whether to configure and create a local PostgreSQL database." ;
19
+ } ;
20
+
14
21
domain = lib . mkOption {
15
22
type = lib . types . str ;
16
23
example = "matrix.example.com" ;
198
205
] ;
199
206
} ;
200
207
208
+ services . postgresql = lib . mkIf cfg . configurePostgres {
209
+ databases = [ "matrix-synapse" ] ; # some parts of nixos-modules read this field to know all databases
210
+ } ;
211
+
201
212
services . portunus . seedSettings . groups = lib . mkIf ( cfgl . userGroup != null ) [ {
202
213
long_name = "Matrix Users" ;
203
214
name = cfgl . userGroup ;
204
215
permissions = { } ;
205
216
} ] ;
206
217
218
+ systemd . services = lib . mkIf cfg . configurePostgres {
219
+ # https://element-hq.github.io/synapse/latest/postgres.html#set-up-database
220
+ # https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/services/databases/postgresql.nix#L655
221
+ postgresql . postStart = ''
222
+ $PSQL -tAc "SELECT 1 FROM pg_database WHERE datname = 'matrix-synapse'" | grep -q 1 || $PSQL -tAc 'CREATE DATABASE "matrix-synapse" ENCODING="UTF8" LOCALE="C" TEMPLATE="template0" OWNER="matrix-synapse"'
223
+ '' ;
224
+ } ;
225
+
207
226
users . users = lib . mkIf cfg . listenOnSocket {
208
227
nginx . extraGroups = [ "matrix-synapse" ] ;
209
228
} ;
You can’t perform that action at this time.
0 commit comments