CCE

Gitea

Contents

NEXT do i need to move this to something else?

doubt i care enough to switch to forgejo, but someday i might...

Gitea on NixOS Configuration

nix:tangle ~/nix/nixos/gitea.nix
{ lib, pkgs, config, ... }:

let cfg = config.services.gitea;
in {
  imports = [
    # ./gitea-ratelimit.nix
  ];

  services.postgresql.ensureDatabases = ["gitea"];
  services.postgresql.ensureUsers = [
    {
      name = "gitea";
      ensureDBOwnership = true;
    }
  ];

  networking.firewall.allowedTCPPorts = [ 2222 ];

  services.gitea = {
    enable = true;
    appName = "rrix's code with a cup of tea";
    stateDir = "/srv/gitea";

    settings = {
      server.DOMAIN = "code.rix.si";
      server.ENABLE_GZIP = true;
      server.HTTP_ADDRESS = "127.0.0.1";
      server.HTTP_PORT = 3009;
      server.LANDING_PAGE = "explore";
      # server.ROOT_URL = "https://code.rix.si";
      server.ROOT_URL = "http://code.rix.si";
      server.SSH_LISTEN_PORT = 2222;
      server.SSH_PORT = 2222;
      server.START_SSH_SERVER = true;
      service.DISABLE_REGISTRATION = true;
      security.REVERSE_PROXY_TRUSTED_PROXIES = "127.0.0.0/8,::1/128,100.85.220.128/32";
      repository.ENABLE_PUSH_CREATE_USER = true;
      repository.DISABLE_DOWNLOAD_SOURCE_ARCHIVES = true;
      federation.ENABLED = true;
      metrics.ENABLED = true;
      packages.ENABLED = false;
      picture.ENABLE_FEDERATED_AVATAR = true;
      session.COOKIE_SECURE = true;
      time.DEFAULT_UI_LOCATION = config.time.timeZone;
      ui.DEFAULT_THEME = "arc-green";
      "repo-archive".ENABLED = false;
    };

    database = {
      socket = "/run/postgresql/";
      type = "postgres";
    };
  };

  services.prometheus.scrapeConfigs = [
    {
      job_name = "gitea";
      static_configs = [{ targets = ["${cfg.settings.server.HTTP_ADDRESS}:${toString cfg.settings.server.HTTP_PORT}"]; }];
    }
  ];

  services.nginx.virtualHosts."code.rix.si".useACMEHost = "fontkeming.fail";
  services.nginx.virtualHosts."code.rix.si".addSSL = true;
  
  services.nginx.virtualHosts."code.rix.si".locations."/".proxyPass = # override option set below for the edge server...
    lib.mkForce "http://${cfg.settings.server.HTTP_ADDRESS}:${toString cfg.settings.server.HTTP_PORT}";
}

See also Limiting expensive to render nginx endpoints.