{ lib, config, pkgs, ... }:
with lib;
let
  cfgBase = config.base;
  cfg = config.services.ppForgejoRunner;
in
{
  options.services.ppForgejoRunner = {
    forgeUrl = mkOption {
      type = types.str;
      default = "git.${cfgBase.domainName}";
      example = "git.example.com";
      description = "The domain of the forgejo server";
    };
    runnerName = mkOption {
      type = types.str;
      default = "${cfgBase.name}.${cfgBase.domainName}";
      example = "git-runner.example.com";
      description = "The name of the runner";
    };
    tokenFile = mkOption {
      type = types.str;
      default = "/etc/forgejo_db_pwd";
      description = "The file containing the token to access forgejo. Be sure to secure it. The content of the file must be of the form TOKEN=<token>";
    };
  };

  config = {
    virtualisation.podman.enable = true;
    services.gitea-actions-runner.package = pkgs.forgejo-actions-runner;
    services.gitea-actions-runner.instances."${cfg.runnerName}" = {
      enable = true;
      name = cfg.runnerName;
      url = cfg.forgeUrl;
      tokenFile = cfg.tokenFile;
      labels = [
        "debian:docker://debian:bookworm"
      ];
    };
  };
}