diff --git a/lib/generators.nix b/lib/generators.nix index 551241e..735ae32 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -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: @@ -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 diff --git a/modules/services/dovecot.nix b/modules/services/dovecot.nix index b760cc6..8c9a3b0 100644 --- a/modules/services/dovecot.nix +++ b/modules/services/dovecot.nix @@ -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.` 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."; }; }; }; @@ -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"; - }; - }; }; }; @@ -195,7 +148,7 @@ in }; ensureSomething.link."config" = lib.mkDefault { - src = cfg.config; + src = cfg.configFile; dst = "/etc/dovecot/dovecot.conf"; persistent = false; }; diff --git a/modules/services/postfix.nix b/modules/services/postfix.nix index aa38f24..7b6bad2 100644 --- a/modules/services/postfix.nix +++ b/modules/services/postfix.nix @@ -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; @@ -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 = @@ -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"; @@ -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 { @@ -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" <