summaryrefslogtreecommitdiff
path: root/hosts
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2022-05-05 18:03:32 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2022-05-05 18:03:32 +0200
commit74805f291c6f18892165cee1e81fe666d15f681f (patch)
treeecfa29c62b1c0e15a9d575693ec7120caf4ee3ca /hosts
parentf1634e60a4b74297bb7875d847f7d7c0660ca024 (diff)
downloadnixos-74805f291c6f18892165cee1e81fe666d15f681f.tar
nixos-74805f291c6f18892165cee1e81fe666d15f681f.tar.gz
nixos-74805f291c6f18892165cee1e81fe666d15f681f.tar.bz2
nixos-74805f291c6f18892165cee1e81fe666d15f681f.tar.xz
nixos-74805f291c6f18892165cee1e81fe666d15f681f.zip
surtr: postgresql email
Diffstat (limited to 'hosts')
-rw-r--r--hosts/surtr/postgresql.nix37
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{ 2let
3 versioning = sources.pqsl-versioning;
4in {
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 };