From 91eb6cf82cc7fa2eaa2802f64a15ab75be726fae Mon Sep 17 00:00:00 2001 From: Joerg Thalheim Date: Thu, 28 Sep 2017 10:47:19 +0100 Subject: [PATCH] nullmailer: simplify config generation --- nixos/modules/services/mail/nullmailer.nix | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/nixos/modules/services/mail/nullmailer.nix b/nixos/modules/services/mail/nullmailer.nix index c5af1d4d381..59cb512c115 100644 --- a/nixos/modules/services/mail/nullmailer.nix +++ b/nixos/modules/services/mail/nullmailer.nix @@ -194,18 +194,10 @@ with lib; environment = { systemPackages = [ pkgs.nullmailer ]; etc = let - getval = attr: builtins.getAttr attr cfg.config; - attrs = builtins.attrNames cfg.config; - remotesFilter = if cfg.remotesFile != null - then (attr: attr != "remotes") - else (_: true); - optionalRemotesFileLink = if cfg.remotesFile != null - then { "nullmailer/remotes".source = cfg.remotesFile; } - else {}; - attrs' = builtins.filter (attr: (! isNull (getval attr)) && (remotesFilter attr)) attrs; + validAttrs = filterAttrs (name: value: value != null) cfg.config; in - (foldl' (as: attr: as // { "nullmailer/${attr}".text = getval attr; }) {} attrs') - // optionalRemotesFileLink; + (foldl' (as: name: as // { "nullmailer/${name}".text = validAttrs.${name}; }) {} (attrNames validAttrs)) + // optionalAttrs (cfg.remotesFile != null) { "nullmailer/remotes".source = cfg.remotesFile; }; }; users = {