{ pkgs, ... }:

{
  services.postgresql = {
    enable = true;
    identMap = ''
      # ArbitraryMapName systemUser DBUser
         superuser_map      root      postgres
         superuser_map      postgres  postgres
         # Let other names login as themselves
         superuser_map      /^(.*)$   \1
    '';
    authentication = pkgs.lib.mkOverride 10 ''
      local all  postgres     peer        map=superuser_map
      local sameuser all trust
      host  all      all     127.0.0.1/32   trust
      host all       all     ::1/128        trust
    '';
  };
}