{
  config,
  pkgs,
  lib,
  ...
}:
let
  inherit (config.machine.postgresql)
    port
    enable
    ;
in
with lib;
mkIf enable {
  services.postgresql = {
    inherit enable;
    settings = {
      inherit port;
    };
    ensureDatabases = [ ];
    enableTCPIP = true;
    authentication = mkOverride 10 ''
      #type database DBuser origin-address auth-method
      local all      all                   trust
      host  all      all    127.0.0.1/32   trust
      host  all      all    ::1/128        trust
      host  all      all    0.0.0.0/0      md5
    '';
  };
}
