nix-config/modules/services/forgejo.nix

171 lines
4.9 KiB
Nix
Raw Normal View History

2024-01-12 15:47:43 +01:00
{
config,
nodes,
2024-01-12 15:47:43 +01:00
pkgs,
2024-03-02 19:40:00 +01:00
lib,
2024-01-12 15:47:43 +01:00
...
}: let
forgejoDomain = "git.${config.secrets.secrets.global.domains.web}";
2024-01-12 15:47:43 +01:00
in {
2024-01-27 23:21:42 +01:00
age.secrets.resticpasswd = {
generator.script = "alnum";
};
age.secrets.forgejoHetznerSsh = {
generator.script = "ssh-ed25519";
};
services.restic.backups = {
main = {
user = "root";
timerConfig = {
OnCalendar = "06:00";
Persistent = true;
RandomizedDelaySec = "3h";
};
initialize = true;
passwordFile = config.age.secrets.resticpasswd.path;
hetznerStorageBox = {
enable = true;
inherit (config.secrets.secrets.global.hetzner) mainUser;
inherit (config.secrets.secrets.global.hetzner.users.forgejo) subUid path;
sshAgeSecret = "forgejoHetznerSsh";
};
paths = [config.services.forgejo.stateDir];
2024-01-27 23:21:42 +01:00
pruneOpts = [
"--keep-daily 10"
"--keep-weekly 7"
"--keep-monthly 12"
"--keep-yearly 75"
];
};
};
2024-01-12 15:47:43 +01:00
# Recommended by forgejo: https://forgejo.org/docs/latest/admin/recommendations/#git-over-ssh
services.openssh.settings.AcceptEnv = "GIT_PROTOCOL";
2024-01-13 19:23:51 +01:00
networking.firewall.allowedTCPPorts = [3000 9922];
2024-01-12 15:47:43 +01:00
environment.persistence."/panzer".directories = [
{
directory = config.services.forgejo.stateDir;
user = "forgejo";
group = "forgejo";
2024-01-12 15:47:43 +01:00
mode = "0700";
}
];
age.secrets.forgejo-mailer-passwd = {
rekeyFile = config.node.secretsDir + "/forgejo-passwd.age";
owner = "forgejo";
group = "forgejo";
2024-01-12 15:47:43 +01:00
mode = "0700";
};
services.forgejo = {
2024-01-12 15:47:43 +01:00
enable = true;
# TODO db backups
# dump.enable = true;
lfs.enable = true;
mailerPasswordFile = config.age.secrets.forgejo-mailer-passwd.path;
2024-01-12 15:47:43 +01:00
settings = {
DEFAULT.APP_NAME = "Patricks tolles git"; # tungsten inert gas?
2024-01-12 15:47:43 +01:00
actions = {
ENABLED = true;
DEFAULT_ACTIONS_URL = "github";
};
database = {
SQLITE_JOURNAL_MODE = "WAL";
LOG_SQL = false; # Leaks secrets
};
# federation.ENABLED = true;
mailer = {
ENABLED = true;
SMTP_ADDR = config.secrets.secrets.local.forgejo.mail.host;
FROM = config.secrets.secrets.local.forgejo.mail.from;
USER = config.secrets.secrets.local.forgejo.mail.user;
2024-01-12 15:47:43 +01:00
SEND_AS_PLAIN_TEXT = true;
};
2024-03-02 19:40:00 +01:00
oauth2_client = {
2024-03-04 21:10:01 +01:00
ACCOUNT_LINKING = "login";
ENABLE_AUTO_REGISTRATION = false;
2024-03-02 19:40:00 +01:00
REGISTER_EMAIL_CONFIRM = false;
UPDATE_AVATAR = true;
USERNAME = "nickname";
2024-03-02 19:40:00 +01:00
};
2024-01-12 15:47:43 +01:00
# packages.ENABLED = true;
repository = {
DEFAULT_PRIVATE = "private";
ENABLE_PUSH_CREATE_USER = true;
ENABLE_PUSH_CREATE_ORG = true;
};
server = {
HTTP_ADDR = "0.0.0.0";
HTTP_PORT = 3000;
DOMAIN = forgejoDomain;
ROOT_URL = "https://${forgejoDomain}/";
2024-01-12 15:47:43 +01:00
LANDING_PAGE = "login";
SSH_PORT = 9922;
# TODO
# port forwarding in fritz box
# port forwarding in elisabeth
};
service = {
DISABLE_REGISTRATION = false;
2024-03-05 00:34:50 +01:00
ALLOW_ONLY_EXTERNAL_REGISTRATION = true;
SHOW_REGISTRATION_BUTTON = false;
2024-01-12 15:47:43 +01:00
REGISTER_EMAIL_CONFIRM = false;
ENABLE_NOTIFY_MAIL = true;
DEFAULT_KEEP_EMAIL_PRIVATE = true;
};
session.COOKIE_SECURE = true;
2024-01-14 02:20:01 +01:00
ui.DEFAULT_THEME = "forgejo-dark";
2024-01-12 15:47:43 +01:00
"ui.meta" = {
AUTHOR = "Patrick";
DESCRIPTION = "Tollstes Forgejo EU-West";
};
};
};
2024-03-02 19:40:00 +01:00
# XXX: PKCE is currently not supported by gitea/forgejo,
# see https://github.com/go-gitea/gitea/issues/21376.
systemd.services.forgejo = {
2024-01-12 15:47:43 +01:00
serviceConfig.RestartSec = "600"; # Retry every 10 minutes
2024-03-02 19:40:00 +01:00
preStart = let
exe = lib.getExe config.services.forgejo.package;
providerName = "kanidm";
2024-03-02 19:40:00 +01:00
clientId = "forgejo";
args = lib.escapeShellArgs [
"--name"
providerName
"--provider"
"openidConnect"
"--key"
clientId
"--auto-discover-url"
2024-03-05 00:34:50 +01:00
"https://auth.${config.secrets.secrets.global.domains.web}/oauth2/openid/${clientId}/.well-known/openid-configuration"
2024-03-04 21:10:01 +01:00
"--scopes"
"email"
"--scopes"
"profile"
2024-03-02 19:40:00 +01:00
"--group-claim-name"
"groups"
"--admin-group"
"admin"
2024-03-02 19:40:00 +01:00
"--skip-local-2fa"
];
in
lib.mkAfter ''
provider_id=$(${exe} admin auth list | ${pkgs.gnugrep}/bin/grep -w '${providerName}' | cut -f1)
2024-03-02 22:26:12 +01:00
SECRET="$(< ${config.age.secrets.openid-secret.path})"
2024-03-02 19:40:00 +01:00
if [[ -z "$provider_id" ]]; then
2024-03-02 22:26:12 +01:00
${exe} admin auth add-oauth ${args} --secret "$SECRET"
2024-03-02 19:40:00 +01:00
else
2024-03-02 22:26:12 +01:00
${exe} admin auth update-oauth --id "$provider_id" ${args} --secret "$SECRET"
2024-03-02 19:40:00 +01:00
fi
'';
};
age.secrets.openid-secret = {
inherit (nodes.elisabeth-kanidm.config.age.secrets.oauth2-forgejo) rekeyFile;
2024-03-02 19:40:00 +01:00
mode = "440";
inherit (config.services.forgejo) group;
2024-01-12 15:47:43 +01:00
};
}