diff options
Diffstat (limited to 'hosts/surtr')
-rw-r--r-- | hosts/surtr/postgresql.nix | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/hosts/surtr/postgresql.nix b/hosts/surtr/postgresql.nix index a34bc675..b5035cb2 100644 --- a/hosts/surtr/postgresql.nix +++ b/hosts/surtr/postgresql.nix | |||
@@ -1,5 +1,7 @@ | |||
1 | { pkgs, ... }: | 1 | { pkgs, sources, ... }: |
2 | { | 2 | let |
3 | versioning = sources.pqsl-versioning; | ||
4 | in { | ||
3 | config = { | 5 | config = { |
4 | services.postgresql = { | 6 | services.postgresql = { |
5 | enable = true; | 7 | enable = true; |
@@ -9,6 +11,37 @@ | |||
9 | CREATE USER "matrix-synapse"; | 11 | CREATE USER "matrix-synapse"; |
10 | GRANT ALL PRIVILEGES ON DATABASE "matrix-synapse" TO "matrix-synapse"; | 12 | GRANT ALL PRIVILEGES ON DATABASE "matrix-synapse" TO "matrix-synapse"; |
11 | GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "matrix-synapse"; | 13 | GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "matrix-synapse"; |
14 | |||
15 | CREATE DATABASE "email" WITH TEMPLATE "template0" ENCODING "UTF8" LOCALE "C"; | ||
16 | CREATE USER "postfix"; | ||
17 | GRANT CONNECT ON DATABASE "email" TO "postfix"; | ||
18 | GRANT SELECT ON ALL TABLES IN SCHEMA public TO "postfix"; | ||
19 | CREATE USER "dovecot2"; | ||
20 | GRANT CONNECT ON DATABASE "email" TO "dovecot2"; | ||
21 | GRANT SELECT ON ALL TABLES IN SCHEMA public TO "dovecot2"; | ||
22 | ''; | ||
23 | }; | ||
24 | |||
25 | systemd.services.postgresql = { | ||
26 | postStart = '' | ||
27 | psql email postgres -eXf ${pkgs.writeText "email.sql" '' | ||
28 | \i ${versioning + "/install.versioning.sql"} | ||
29 | |||
30 | BEGIN; | ||
31 | select _v.register_patch('000-base', null, null); | ||
32 | |||
33 | create table virtual_mailbox ( | ||
34 | id uuid PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), | ||
35 | local text, | ||
36 | CHECK (local IS DISTINCT FROM ''''), | ||
37 | domain text NOT NULL, | ||
38 | CHECK (domain <> ''''), | ||
39 | mailbox text NOT NULL, | ||
40 | CHECK (mailbox <> ''''), | ||
41 | UNIQUE(COALESCE(local, ''''), domain) | ||
42 | ); | ||
43 | COMMIT; | ||
44 | ''} | ||
12 | ''; | 45 | ''; |
13 | }; | 46 | }; |
14 | }; | 47 | }; |