mirror of
https://gitlab.com/simple-nixos-mailserver/nixos-mailserver.git
synced 2024-11-11 19:39:16 +05:00
Qualify user names
This commit is contained in:
parent
bbca0bd678
commit
f372754052
@ -35,6 +35,7 @@ in
|
||||
extraDomains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
example = "[ example.com ]";
|
||||
default = [];
|
||||
description = "Extra domains that this mail server serves.";
|
||||
};
|
||||
|
||||
|
@ -14,10 +14,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
{ config }:
|
||||
{ config, lib }:
|
||||
|
||||
let
|
||||
cfg = config.mailserver;
|
||||
inherit (lib.strings) stringToCharacters;
|
||||
in
|
||||
{
|
||||
# cert :: PATH
|
||||
@ -37,4 +38,10 @@ in
|
||||
else if cfg.certificateScheme == 3
|
||||
then "/var/lib/acme/mailserver/key.pem"
|
||||
else throw "Error: Certificate Scheme must be in { 1, 2, 3 }";
|
||||
|
||||
# appends cfg.domain to argument if it does not contain "@"
|
||||
qualifyUser = user: (
|
||||
if (builtins.any (c: c == "@") (stringToCharacters user))
|
||||
then user
|
||||
else "${user}@${cfg.domain}");
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
with (import ./common.nix { inherit config; });
|
||||
with (import ./common.nix { inherit config lib; });
|
||||
|
||||
let
|
||||
cfg = config.mailserver;
|
||||
|
@ -26,11 +26,11 @@ let
|
||||
acmeRoot = "/var/lib/acme/acme-challenge";
|
||||
in
|
||||
{
|
||||
config = with cfg; lib.mkIf (certificateScheme == 3) {
|
||||
config = lib.mkIf (cfg.certificateScheme == 3) {
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
virtualHosts = genAttrs allDomains (domain: {
|
||||
serverName = "${hostPrefix}.${domain}";
|
||||
virtualHosts = genAttrs (map (domain: "${cfg.hostPrefix}.${domain}") allDomains) (domain: {
|
||||
serverName = "${domain}";
|
||||
forceSSL = true;
|
||||
enableACME = true;
|
||||
locations."/" = {
|
||||
@ -40,11 +40,8 @@ in
|
||||
});
|
||||
};
|
||||
security.acme.certs."mailserver" = {
|
||||
# @todo what user/group should this run as?
|
||||
user = "postfix"; # cfg.user;
|
||||
group = "postfix"; # lib.mkDefault cfg.group;
|
||||
domain = "${hostPrefix}.${domain}";
|
||||
extraDomains = map (domain: "${hostPrefix}.${domain}") extraDomains;
|
||||
domain = "${cfg.hostPrefix}.${cfg.domain}";
|
||||
extraDomains = genAttrs (map (domain: "${cfg.hostPrefix}.${domain}") cfg.extraDomains) (domain: null);
|
||||
webroot = acmeRoot;
|
||||
# @todo should we reload postfix here?
|
||||
postRun = ''
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
with (import ./common.nix { inherit config; });
|
||||
with (import ./common.nix { inherit config lib; });
|
||||
|
||||
let
|
||||
inherit (lib.strings) concatStringsSep;
|
||||
@ -27,11 +27,11 @@ let
|
||||
valiases_postfix = map
|
||||
(from:
|
||||
let to = cfg.virtualAliases.${from};
|
||||
in "${from} ${to}")
|
||||
in "${qualifyUser from} ${qualifyUser to}")
|
||||
(builtins.attrNames cfg.virtualAliases);
|
||||
|
||||
# accountToIdentity :: User -> String
|
||||
accountToIdentity = account: "${account.name} ${account.name}";
|
||||
accountToIdentity = account: "${qualifyUser account.name} ${qualifyUser account.name}";
|
||||
|
||||
# vaccounts_identity :: [ String ]
|
||||
vaccounts_identity = map accountToIdentity (lib.attrValues cfg.loginAccounts);
|
||||
|
@ -19,6 +19,8 @@
|
||||
with config.mailserver;
|
||||
|
||||
let
|
||||
qualifyUser = (import ./common.nix { inherit config lib; }).qualifyUser;
|
||||
|
||||
vmail_user = {
|
||||
name = vmailUserName;
|
||||
isNormalUser = false;
|
||||
@ -30,14 +32,14 @@ let
|
||||
|
||||
# accountsToUser :: String -> UserRecord
|
||||
accountsToUser = account: {
|
||||
name = account.name;
|
||||
name = (qualifyUser account.name);
|
||||
isNormalUser = false;
|
||||
group = vmailGroupName;
|
||||
inherit (account) hashedPassword;
|
||||
};
|
||||
|
||||
# mail_users :: { [String]: UserRecord }
|
||||
mail_users = lib.foldl (prev: next: prev // { "${next.name}" = next; }) {}
|
||||
mail_users = lib.foldl (prev: next: prev // { "${qualifyUser next.name}" = next; }) {}
|
||||
(map accountsToUser (lib.attrValues loginAccounts));
|
||||
|
||||
in
|
||||
|
@ -15,18 +15,18 @@
|
||||
|
||||
hostPrefix = "mail";
|
||||
loginAccounts = {
|
||||
"user1@example.com" = {
|
||||
"user1" = {
|
||||
hashedPassword = "$6$/z4n8AQl6K$kiOkBTWlZfBd7PvF5GsJ8PmPgdZsFGN1jPGZufxxr60PoR0oUsrvzm2oQiflyz5ir9fFJ.d/zKm/NgLXNUsNX/";
|
||||
};
|
||||
};
|
||||
virtualAliases = {
|
||||
"user1@example2.com" = "user1@example.com";
|
||||
"info@example.com" = "user1@example.com";
|
||||
"postmaster@example.com" = "user1@example.com";
|
||||
"abuse@example.com" = "user1@example.com";
|
||||
"info@example2.com" = "user1@example.com";
|
||||
"postmaster@example2.com" = "user1@example.com";
|
||||
"abuse@example2.com" = "user1@example.com";
|
||||
"info" = "user1";
|
||||
"postmaster" = "user1";
|
||||
"abuse" = "user1";
|
||||
"user1@example2.com" = "user1";
|
||||
"info@example2.com" = "user1";
|
||||
"postmaster@example2.com" = "user1";
|
||||
"abuse@example2.com" = "user1";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user