{ config, lib, ... }:

with lib;

let
  cfg = config.settings.containers.forgejo;
in {
  options = {
    settings.containers.forgejo.enable = lib.mkOption {
      type = lib.types.bool;
      default = false;
      description = ''
        Enable forgejo container
      '';
    };
  };

  config = mkIf cfg.enable {
    services.podman.containers.forgejo = {
      image = "codeberg.org/forgejo/forgejo:11";
      network = "proxy";
      volumes = [
        "%h/containers/forgejo/data:/data" 
      ];
      environment = {
        FORGEJO__service__ALLOW_ONLY_EXTERNAL_REGISTRATION = true;
        FORGEJO__service__SHOW_REGISTRATION_BUTTON = false;
        FORGEJO__service__ENABLE_PASSWORD_SIGNIN_FORM = false;
      };
    };

    settings.containers.caddy.routes.tbmrs.routes.forgejo = {
      host = "git";
      url = "forgejo:3000"; 
    };
  };
}
