nixos: describe both servers as NixOS systems
Start of the move from Ansible to NixOS. Services run as native NixOS services where nixpkgs has a module and as Podman containers otherwise; there is no Docker. Shared: users with their Debian UIDs, SSH with the Ansible role's crypto settings, nftables firewall, WireGuard (ops is the hub), sops-nix secrets per host, the restic backup script with its schedule and retention, mail on unit failure. asxpio-services: Xray, SillyTavern, Minecraft (Paper) and the ACME forwarder natively; XMPP stays in containers because the server is a custom build. asxpio-ops: Postgres, Garage and Forgejo natively. Roles, buckets, keys and grants move here from the storage repo's init scripts. Services that own data wait for /var/lib/.data-in-place, so an install never creates empty state where a restore is about to land. migration/*-data.sh move the Debian-era data into the new layout. hosts/rehearsal turns the two hosts into a test pair with its own keys and dummy secrets. Everything here ran there, Postgres, Garage, Forgejo, Minecraft and SillyTavern on a restored copy of production data. Three differences from the containers showed up and are handled: Garage rejects a 0440 credential file, Geyser needs libcrypto and netlink, SillyTavern ignores the module's listen flags. Production is untouched: both servers still run Debian under Ansible. Assisted-by: Claude:fable-5-2
This commit is contained in:
parent
c51522d371
commit
be68c5adef
1 changed files with 1981 additions and 0 deletions
131
nixos/hosts/asxpio-ops/forgejo.nix
Normal file
131
nixos/hosts/asxpio-ops/forgejo.nix
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
# 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;
|
||||
useDefaultShell = true;
|
||||
};
|
||||
users.groups.git = { };
|
||||
# Anyone may try a key against git; Forgejo decides what it may do
|
||||
services.openssh.settings.AllowUsers = [ "git" ];
|
||||
|
||||
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'"''
|
||||
];
|
||||
}
|
||||
Loading…
Reference in a new issue