infra/hosts/git/forgejo.nix
2026-07-31 19:54:44 +02:00

98 lines
2.4 KiB
Nix

{
lib,
config,
pkgs,
...
}:
let
fqdn = "git.${config.networking.domain}";
in
{
imports = [
../../services/nginx.nix
../../services/prometheus-nginx.nix
];
services = {
forgejo = {
enable = true;
package = pkgs.forgejo;
secrets = {
security = {
SECRET_KEY = lib.mkDefault config.age.secrets.forgejo-secret-key.path;
INTERNAL_TOKEN = lib.mkDefault config.age.secrets.forgejo-internal-token.path;
};
};
settings = {
security.GLOBAL_TWO_FACTOR_REQUIREMENT = "all";
session.COOKIE_SECURE = true;
log.LEVEL = "Warn";
server = {
DOMAIN = fqdn;
PROTOCOL = "http+unix";
ROOT_URL = "https://${fqdn}:443";
};
mailer = {
ENABLED = true;
FROM = "admin@berlin.ccc.de";
PROTOCOL = "sendmail";
SENDMAIL_PATH = "${pkgs.msmtp}/bin/msmtp";
SENDMAIL_ARGS = "--";
};
};
lfs.enable = true;
dump = {
enable = true;
type = "tar.zst";
interval = "daily";
};
database = {
createDatabase = false;
host = "sql.${config.networking.domain}";
name = "git";
passwordFile = config.age.secrets.postgresql-forgejo.path;
port = 5432;
user = "git";
type = "postgres";
};
};
#openssh.extraConfig = ''
# Match User git
# AcceptEnv GIT_PROTOCOL
# PerSourcePenalties no
#'';
nginx.virtualHosts."${fqdn}" = {
quic = true;
kTLS = true;
forceSSL = true;
enableACME = true;
extraConfig = ''
merge_slashes off; # Required to handle URL-encoded slashes
'';
locations = {
"/" = {
recommendedProxySettings = true;
proxyWebsockets = true;
proxyPass = "http://unix:${config.services.forgejo.settings.server.HTTP_ADDR}";
extraConfig = ''
client_max_body_size 512M;
'';
};
"/metrics" = {
recommendedProxySettings = true;
proxyPass = "http://unix:${config.services.forgejo.settings.server.HTTP_ADDR}";
extraConfig = ''
allow 195.160.173.14;
allow 2001:678:760:cccb::14;
deny all;
'';
};
};
};
};
security.acme.certs."${fqdn}".reloadServices = [ "nginx" ];
}