about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2016-01-10 05:39:17 +0300
committerNikolay Amiantov <ab@fmap.me>2016-01-12 18:00:54 +0300
commit1edb62b40abb54532d0f8c953409a551d23b35a4 (patch)
tree69fb0948586a636002b725acce347d612de81b4a /nixos
parent9c502abb1cd764b6c0dd3099705273b8e8ef36bf (diff)
downloadnixlib-1edb62b40abb54532d0f8c953409a551d23b35a4.tar
nixlib-1edb62b40abb54532d0f8c953409a551d23b35a4.tar.gz
nixlib-1edb62b40abb54532d0f8c953409a551d23b35a4.tar.bz2
nixlib-1edb62b40abb54532d0f8c953409a551d23b35a4.tar.lz
nixlib-1edb62b40abb54532d0f8c953409a551d23b35a4.tar.xz
nixlib-1edb62b40abb54532d0f8c953409a551d23b35a4.tar.zst
nixlib-1edb62b40abb54532d0f8c953409a551d23b35a4.zip
nixos/postfix: add options to compile additional maps and aliases
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/mail/postfix.nix175
1 files changed, 97 insertions, 78 deletions
diff --git a/nixos/modules/services/mail/postfix.nix b/nixos/modules/services/mail/postfix.nix
index 4d5f9c8c5480..00cabc505cab 100644
--- a/nixos/modules/services/mail/postfix.nix
+++ b/nixos/modules/services/mail/postfix.nix
@@ -356,6 +356,18 @@ in
         description = "Extra lines to append to the generated master.cf file.";
       };
 
+      aliasFiles = mkOption {
+        type = types.attrsOf types.path;
+        default = {};
+        description = "Aliases' tables to be compiled and placed into /var/lib/postfix/conf.";
+      };
+
+      mapFiles = mkOption {
+        type = types.attrsOf types.path;
+        default = {};
+        description = "Maps to be compiled and placed into /var/lib/postfix/conf.";
+      };
+
     };
 
   };
@@ -363,92 +375,99 @@ in
 
   ###### implementation
 
