From 885edd78d67656f6f3aee02e6457d9290075638e Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Wed, 5 Oct 2016 21:11:40 +0300 Subject: postgresql: refactor keyrings code Several instances can run as the same user. --- modules/apps/postgresql/default.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'modules/apps/postgresql') diff --git a/modules/apps/postgresql/default.nix b/modules/apps/postgresql/default.nix index 847fc75..bfbf4bd 100644 --- a/modules/apps/postgresql/default.nix +++ b/modules/apps/postgresql/default.nix @@ -5,9 +5,9 @@ let match toString ; inherit (lib) - concatMapStrings concatStringsSep filter filterAttrs foldl hasPrefix - isBool isInt isList isString length mapAttrs' mapAttrsToList mkDefault - mkIf mkOption nameValuePair types ; + concatMapStrings concatStringsSep filter filterAttrs foldAttrs foldl + hasPrefix isBool isInt isList isString length mapAttrs' mapAttrsToList + mkDefault mkIf mkOption nameValuePair types ; inherit (types) attrsOf lines listOf nullOr package path str submodule ; @@ -19,10 +19,13 @@ let users = mapAttrsToList (_: v: v.user) instances; isFloat = x: match "^[0-9]+(\\.[0-9]+)?$" (toString x) != null; - isKey = s: s != null && hasPrefix "/run/keys/" s; - keyrings = mapAttrs' (_: i: nameValuePair "${i.user}" [ i.server.ssl_key_file ] - ) (filterAttrs (_: i: isKey i.server.ssl_key_file) instances); + keyrings = + let + isKey = s: s != null && hasPrefix "/run/keys/" s; + keys = i: filter isKey [ i.server.ssl_key_file ]; + ik = mapAttrsToList (_: i: { "${i.user}" = keys i; } ) instances; + in foldAttrs (l: r: l ++ r) [] ik; mkService = name: opts: let -- cgit v1.2.3