Some more accounts stuff
This commit is contained in:
parent
cd4c06686e
commit
9c4a751fe0
1 changed files with 19 additions and 49 deletions
|
@ -7,21 +7,14 @@
|
||||||
let
|
let
|
||||||
cfg = config.khscodes."mx.kaareskovgaard.net";
|
cfg = config.khscodes."mx.kaareskovgaard.net";
|
||||||
passDbFile = "/run/secret/dovecot/passwd";
|
passDbFile = "/run/secret/dovecot/passwd";
|
||||||
# This just replicates what simple-nixos-mailserver does, but using the proper usernames
|
|
||||||
userDbFile = pkgs.writeTextFile {
|
|
||||||
name = "userdb";
|
|
||||||
text = lib.concatStringsSep "\n" (
|
|
||||||
lib.mapAttrsToList (
|
|
||||||
name: value:
|
|
||||||
"${name}:::::::"
|
|
||||||
+ lib.optionalString (value.quota != null) "userdb_quota_rule=*:storage=${value.quota}"
|
|
||||||
) cfg.accounts
|
|
||||||
);
|
|
||||||
};
|
|
||||||
bogusPasswdFile = pkgs.writeTextFile {
|
bogusPasswdFile = pkgs.writeTextFile {
|
||||||
name = "bogus-passwd";
|
name = "bogus-passwd";
|
||||||
text = "$6$1234";
|
text = "$6$1234";
|
||||||
};
|
};
|
||||||
|
userDbFile = pkgs.writeTextFile {
|
||||||
|
name = "userdb";
|
||||||
|
text = '''';
|
||||||
|
};
|
||||||
accountPrimaryEmail =
|
accountPrimaryEmail =
|
||||||
name: account: if account.isLdapAccount then lib.lists.head account.aliases else name;
|
name: account: if account.isLdapAccount then lib.lists.head account.aliases else name;
|
||||||
accountAlternativeEmails =
|
accountAlternativeEmails =
|
||||||
|
@ -139,7 +132,7 @@ let
|
||||||
|
|
||||||
systemAccounts = lib.attrsets.foldlAttrs (
|
systemAccounts = lib.attrsets.foldlAttrs (
|
||||||
acc: name: value:
|
acc: name: value:
|
||||||
if value.isLdapAccount then acc else acc ++ [ (accountPrimaryEmail name value) ]
|
if value.isLdapAccount then acc else acc ++ [ name ]
|
||||||
) [ ] cfg.accounts;
|
) [ ] cfg.accounts;
|
||||||
|
|
||||||
systemAccountsPassDbTemplateContents =
|
systemAccountsPassDbTemplateContents =
|
||||||
|
@ -152,15 +145,6 @@ let
|
||||||
)
|
)
|
||||||
# Just make sure the file is not empty
|
# Just make sure the file is not empty
|
||||||
+ "\n";
|
+ "\n";
|
||||||
|
|
||||||
data = import ./accounts/mailbox_map.nix {
|
|
||||||
inherit lib accountPrimaryEmail accountAlternativeEmails;
|
|
||||||
accounts = cfg.accounts;
|
|
||||||
extraVirtualAliases = { };
|
|
||||||
};
|
|
||||||
|
|
||||||
mappedFile = name: "hash:/var/lib/postfix/conf/${name}";
|
|
||||||
mappedRegexFile = name: "pcre:/var/lib/postfix/conf/${name}";
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.khscodes."mx.kaareskovgaard.net".accounts = lib.mkOption {
|
options.khscodes."mx.kaareskovgaard.net".accounts = lib.mkOption {
|
||||||
|
@ -169,9 +153,7 @@ in
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
mailserver = {
|
mailserver = {
|
||||||
loginAccounts = lib.attrsets.mapAttrs' (name: value: {
|
loginAccounts = lib.attrsets.mapAttrs (name: value: {
|
||||||
name = accountPrimaryEmail name value;
|
|
||||||
value = {
|
|
||||||
inherit (value)
|
inherit (value)
|
||||||
name
|
name
|
||||||
aliasesRegexp
|
aliasesRegexp
|
||||||
|
@ -180,23 +162,11 @@ in
|
||||||
sieveScript
|
sieveScript
|
||||||
sendOnly
|
sendOnly
|
||||||
sendOnlyRejectMessage
|
sendOnlyRejectMessage
|
||||||
|
aliases
|
||||||
;
|
;
|
||||||
aliases = accountAlternativeEmails name value;
|
|
||||||
hashedPasswordFile = bogusPasswdFile;
|
hashedPasswordFile = bogusPasswdFile;
|
||||||
};
|
|
||||||
}) cfg.accounts;
|
}) cfg.accounts;
|
||||||
extraVirtualAliases = data.mailserverExtraVirtualAliases;
|
extraVirtualAliases = { };
|
||||||
};
|
|
||||||
services.postfix = {
|
|
||||||
mapFiles."valias_maps" = data.valiases_file;
|
|
||||||
mapFiles."regex_valias_maps" = data.regex_valiases_file;
|
|
||||||
mapFiles."vaccounts" = lib.mkForce data.vaccounts_file;
|
|
||||||
mapFiles."regex_vaccounts" = lib.mkForce data.regex_vaccounts_file;
|
|
||||||
config.virtual_mailbox_maps = lib.mkForce [
|
|
||||||
(mappedFile "valias_maps")
|
|
||||||
(mappedRegexFile "regex_valias_maps")
|
|
||||||
];
|
|
||||||
|
|
||||||
};
|
};
|
||||||
khscodes.infrastructure.vault-server-approle.policy = {
|
khscodes.infrastructure.vault-server-approle.policy = {
|
||||||
"mx.kaareskovgaard.net/data/users/*" = {
|
"mx.kaareskovgaard.net/data/users/*" = {
|
||||||
|
@ -258,7 +228,7 @@ in
|
||||||
# with our own.
|
# with our own.
|
||||||
preStart = lib.mkAfter ''
|
preStart = lib.mkAfter ''
|
||||||
cp ${passDbFile} /run/dovecot2/passwd
|
cp ${passDbFile} /run/dovecot2/passwd
|
||||||
cp ${userDbFile} /run/dovecot2/userdb
|
# cp ${userDbFile} /run/dovecot2/userdb
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
# This prevents local usernames without domain names to get rewritten.
|
# This prevents local usernames without domain names to get rewritten.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue