Some checks failed
nixos / nixos (push) Failing after 57s
Forgejo's INTERNAL_TOKEN, JWT_SECRET and LFS_JWT_SECRET sat in the old repository history for a year; Grafana ran on its public default secret_key. New values, generated by Forgejo and openssl, straight into sops. SECRET_KEY stays: changing it would break 2FA. sops-nix does not restart anything when a secret changes. The secrets now name the unit that reads them (Forgejo, Grafana, postgres-roles, garage-bootstrap), so a changed value takes effect on the deploy. Assisted-by: Claude:opus-5-5
139 lines
4.4 KiB
Nix
139 lines
4.4 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;
|
|
restartUnits = [ "forgejo.service" ]; # a changed secret takes effect
|
|
});
|
|
|
|
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'"''
|
|
];
|
|
}
|