{
  lib,
  pkgs,
  config,
  ...
}: {
  systemd.services.forgejo = {
    after = ["postgresql.service"];
    requires = ["postgresql.service"];
  };

  services.postgresql = {
    enable = true;
    ensureDatabases = ["forgejo"];
    ensureUsers = [
      {
        name = "forgejo";
        ensureDBOwnership = true;
      }
    ];
    authentication = pkgs.lib.mkOverride 10 ''
      #type database  DBuser  auth-method
      local all       all     trust
    '';
  };

  services.prometheus.exporters.postgres.enable = true;
  services.prometheus.exporters.postgres.openFirewall = true;
}
