{ pkgs, lib, config, ... }: let inherit (lib) types; inherit (pkgs.lib) unlinesAttrs unwords; inherit (config) networking; inherit (config.services) postfix; in { options.services.postfix = { aliases = lib.mkOption { type = with types; attrsOf (listOf str); default = {}; example = { "root@${networking.domain}" = [ "user1@${networking.domain}" "user2@${networking.domain}" ]; "@example.coop" = ["user1@${networking.domain}"]; }; }; }; config = lib.mkIf postfix.enable { services.postfix = { mapFiles."virtual_alias_maps" = pkgs.writeText "virtual_alias_maps" (unlinesAttrs (from: to: "${from} ${unwords to}") postfix.aliases); config = { virtual_alias_maps = [ "hash:/etc/postfix/virtual_alias_maps" ]; }; }; }; }