system/machines/magenta/services/gitea.nix
2023-03-03 13:58:47 +03:00

132 lines
3.6 KiB
Nix

{ config, pkgs, lib, ... }:
let
hostname = "git.pleshevski.ru";
giteaCfg = config.services.gitea;
robotsTxt = pkgs.writeText "robots.txt" ''
User-agent: *
Disallow: /github
'';
in
{
services.postgresql.package = pkgs.postgresql_14;
services.gitea = {
enable = true;
httpPort = 9901;
domain = hostname;
rootUrl = "https://${hostname}";
appName = "Pleshevskiy Git Repositories";
mailerPasswordFile = config.age.secrets.gitea-mailserver-passfile.path;
database = {
type = "postgres";
host = "/run/postgresql";
port = config.services.postgresql.port;
};
lfs.enable = true;
settings = {
log = {
LEVEL = "Info";
ENABLE_SSH_LOG = true;
};
database = {
CHARSET = "utf8";
LOG_SQL = false;
};
server = {
LANDING_PAGE = "explore";
};
service = {
ALLOW_ONLY_EXTERNAL_REGISTRATION = false;
DEFAULT_KEEP_EMAIL_PRIVATE = false;
DEFAULT_ALLOW_CREATE_ORGANIZATION = true;
DEFAULT_ENABLE_TIMETRACKING = true;
DEFAULT_ENABLE_DEPENDENCIES = false;
DISABLE_REGISTRATION = true;
ENABLE_NOTIFY_MAIL = false;
ENABLE_CAPTCHA = false;
ENABLE_TIMETRACKING = false;
REQUIRE_SIGNIN_VIEW = false;
REGISTER_EMAIL_CONFIRM = false;
NO_REPLY_ADDRESS = "noreply.pleshevski.ru";
};
repository = {
DISABLE_MIGRATIONS = false;
DISABLE_HTTP_GIT = false;
DISABLE_STARS = true;
DEFAULT_BRANCH = "main";
DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH = true;
};
"repository.local" = {
LOCAL_COPY_PATH = "${giteaCfg.stateDir}/tmp/local-repo";
};
"repository.upload" = {
TEMP_PATH = "${giteaCfg.stateDir}/uploads";
ALLOWED_TYPES = "image/*";
};
"repository.pull-request" = {
WORK_IN_PROGRESS_PREFIXES = "Draft:,[Draft]:,WIP:,[WIP]:";
};
indexer = {
ISSUE_INDEXER_PATH = "${giteaCfg.stateDir}/indexers/issues.bleve";
};
sessions = {
PROVIDER = "file";
PROVIDER_CONFIG = "${giteaCfg.stateDir}/sessions";
};
picture = {
AVATAR_UPLOAD_PATH = "${giteaCfg.stateDir}/avatars";
REPOSITORY_AVATAR_UPLOAD_PATH = "${giteaCfg.stateDir}/repo-avatars";
DISABLE_GRAVATAR = false;
ENABLE_FEDERATED_AVATAR = true;
};
attachment = {
PATH = "${giteaCfg.stateDir}/attachments";
};
mailer = {
ENABLED = true;
MAILER_TYPE = "smtp";
FROM = "\"${giteaCfg.appName}\" <no-reply@pleshevski.ru>";
USER = "dmitriy@pleshevski.ru";
HOST = "mail.pleshevski.ru:465";
};
openid = {
ENABLE_OPENID_SIGNIN = true;
ENABLE_OPENID_SIGNUP = false;
};
};
};
systemd.services.gitea.preStart = lib.mkAfter ''
cp -f ${robotsTxt} ${giteaCfg.stateDir}/custom/robots.txt
'';
services.nginx.virtualHosts.${hostname} = {
enableACME = true;
forceSSL = true;
locations."/".proxyPass = "http://localhost:${toString giteaCfg.httpPort}/";
};
age.secrets.gitea-mailserver-passfile = {
file = ../../../secrets/mailserver-users-jan-passfile.age;
owner = giteaCfg.user;
group = "gitea";
};
services.fail2ban.jails.gitea = ''
enabled = true
filter = gitea
findtime = 3600
bantime = 900
action = iptables-allports
'';
environment.etc."fail2ban/filter.d/gitea.conf".text = ''
[Definition]
failregex = .*Failed authentication attempt for .* from <HOST>
ignoreregex =
journalmatch = _SYSTEMD_UNIT=gitea.service
'';
}