iac/nixos/hosts/asxpio-ops/forgejo.nix
Sergei Poljanski 72a14a1b1b
All checks were successful
nixos / nixos (push) Successful in 1m3s
nixos: zsh for every account, security summary on login, XMPP over IPv6
Every account now logs in with zsh, including ones added later, except
deploy and git: the app CI and Forgejo run commands through their login
shells. root gets the same zsh with a red prompt ending in #.

Interactive SSH logins show, under fastfetch, the host's security state
as the Grafana alerts see it, read from the local metrics files:
anything unexpected (peers, devices, accounts, ports, containers),
who is logged in, the last good backup per repository, the bucket
replica, failed units and fail2ban bans.

XMPP gets a Podman network of its own with IPv6. xmpp.asxp.io has an
AAAA record, and Podman's default network forwards published ports over
IPv4 only, where Docker on Debian did both: since the conversion, XMPP
over IPv6 was refused. Tried on the rehearsal host with a published port
on the new network, reached over IPv6 and IPv4.

Assisted-by: Claude:opus-5-5
2026-11-17 07:28:36 +04:00

136 lines
4.3 KiB
Nix

# Forgejo at git.asxp.io (git.czsk.it is an alias), with its package
# registry and Actions. It runs as user git, so git@git.asxp.io reaches
# it through the host's sshd with no passthrough.
#
# State: /var/lib/forgejo (repositories/, data/forgejo.db, data/lfs, ...).
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.forgejo;
secret = name: config.sops.secrets."forgejo/${name}".path;
in
{
sops.secrets = lib.genAttrs (map (n: "forgejo/${n}") [
"secret_key"
"internal_token"
"jwt_secret"
"lfs_jwt_secret"
"smtp_user"
"smtp_password"
"metrics_token"
]) (_: { owner = cfg.user; });
users.users.git = {
isSystemUser = true;
group = "git";
home = cfg.stateDir;
# Forgejo's SSH commands run through it; not the zsh default
shell = pkgs.bashInteractive;
};
users.groups.git = { };
# Anyone may try a key against git; Forgejo decides what it may do
services.openssh.settings.AllowUsers = [ "git" ];
asxpio.security.loginUsers = [ "git" ];
# HTTP for Traefik and, over the private network, for the runners
asxpio.security.ports = [ "tcp/3000/.forgejo-wrappe" ];
asxpio.security.forgejoDb = "${cfg.stateDir}/data/forgejo.db";
services.forgejo = {
enable = true;
package = pkgs.forgejo; # the current release, not the LTS: the data is from 17
user = "git";
group = "git";
database.type = "sqlite3";
lfs.enable = true;
secrets = {
security.SECRET_KEY = lib.mkForce (secret "secret_key");
security.INTERNAL_TOKEN = lib.mkForce (secret "internal_token");
oauth2.JWT_SECRET = lib.mkForce (secret "jwt_secret");
server.LFS_JWT_SECRET = lib.mkForce (secret "lfs_jwt_secret");
mailer.USER = secret "smtp_user";
mailer.PASSWD = secret "smtp_password";
metrics.TOKEN = secret "metrics_token";
};
settings = {
DEFAULT.APP_NAME = "Git with a cup of tea";
server = {
DOMAIN = "git.asxp.io";
ROOT_URL = "https://git.asxp.io/";
HTTP_PORT = 3000;
SSH_DOMAIN = "git.asxp.io";
SSH_PORT = 22;
LANDING_PAGE = "explore";
};
repository = {
DEFAULT_BRANCH = "main";
DEFAULT_PRIVATE = "private";
ENABLE_PUSH_CREATE_USER = true;
ENABLE_PUSH_CREATE_ORG = false;
DEFAULT_REPO_UNITS = "repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages,repo.actions";
};
"repository.pull-request".DEFAULT_MERGE_STYLE = "merge";
"repository.signing".DEFAULT_TRUST_MODEL = "collaborator";
ui = {
THEMES = "forgejo-auto,forgejo-light,forgejo-dark,gitea-auto,gitea-light,gitea-dark";
DEFAULT_THEME = "forgejo-auto";
};
security.PASSWORD_HASH_ALGO = "pbkdf2";
service = {
DISABLE_REGISTRATION = true;
REQUIRE_SIGNIN_VIEW = false;
REGISTER_EMAIL_CONFIRM = false;
ENABLE_NOTIFY_MAIL = true;
DEFAULT_KEEP_EMAIL_PRIVATE = true;
DEFAULT_ALLOW_CREATE_ORGANIZATION = true;
DEFAULT_ENABLE_TIMETRACKING = true;
NO_REPLY_ADDRESS = "noreply.git.asxp.io";
};
oauth2.ENABLED = true;
mailer = {
ENABLED = lib.mkDefault true;
FROM = "Czechoslovakia Git <noreply@asxp.io>";
PROTOCOL = "smtp+starttls";
SMTP_ADDR = "smtp.fastmail.com";
SMTP_PORT = 587;
};
session.PROVIDER = "file";
log.LEVEL = "Info";
actions = {
ENABLED = true;
DEFAULT_ACTIONS_URL = "https://github.com";
ARTIFACT_RETENTION_DAYS = 365;
};
packages.ENABLED = true;
other = {
SHOW_FOOTER_VERSION = false;
SHOW_FOOTER_TEMPLATE_LOAD_TIME = false;
SHOW_FOOTER_POWERED_BY = false;
};
metrics.ENABLED = true;
};
};
asxpio.waitForData = [
"forgejo"
"forgejo-secrets"
];
# `forgejo-admin regenerate keys`, `forgejo-admin user list`, ...
environment.systemPackages = [
(pkgs.writeShellScriptBin "forgejo-admin" ''
exec ${pkgs.util-linux}/bin/runuser -u ${cfg.user} -- env \
HOME=${cfg.stateDir} FORGEJO_WORK_DIR=${cfg.stateDir} FORGEJO_CUSTOM=${cfg.customDir} \
${lib.getExe cfg.package} --config ${cfg.customDir}/conf/app.ini admin "$@"
'')
];
asxpio.backup.paths = [ "/var/lib/forgejo" ];
asxpio.backup.hooks = [
''sqlite3 /var/lib/forgejo/data/forgejo.db ".backup '$STAGE/forgejo.db'"''
];
}