-  config = mkIf config.services.postfix.enable {
+  config = mkIf config.services.postfix.enable (mkMerge [
+    {
 
-    environment = {
-      etc = singleton
-        { source = "/var/lib/postfix/conf";
-          target = "postfix";
-        };
-
-      # This makes comfortable for root to run 'postqueue' for example.
-      systemPackages = [ pkgs.postfix ];
-    };
+      environment = {
+        etc = singleton
+          { source = "/var/lib/postfix/conf";
+            target = "postfix";
+          };
 
-    services.mail.sendmailSetuidWrapper = mkIf config.services.postfix.setSendmail {
-      program = "sendmail";
-      source = "${pkgs.postfix}/bin/sendmail";
-      group = setgidGroup;
-      setuid = false;
-      setgid = true;
-    };
-
-    users.extraUsers = optional (user == "postfix")
-      { name = "postfix";
-        description = "Postfix mail server user";
-        uid = config.ids.uids.postfix;
-        group = group;
+        # This makes comfortable for root to run 'postqueue' for example.
+        systemPackages = [ pkgs.postfix ];
       };
 
-    users.extraGroups =
-      optional (group == "postfix")
-      { name = group;
-        gid = config.ids.gids.postfix;
-      }
-      ++ optional (setgidGroup == "postdrop")
-      { name = setgidGroup;
-        gid = config.ids.gids.postdrop;
+      services.mail.sendmailSetuidWrapper = mkIf config.services.postfix.setSendmail {
+        program = "sendmail";
+        source = "${pkgs.postfix}/bin/sendmail";
+        group = setgidGroup;
+        setuid = false;
+        setgid = true;
       };
 
-    systemd.services.postfix =
-      { description = "Postfix mail server";
-
-        wantedBy = [ "multi-user.target" ];
-        after = [ "network.target" ];
-        path = [ pkgs.postfix ];
-
-        serviceConfig = {
-          Type = "forking";
-          Restart = "always";
-          PIDFile = "/var/lib/postfix/queue/pid/master.pid";
-          ExecStart = "${pkgs.postfix}/bin/postfix -c /etc/postfix start";
-          ExecStop = "${pkgs.postfix}/bin/postfix -c /etc/postfix stop";
-          ExecReload = "${pkgs.postfix}/bin/postfix -c /etc/postfix reload";
+      users.extraUsers = optional (user == "postfix")
+        { name = "postfix";
+          description = "Postfix mail server user";
+          uid = config.ids.uids.postfix;
+          group = group;
         };
 
-        preStart = ''
-          mkdir -p /var/lib/postfix/data /var/lib/postfix/queue/{pid,public,maildrop}
-
-          chown -R ${user}:${group} /var/lib/postfix
-          chown root /var/lib/postfix/queue
-          chown root /var/lib/postfix/queue/pid
-          chgrp -R ${setgidGroup} /var/lib/postfix/queue/{public,maildrop}
-          chmod 770 /var/lib/postfix/queue/{public,maildrop}
-
-          rm -rf /var/lib/postfix/conf
-          mkdir -p /var/lib/postfix/conf
-          ln -sf ${mainCfFile} /var/lib/postfix/conf/main.cf
-          ln -sf ${masterCfFile} /var/lib/postfix/conf/master.cf
-          ${optionalString haveAliases ''
-            ln -sf ${aliasesFile} /var/lib/postfix/conf/aliases
-            postalias /var/lib/postfix/conf/aliases
-          ''}
-          ${optionalString haveTransport ''
-            ${pkgs.coreutils}/bin/ln -sf ${transportFile} /var/lib/postfix/conf/transport
-            ${pkgs.postfix}/bin/postmap /var/lib/postfix/conf/transport
-          ''}
-          ${optionalString haveVirtual ''
-            ln -sf ${virtualFile} /var/lib/postfix/conf/virtual
-            postmap /var/lib/postfix/conf/virtual
-          ''}
-
-          mkdir -p /var/spool/mail
-          chown root:root /var/spool/mail
-          chmod a+rwxt /var/spool/mail
-          ln -sf /var/spool/mail /var/
-        '';
-      };
+      users.extraGroups =
+        optional (group == "postfix")
+        { name = group;
+          gid = config.ids.gids.postfix;
+        }
+        ++ optional (setgidGroup == "postdrop")
+        { name = setgidGroup;
+          gid = config.ids.gids.postdrop;
+        };
 
-  };
+      systemd.services.postfix =
+        { description = "Postfix mail server";
+
+          wantedBy = [ "multi-user.target" ];
+          after = [ "network.target" ];
+          path = [ pkgs.postfix ];
+
+          serviceConfig = {
+            Type = "forking";
+            Restart = "always";
+            PIDFile = "/var/lib/postfix/queue/pid/master.pid";
+            ExecStart = "${pkgs.postfix}/bin/postfix start";
+            ExecStop = "${pkgs.postfix}/bin/postfix stop";
+            ExecReload = "${pkgs.postfix}/bin/postfix reload";
+          };
+
+          preStart = ''
+            mkdir -p /var/lib/postfix/data /var/lib/postfix/queue/{pid,public,maildrop}
+
+            chown -R ${user}:${group} /var/lib/postfix
+            chown root /var/lib/postfix/queue
+            chown root /var/lib/postfix/queue/pid
+            chgrp -R ${setgidGroup} /var/lib/postfix/queue/{public,maildrop}
+            chmod 770 /var/lib/postfix/queue/{public,maildrop}
+
+            rm -rf /var/lib/postfix/conf
+            mkdir -p /var/lib/postfix/conf
+            ln -sf ${mainCfFile} /var/lib/postfix/conf/main.cf
+            ln -sf ${masterCfFile} /var/lib/postfix/conf/master.cf
+            ${concatStringsSep "\n" (mapAttrsToList (to: from: ''
+              ln -sf ${from} /var/lib/postfix/conf/${to}
+              postalias /var/lib/postfix/conf/${to}
+            '') cfg.aliasFiles)}
+            ${concatStringsSep "\n" (mapAttrsToList (to: from: ''
+              ln -sf ${from} /var/lib/postfix/conf/${to}
+              postmap /var/lib/postfix/conf/${to}
+            '') cfg.mapFiles)}
+
+            mkdir -p /var/spool/mail
+            chown root:root /var/spool/mail
+            chmod a+rwxt /var/spool/mail
+            ln -sf /var/spool/mail /var/
+          '';
+        };
+    }
+
+    (mkIf haveAliases {
+      services.postfix.aliasFiles."aliases" = aliasesFile;
+    })
+    (mkIf haveTransport {
+      services.postfix.mapFiles."transport" = transportFile;
+    })
+    (mkIf haveVirtual {
+      services.postfix.mapFiles."virtual" = virtualFile;
+    })
+  ]);
 
 }