Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/generators.nix
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ rec {
''
) value
)
else if isList value && name != "include'" && name != "include_try'" then
else if isList value && name != "!include" && name != "!include_try" then
"${name} = "
+ concatMapStringsSep ", " (
x:
Expand All @@ -162,14 +162,14 @@ rec {
else if isBool x then
if value then "yes" else "no"
else
abort "Unsupported type in Dovecot configuration attrset!"
abort "Unsupported type in Dovecot configuration attrset! ${toString x}"
) value
else if isList value && name == "include'" then
concatMapStringsSep "\n" (x: "include! " + x) value
else if isList value && name == "include_try'" then
concatMapStringsSep "\n" (x: "include_try! " + x) value
else if isList value && name == "!include" then
concatMapStringsSep "\n" (x: "!include " + x) value
else if isList value && name == "!include_try" then
concatMapStringsSep "\n" (x: "!include_try " + x) value
else
abort "Unsupported type in Dovecot configuration attrset!"
abort "Unsupported type in Dovecot configuration attrset! ${name} = ${toString value}"
) cfg
)
else
Expand Down
61 changes: 7 additions & 54 deletions modules/services/dovecot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,40 +93,18 @@ in
package
bool
]))
(attrsOf self)
(attrsOf (self // { description = "Dovecot config type"; }))
])
);
in
self // { description = "loop breaker"; };
self;
description = "Dovecot configuration entries in Nix format.";
default = { };
apply = x: pkgs.writeText "dovecot.conf" (nglib.generators.toDovecot x);
};

extConfig = lib.mkOption {
type =
with lib.types;
let
self = attrsOf (
nullOr (oneOf [
str
int
package
bool
(listOf (oneOf [
str
int
package
bool
]))
(attrsOf self)
])
);
in
self // { description = "loop breaker"; };
description = "Extra config files to generate, if you pass in a config attrset, you can access the generated file via the `config.services.dovecot.extConfig.<name>` attribute.";
default = { };
apply = x: lib.mapAttrs (n: v: pkgs.writeText n (nglib.generators.toDovecot v)) x;
configFile = lib.mkOption {
type = lib.types.path;
description = "Dovecot config file.";
};
};
};
Expand Down Expand Up @@ -154,36 +132,11 @@ in
environment.systemPackages = [ cfg.package ];

services.dovecot = {
configFile = lib.mkDefault (pkgs.writeText "dovecot.conf" (nglib.generators.toDovecot cfg.config));
config = {
default_login_user = lib.mkIf (cfg.loginUser != null) cfg.loginUser;
default_internal_user = lib.mkIf (cfg.user != null) cfg.user;
default_internal_group = lib.mkIf (cfg.group != null) cfg.group;

auth_mechanisms = lib.mkDefault "plain";

namespace."inbox" = {
inbox = true;

mailbox."Drafts" = {
special_use = "\\Drafts";
};

mailbox."Junk" = {
special_use = "\\Junk";
};

mailbox."Trash" = {
special_use = "\\Trash";
};

mailbox."Sent" = {
special_use = "\\Sent";
};

mailbox."Sent Messages" = {
special_use = "\\Sent";
};
};
};
};

Expand All @@ -195,7 +148,7 @@ in
};

ensureSomething.link."config" = lib.mkDefault {
src = cfg.config;
src = cfg.configFile;
dst = "/etc/dovecot/dovecot.conf";
persistent = false;
};
Expand Down
54 changes: 43 additions & 11 deletions modules/services/postfix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ in
services.postfix = {
enable = lib.mkEnableOption "Enable Postfix MTA.";

hashMaps = lib.mkOption {
description = "";
type = lib.types.attrsOf (lib.types.attrsOf (lib.types.oneOf [ lib.types.str lib.types.int ]));
default = {};
};

package = lib.mkOption {
description = "Postfix package.";
type = lib.types.package;
Expand All @@ -164,6 +170,12 @@ in
default = "postdrop";
};

stateDirectory = lib.mkOption {
description = "Postfix state directory.";
type = lib.types.path;
default = "/var/lib/postfix";
};

mainConfig = lib.mkOption {
description = "Postfix main.cnf.";
type =
Expand Down Expand Up @@ -235,8 +247,8 @@ in
default_privs = lib.mkDefault "nobody";

# NixOS specific locations
data_directory = lib.mkDefault "/var/lib/postfix/data";
queue_directory = lib.mkDefault "/var/lib/postfix/queue";
data_directory = lib.mkDefault "${cfg.stateDirectory}/data";
queue_directory = lib.mkDefault "${cfg.stateDirectory}/queue";

# Default location of everything in package
meta_directory = "${cfg.package}/etc/postfix";
Expand Down Expand Up @@ -417,11 +429,6 @@ in
let
mainCnf = pkgs.writeText "main.cf" (toMainCnf cfg.mainConfig);
masterCnf = pkgs.writeText "master.cf" cfg.masterConfig;
configDir = pkgs.runCommandNoCCLocal "postfix-config-dir" { } ''
mkdir -p $out
ln -s ${mainCnf} $out/main.cf
ln -s ${masterCnf} $out/master.cf
'';
in
{
ensureSomething.create."data" = lib.mkDefault {
Expand All @@ -441,11 +448,36 @@ in
};

script = pkgs.writeShellScript "postfix-run" ''
echo asd
mkdir -p ${cfg.stateDirectory} ${cfg.mainConfig.queue_directory}/{pid,public,maildrop}
chmod 0755 ${cfg.stateDirectory}
chown root:root ${cfg.stateDirectory}

rm -rf ${cfg.stateDirectory}/conf
mkdir -p ${cfg.stateDirectory}/conf
chmod 0755 ${cfg.stateDirectory}/conf
ln -sf ${pkgs.postfix}/etc/postfix/postfix-files ${cfg.stateDirectory}/conf/postfix-files
ln -sf ${mainCnf} ${cfg.stateDirectory}/conf/main.cf
ln -sf ${masterCnf} ${cfg.stateDirectory}/conf/master.cf

mkdir -p ${cfg.stateDirectory}/conf/hash_maps
${lib.pipe cfg.hashMaps [
(lib.mapAttrsToList (n: v:
''
_map="${cfg.stateDirectory}/conf/hash_maps/${n}"
cat > "$_map" <<EOF
${lib.pipe v [
(lib.mapAttrsToList (n': v': "${n'} ${v'}"))
(lib.concatStringsSep "\n")
]}
EOF
${lib.getExe' cfg.package "postmap"} -c ${cfg.stateDirectory}/conf "$_map"
''
))
(lib.concatStringsSep "\n")
]}

mkdir -p /etc/postfix/
${cfg.package}/bin/postfix -c ${configDir} set-permissions
${cfg.package}/libexec/postfix/master -c ${configDir}
${cfg.package}/bin/postfix -c ${cfg.stateDirectory}/conf set-permissions
exec ${cfg.package}/libexec/postfix/master -c ${cfg.stateDirectory}/conf
'';
enabled = true;
};
Expand Down