nix-config/config/services/forgejo.nix

206 lines
5.7 KiB
Nix
Raw Normal View History

2024-01-12 15:47:43 +01:00
{
config,
2024-12-20 20:40:27 +01:00
globals,
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
...
2024-07-26 22:12:48 +02:00
}:
{
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;
2024-12-20 20:40:27 +01:00
inherit (globals.hetzner) mainUser;
inherit (globals.hetzner.users.forgejo) subUid path;
2024-01-27 23:21:42 +01:00
sshAgeSecret = "forgejoHetznerSsh";
};
2024-07-26 22:12:48 +02:00
paths = [ config.services.forgejo.stateDir ];
2024-08-08 20:08:01 +02:00
#pruneOpts = [
# "--keep-daily 10"
# "--keep-weekly 7"
# "--keep-monthly 12"
# "--keep-yearly 75"
#];
2024-01-27 23:21:42 +01:00
};
};
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-03-14 23:08:42 +01:00
2024-07-26 22:12:48 +02:00
users.groups.git = { };
2024-04-13 19:17:41 +02:00
users.users.git = {
isSystemUser = true;
useDefaultShell = true;
group = "git";
home = config.services.forgejo.stateDir;
};
2024-12-20 20:40:27 +01:00
wireguard.services = {
client.via = "nucnix";
firewallRuleForNode.nucnix-nginx.allowedTCPPorts = [
2024-07-26 22:12:48 +02:00
config.services.forgejo.settings.server.HTTP_PORT
];
2024-03-14 23:08:42 +01:00
};
2024-07-26 22:12:48 +02:00
networking.firewall.allowedTCPPorts = [ config.services.forgejo.settings.server.SSH_PORT ];
2024-01-12 15:47:43 +01:00
environment.persistence."/panzer".directories = [
{
directory = config.services.forgejo.stateDir;
2024-04-13 19:17:41 +02:00
user = "git";
group = "git";
2024-01-12 15:47:43 +01:00
mode = "0700";
}
];
2024-12-07 15:06:07 +01:00
age.secrets.mailnix-passwd = {
2024-07-27 19:48:49 +02:00
generator.script = "alnum";
2024-04-13 19:17:41 +02:00
group = "git";
2024-07-27 19:48:49 +02:00
};
2024-12-07 15:06:07 +01:00
age.secrets.mailnix-passwd-hash = {
generator.dependencies = [ config.age.secrets.mailnix-passwd ];
generator.script = "argon2id";
mode = "440";
intermediary = true;
};
nodes.mailnix = {
age.secrets.idmail-forgejo-passwd-hash = {
inherit (config.age.secrets.mailnix-passwd-hash) rekeyFile;
group = "stalwart-mail";
mode = "440";
2024-07-27 19:48:49 +02:00
};
2024-12-20 20:40:27 +01:00
services.idmail.provision.mailboxes."forge@${globals.domains.mail_public}" = {
2024-12-07 15:06:07 +01:00
password_hash = "%{file:${nodes.mailnix.config.age.secrets.idmail-forgejo-passwd-hash.path}}%";
owner = "admin";
2024-07-27 19:48:49 +02:00
};
2024-01-12 15:47:43 +01:00
};
services.forgejo = {
2024-01-12 15:47:43 +01:00
enable = true;
# TODO db backups
# dump.enable = true;
2024-04-13 19:17:41 +02:00
user = "git";
group = "git";
2024-01-12 15:47:43 +01:00
lfs.enable = true;
2024-12-07 15:06:07 +01:00
secrets.mailer.PASSWD = config.age.secrets.mailnix-passwd.path;
2024-01-12 15:47:43 +01:00
settings = {
2024-07-27 19:48:49 +02:00
DEFAULT.APP_NAME = "Patricks tolles git";
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
};
2024-06-17 21:06:07 +02:00
indexer = {
REPO_INDEXER_ENABLED = true;
};
2024-01-12 15:47:43 +01:00
# federation.ENABLED = true;
mailer = {
ENABLED = true;
2024-12-20 20:40:27 +01:00
SMTP_ADDR = "smtp.${globals.domains.mail_public}";
FROM = "forge@${globals.domains.mail_public}";
USER = "forge@${globals.domains.mail_public}";
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;
2024-12-20 20:40:27 +01:00
DOMAIN = globals.services.forgejo.domain;
ROOT_URL = "https://${globals.services.forgejo.domain}/";
2024-01-12 15:47:43 +01:00
LANDING_PAGE = "login";
SSH_PORT = 9922;
};
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-03-19 00:46:35 +01:00
serviceConfig.RestartSec = "60"; # Retry every minute
2024-07-26 22:12:48 +02:00
preStart =
let
exe = lib.getExe config.services.forgejo.package;
providerName = "kanidm";
clientId = "forgejo";
args = lib.escapeShellArgs [
"--name"
providerName
"--provider"
"openidConnect"
"--key"
clientId
"--auto-discover-url"
2024-12-20 20:40:27 +01:00
"https://auth.${globals.domains.web}/oauth2/openid/${clientId}/.well-known/openid-configuration"
2024-07-26 22:12:48 +02:00
"--scopes"
"email"
"--scopes"
"profile"
"--group-claim-name"
"groups"
"--admin-group"
"admin"
"--skip-local-2fa"
];
in
2024-03-02 19:40:00 +01:00
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
};
}