complete-computing-environment/gitea.org

2.0 KiB

Gitea on NixOS

{ config, ... }:

let cfg = config.services.gitea;
in {
  services.postgresql.ensureDatabases = ["gitea"];
  services.postgresql.ensureUsers = [
    {
      name = "gitea";
      ensurePermissions = {
        "DATABASE gitea" = "ALL PRIVILEGES";
      };
    }
  ];

  networking.firewall.allowedTCPPorts = [ 2222 ];

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

    domain = "code.rix.si";
    rootUrl = "https://code.rix.si";

    httpAddress = "127.0.0.1";
    httpPort = 3009;

    settings = {
      server = {
        DISABLE_REGISTRATION = true;
        START_SSH_SERVER = true;
        SSH_LISTEN_PORT = 2222;
        SSH_PORT = 2222;
        ENABLE_GZIP = true;
        LANDING_PAGE = "explore";
      };
      ui.DEFAULT_THEME = "arc-green";
      session.COOKIE_SECURE = true;
      federation.ENABLED = true;
      metrics.ENABLED = true;
      packages.ENABLED = false;
      picture.ENABLE_FEDERATED_AVATAR = true;
      time.DEFAULT_UI_LOCATION = config.time.timeZone;
    };

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

  services.prometheus.scrapeConfigs = [
    {
      job_name = "gitea";
      static_configs = [{ targets = ["${cfg.httpAddress}:${toString cfg.httpPort}"]; }];
    }
  ];

  services.nginx.virtualHosts."code.rix.si" = {
    locations."/" = {
      proxyPass = "http://${cfg.httpAddress}:${toString cfg.httpPort}";
      extraConfig = ''
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
      '';
    };
  };
}