summaryrefslogtreecommitdiff
path: root/hosts/surtr
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2022-05-05 19:42:27 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2022-05-05 19:42:27 +0200
commita348ad9cd88d2ae87a879d72453bc6ace03a6590 (patch)
tree7febc6c490d5655db26028055ec91a5ed98acfab /hosts/surtr
parent261bf65c6a34fe8d9a81c2c017b7ef1435da5fea (diff)
downloadnixos-a348ad9cd88d2ae87a879d72453bc6ace03a6590.tar
nixos-a348ad9cd88d2ae87a879d72453bc6ace03a6590.tar.gz
nixos-a348ad9cd88d2ae87a879d72453bc6ace03a6590.tar.bz2
nixos-a348ad9cd88d2ae87a879d72453bc6ace03a6590.tar.xz
nixos-a348ad9cd88d2ae87a879d72453bc6ace03a6590.zip
...
Diffstat (limited to 'hosts/surtr')
-rw-r--r--hosts/surtr/email/default.nix2
-rw-r--r--hosts/surtr/postgresql.nix4
2 files changed, 4 insertions, 2 deletions
diff --git a/hosts/surtr/email/default.nix b/hosts/surtr/email/default.nix
index eb4ec69e..b4ae5ffb 100644
--- a/hosts/surtr/email/default.nix
+++ b/hosts/surtr/email/default.nix
@@ -293,7 +293,7 @@ in {
293 args = ${pkgs.writeText "dovecot-sql.conf" '' 293 args = ${pkgs.writeText "dovecot-sql.conf" ''
294 driver = pgsql 294 driver = pgsql
295 connect = host=localhost dbname=email 295 connect = host=localhost dbname=email
296 user_query = SELECT mailbox AS user, quota_rule FROM mailbox WHERE mailbox = '%u' 296 user_query = SELECT user, quota_rule FROM imap_user WHERE user = '%u'
297 ''} 297 ''}
298 default_fields = uid=dovecot2 gid=dovecot2 298 default_fields = uid=dovecot2 gid=dovecot2
299 } 299 }
diff --git a/hosts/surtr/postgresql.nix b/hosts/surtr/postgresql.nix
index 932ff531..e3384fbd 100644
--- a/hosts/surtr/postgresql.nix
+++ b/hosts/surtr/postgresql.nix
@@ -34,7 +34,7 @@ in {
34 id uuid PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), 34 id uuid PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(),
35 mailbox text NOT NULL CONSTRAINT mailbox_non_empty CHECK (mailbox <> '''), 35 mailbox text NOT NULL CONSTRAINT mailbox_non_empty CHECK (mailbox <> '''),
36 quota_bytes bigint CONSTRAINT quota_bytes_positive CHECK (CASE WHEN quota_bytes IS NOT NULL THEN quota_bytes > 0 ELSE true END), 36 quota_bytes bigint CONSTRAINT quota_bytes_positive CHECK (CASE WHEN quota_bytes IS NOT NULL THEN quota_bytes > 0 ELSE true END),
37 quota_rule text GENERATED ALWAYS AS (CASE WHEN quota_bytes IS NULL THEN '*:ignore' ELSE '*:bytes=' || quota_bytes END) STORED 37 CONSTRAINT mailbox_unique UNIQUE mailbox
38 ); 38 );
39 CREATE TABLE mailbox_mapping ( 39 CREATE TABLE mailbox_mapping (
40 id uuid PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), 40 id uuid PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(),
@@ -47,6 +47,8 @@ in {
47 47
48 CREATE VIEW virtual_mailbox_domain (domain) AS SELECT DISTINCT domain FROM virtual_mailbox_mapping; 48 CREATE VIEW virtual_mailbox_domain (domain) AS SELECT DISTINCT domain FROM virtual_mailbox_mapping;
49 CREATE VIEW virtual_mailbox_mapping (mailbox, lookup) AS SELECT mailbox.mailbox as mailbox, (CASE WHEN local IS NULL THEN ''' ELSE local END) || '@' || domain AS lookup FROM mailbox_mapping INNER JOIN mailbox on mailbox.id = mailbox_mapping.mailbox; 49 CREATE VIEW virtual_mailbox_mapping (mailbox, lookup) AS SELECT mailbox.mailbox as mailbox, (CASE WHEN local IS NULL THEN ''' ELSE local END) || '@' || domain AS lookup FROM mailbox_mapping INNER JOIN mailbox on mailbox.id = mailbox_mapping.mailbox;
50
51 CREATE VIEW imap_user ("user", quota_rule) AS SELECT mailbox AS "user", (CASE WHEN quota_bytes IS NULL THEN '*:ignore' ELSE '*:bytes=' || quota_bytes END) AS quota_rule FROM mailbox;
50 COMMIT; 52 COMMIT;
51 ''} 53 ''}
52 ''; 54 '';