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
7 changed files with 1981 additions and 0 deletions
20
nixos/hosts/asxpio-services/acme-forward.nix
Normal file
20
nixos/hosts/asxpio-services/acme-forward.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Let's Encrypt validates xmpp.asxp.io on this host's port 80, but the
|
||||
# certificates are requested by Traefik on asxpio-ops: pass the
|
||||
# challenges on, answer nothing else.
|
||||
{ ... }:
|
||||
{
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
serverTokens = false;
|
||||
virtualHosts.acme-forward = {
|
||||
default = true;
|
||||
extraConfig = "access_log off;";
|
||||
locations."/.well-known/acme-challenge/" = {
|
||||
proxyPass = "http://10.10.0.10";
|
||||
extraConfig = "proxy_set_header Host $host;";
|
||||
};
|
||||
locations."/".return = "404";
|
||||
};
|
||||
};
|
||||
networking.firewall.allowedTCPPorts = [ 80 ];
|
||||
}
|
||||
71
nixos/hosts/asxpio-services/default.nix
Normal file
71
nixos/hosts/asxpio-services/default.nix
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
# asxpio-services: CI runners, Minecraft, XMPP, Xray, SillyTavern.
|
||||
# Services are added here as they move over from ../../ansible (see
|
||||
# MIGRATION.md at the repo root); until then this is the base system only.
|
||||
{ lib, ... }:
|
||||
{
|
||||
imports = [
|
||||
./acme-forward.nix
|
||||
./minecraft.nix
|
||||
./sillytavern.nix
|
||||
./xmpp.nix
|
||||
./xray.nix
|
||||
];
|
||||
|
||||
asxpio.publicIPv4 = lib.mkDefault "46.62.228.216";
|
||||
|
||||
networking.hostName = lib.mkDefault "asxpio-services";
|
||||
networking.domain = "asxp.io";
|
||||
system.stateVersion = "26.05";
|
||||
|
||||
systemd.network.networks."10-public".address = [ "2a01:4f9:c013:8269::1/64" ];
|
||||
# No swap, by choice
|
||||
|
||||
sops.defaultSopsFile = lib.mkDefault ../../secrets/asxpio-services.yaml;
|
||||
|
||||
# --- WireGuard spoke of asxpio-ops ---------------------------------------
|
||||
asxpio.wireguard = {
|
||||
interface = "asxpio-services";
|
||||
address = [
|
||||
"10.20.0.20/32"
|
||||
"fd69:69:69::20/128"
|
||||
];
|
||||
listenPort = 52820;
|
||||
peers = lib.mkDefault [
|
||||
{
|
||||
name = "asxpio-ops";
|
||||
publicKey = "0gRrNiV4FjP6ipczZCRD3dsnK7k7rl6IyjG84fPaJB4=";
|
||||
endpoint = "135.181.27.77:60101";
|
||||
allowedIPs = [
|
||||
"10.20.0.0/24"
|
||||
"fd69:69:69::/64"
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# --- Backup ---------------------------------------------------------------
|
||||
# ejabberd's Mnesia through its own backup command, its SQLite through
|
||||
# the online backup API. The Paper world is copied live (RCON is off, so
|
||||
# there is no save-off); its autosave keeps that close enough.
|
||||
asxpio.backup = {
|
||||
hostName = "asxpio-services";
|
||||
schedule = "*-*-* 04:15:00";
|
||||
paths = [
|
||||
"/etc/ssh" # the host key decrypts this host's secrets
|
||||
"/opt"
|
||||
"/var/lib/minecraft"
|
||||
"/var/lib/SillyTavern"
|
||||
"/var/lib/containers/storage/volumes/xmpp_database"
|
||||
"/var/lib/containers/storage/volumes/xmpp_tackygram"
|
||||
];
|
||||
excludes = [
|
||||
"/var/lib/minecraft/cache"
|
||||
"/var/lib/minecraft/libraries"
|
||||
"/var/lib/minecraft/versions"
|
||||
];
|
||||
hooks = [
|
||||
"podman exec xmpp-ejabberd ejabberdctl backup /opt/ejabberd/database/nightly.backup"
|
||||
''sqlite3 /var/lib/containers/storage/volumes/xmpp_database/_data/ejabberd.sqlite ".backup '$STAGE/ejabberd.sqlite'"''
|
||||
];
|
||||
};
|
||||
}
|
||||
33
nixos/hosts/asxpio-services/minecraft.nix
Normal file
33
nixos/hosts/asxpio-services/minecraft.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Paper. The world, plugins and server.properties are data in
|
||||
# /var/lib/minecraft and not managed here; Geyser (a plugin) adds the
|
||||
# Bedrock port.
|
||||
{ lib, pkgs, ... }:
|
||||
{
|
||||
services.minecraft-server = {
|
||||
enable = true;
|
||||
eula = true;
|
||||
package = pkgs.papermc;
|
||||
jvmOpts = "-Xmx4G -Xms2G";
|
||||
};
|
||||
asxpio.waitForData = [ "minecraft-server" ];
|
||||
systemd.services.minecraft-server = {
|
||||
# Stopping saves the world first
|
||||
serviceConfig.TimeoutStopSec = 120;
|
||||
# Geyser lists the network interfaces (netlink) for Bedrock's
|
||||
# signalling; the module allows IP sockets only
|
||||
serviceConfig.RestrictAddressFamilies = lib.mkForce [
|
||||
"AF_INET"
|
||||
"AF_INET6"
|
||||
"AF_UNIX"
|
||||
"AF_NETLINK"
|
||||
];
|
||||
# Geyser unpacks native libraries that expect a usual Linux around
|
||||
# them (libcrypto, libstdc++)
|
||||
environment.LD_LIBRARY_PATH = lib.makeLibraryPath [
|
||||
pkgs.openssl
|
||||
pkgs.stdenv.cc.cc.lib
|
||||
];
|
||||
};
|
||||
networking.firewall.allowedTCPPorts = [ 25565 ];
|
||||
networking.firewall.allowedUDPPorts = [ 19132 ];
|
||||
}
|
||||
18
nixos/hosts/asxpio-services/sillytavern.nix
Normal file
18
nixos/hosts/asxpio-services/sillytavern.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# SillyTavern, on the WireGuard address only. State: /var/lib/SillyTavern
|
||||
# (data/, extensions/).
|
||||
{ config, unstable, ... }:
|
||||
{
|
||||
services.sillytavern = {
|
||||
enable = true;
|
||||
package = unstable.sillytavern; # 26.05 has 1.18, the data is from 1.19
|
||||
configFile = "${./sillytavern.yaml}";
|
||||
# Port 8000, the WireGuard address and the whitelist (WireGuard only)
|
||||
# are in the config file; the module's flags do not reach the server
|
||||
};
|
||||
asxpio.waitForData = [ "sillytavern" ];
|
||||
systemd.services.sillytavern = {
|
||||
after = [ "wireguard-${config.asxpio.wireguard.interface}.service" ];
|
||||
wants = [ "wireguard-${config.asxpio.wireguard.interface}.service" ];
|
||||
serviceConfig.RestartSec = 5;
|
||||
};
|
||||
}
|
||||
171
nixos/hosts/asxpio-services/sillytavern.yaml
Normal file
171
nixos/hosts/asxpio-services/sillytavern.yaml
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
dataRoot: ./data
|
||||
# Bound to the WireGuard address (in Docker this was the published port)
|
||||
listen: true
|
||||
listenAddress:
|
||||
ipv4: 10.20.0.20
|
||||
ipv6: "[::]"
|
||||
protocol:
|
||||
ipv4: true
|
||||
ipv6: false
|
||||
dnsPreferIPv6: false
|
||||
browserLaunch:
|
||||
enabled: false
|
||||
browser: default
|
||||
hostname: auto
|
||||
port: -1
|
||||
avoidLocalhost: false
|
||||
port: 8000
|
||||
ssl:
|
||||
enabled: false
|
||||
certPath: ./certs/cert.pem
|
||||
keyPath: ./certs/privkey.pem
|
||||
keyPassphrase: ""
|
||||
whitelistMode: true
|
||||
enableForwardedWhitelist: true
|
||||
whitelist:
|
||||
- ::1
|
||||
- 127.0.0.1
|
||||
- 10.20.0.0/24
|
||||
whitelistDockerHosts: true
|
||||
basicAuthMode: false
|
||||
basicAuthUser:
|
||||
username: user
|
||||
password: password
|
||||
enableCorsProxy: false
|
||||
requestProxy:
|
||||
enabled: false
|
||||
url: socks5://username:password@example.com:1080
|
||||
bypass:
|
||||
- localhost
|
||||
- 127.0.0.1
|
||||
enableUserAccounts: true
|
||||
enableDiscreetLogin: false
|
||||
perUserBasicAuth: false
|
||||
sso:
|
||||
autheliaAuth: false
|
||||
authentikAuth: false
|
||||
trustedProxies:
|
||||
- ::1
|
||||
- 127.0.0.1
|
||||
hostWhitelist:
|
||||
enabled: false
|
||||
scan: true
|
||||
hosts: []
|
||||
sessionTimeout: -1
|
||||
disableCsrfProtection: false
|
||||
securityOverride: false
|
||||
logging:
|
||||
enableAccessLog: true
|
||||
minLogLevel: 0
|
||||
rateLimiting:
|
||||
preferRealIpHeader: false
|
||||
basicAuthMaxAttempts: 5
|
||||
accountsLoginMaxAttempts: 5
|
||||
accountsRecoverMaxAttempts: 5
|
||||
accountsResetMaxAttempts: 5
|
||||
backups:
|
||||
common:
|
||||
numberOfBackups: 50
|
||||
chat:
|
||||
enabled: true
|
||||
checkIntegrity: true
|
||||
maxTotalBackups: -1
|
||||
throttleInterval: 10000
|
||||
allowFullDataBackup: true
|
||||
thumbnails:
|
||||
enabled: true
|
||||
format: jpg
|
||||
quality: 95
|
||||
dimensions:
|
||||
bg:
|
||||
- 160
|
||||
- 90
|
||||
avatar:
|
||||
- 96
|
||||
- 144
|
||||
persona:
|
||||
- 96
|
||||
- 144
|
||||
performance:
|
||||
lazyLoadCharacters: false
|
||||
memoryCacheCapacity: 100mb
|
||||
useDiskCache: true
|
||||
requestCompression:
|
||||
enabled: false
|
||||
minPayloadSize: 256kb
|
||||
maxPayloadSize: 8mb
|
||||
timeout: 4000
|
||||
cacheBuster:
|
||||
enabled: false
|
||||
userAgentPattern: ""
|
||||
allowKeysExposure: false
|
||||
skipContentCheck: false
|
||||
whitelistImportDomains:
|
||||
- localhost
|
||||
- cdn.discordapp.com
|
||||
- files.catbox.moe
|
||||
- raw.githubusercontent.com
|
||||
- char-archive.evulid.cc
|
||||
requestOverrides: []
|
||||
extensions:
|
||||
enabled: true
|
||||
autoUpdate: true
|
||||
models:
|
||||
autoDownload: true
|
||||
classification: Cohee/distilbert-base-uncased-go-emotions-onnx
|
||||
captioning: Xenova/vit-gpt2-image-captioning
|
||||
embedding: Cohee/jina-embeddings-v2-base-en
|
||||
speechToText: Xenova/whisper-small
|
||||
textToSpeech: Xenova/speecht5_tts
|
||||
enableDownloadableTokenizers: true
|
||||
promptPlaceholder: "[Start a new chat]"
|
||||
openai:
|
||||
randomizeUserId: false
|
||||
captionSystemPrompt: ""
|
||||
deepl:
|
||||
formality: default
|
||||
mistral:
|
||||
enablePrefix: false
|
||||
ollama:
|
||||
keepAlive: -1
|
||||
batchSize: -1
|
||||
claude:
|
||||
enableSystemPromptCache: false
|
||||
cachingAtDepth: -1
|
||||
extendedTTL: false
|
||||
enableAdaptiveThinking: false
|
||||
gemini:
|
||||
apiVersion: v1beta
|
||||
thoughtSignatures: true
|
||||
enableSystemPromptCache: false
|
||||
image:
|
||||
personGeneration: allow_adult
|
||||
enableServerPlugins: false
|
||||
enableServerPluginsAutoUpdate: true
|
||||
heartbeatInterval: 0
|
||||
enableKeepAlive: false
|
||||
cors:
|
||||
enabled: true
|
||||
origin:
|
||||
- "null"
|
||||
methods:
|
||||
- OPTIONS
|
||||
allowedHeaders: []
|
||||
exposedHeaders: []
|
||||
credentials: false
|
||||
maxAge: null
|
||||
privateAddressWhitelist:
|
||||
enabled: false
|
||||
allowUnresolvedHosts: false
|
||||
log:
|
||||
blockedRequests: true
|
||||
allowedRequests: false
|
||||
allowedRanges:
|
||||
- 127.0.0.0/8
|
||||
- ::1/128
|
||||
forwardedHeaders:
|
||||
xRealIp: true
|
||||
xForwardedFor: true
|
||||
cfConnectingIp: false
|
||||
git:
|
||||
backend: auto
|
||||
100
nixos/hosts/asxpio-services/xmpp.nix
Normal file
100
nixos/hosts/asxpio-services/xmpp.nix
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
# XMPP for asxp.io: another.im's ejabberd build, its push server and the
|
||||
# Telegram gateway. A custom image, so containers; the two helpers share
|
||||
# ejabberd's network namespace and reach its component port on 127.0.0.1.
|
||||
#
|
||||
# /opt/xmpp/state (secrets.env, certs/, apushd/, tackygram/) is host data:
|
||||
# generated once, backed up, not in this repo. Certificates arrive there
|
||||
# from asxpio-ops (xmpp-cert-sync).
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
# renovate: datasource=docker depName=dev.another.im/another-im/anotherim-server
|
||||
ejabberd = "dev.another.im/another-im/anotherim-server:2026.11.07";
|
||||
# renovate: datasource=docker depName=dev.another.im/another-im/apushd
|
||||
apushd = "dev.another.im/another-im/apushd:0.2";
|
||||
# renovate: datasource=docker depName=dev.another.im/another-im/tackygram
|
||||
tackygram = "dev.another.im/another-im/tackygram:0.4.3";
|
||||
|
||||
callPorts = "50000-50099";
|
||||
state = "/opt/xmpp/state";
|
||||
helper = {
|
||||
dependsOn = [ "xmpp-ejabberd" ];
|
||||
extraOptions = [ "--network=container:xmpp-ejabberd" ];
|
||||
};
|
||||
in
|
||||
{
|
||||
options.asxpio.publicIPv4 = lib.mkOption { type = lib.types.str; };
|
||||
|
||||
config = {
|
||||
virtualisation.oci-containers.containers = {
|
||||
xmpp-ejabberd = {
|
||||
image = ejabberd;
|
||||
environment = {
|
||||
EJABBERD_MACRO_XMPP_DOMAIN = "asxp.io";
|
||||
EJABBERD_MACRO_TURN_IP = config.asxpio.publicIPv4;
|
||||
EJABBERD_MACRO_POW_DIFFICULTY = "6";
|
||||
EJABBERD_MACRO_REGISTRATION_TIMEOUT = "600";
|
||||
EJABBERD_MACRO_UPLOAD_URL = "https://hel1.your-objectstorage.com/asxpio-xmpp-public/";
|
||||
EJABBERD_MACRO_ACME_URL = "https://acme-v02.api.letsencrypt.org/directory";
|
||||
};
|
||||
environmentFiles = [ "${state}/secrets.env" ];
|
||||
ports = [
|
||||
"5222:5222" # clients, STARTTLS
|
||||
"5223:5223" # clients, direct TLS
|
||||
"5269:5269" # other servers
|
||||
"5443:5443" # WebSocket, host-meta
|
||||
"8448:8448" # Matrix federation
|
||||
"3478:3478/udp" # STUN and TURN
|
||||
"3478:3478/tcp"
|
||||
"49160-49199:49160-49199/udp" # TURN relay
|
||||
"7777:7777" # SOCKS5 bytestreams proxy
|
||||
"${callPorts}:${callPorts}/udp" # gateway calls
|
||||
];
|
||||
volumes = [
|
||||
"xmpp_database:/opt/ejabberd/database"
|
||||
"xmpp_logs:/opt/ejabberd/logs"
|
||||
"${state}/certs:/opt/ejabberd/conf/certs:ro"
|
||||
];
|
||||
};
|
||||
|
||||
xmpp-apushd = helper // {
|
||||
image = apushd;
|
||||
volumes = [ "${state}/apushd:/etc/apushd:ro" ];
|
||||
};
|
||||
|
||||
xmpp-tackygram = helper // {
|
||||
image = tackygram;
|
||||
environment = {
|
||||
CREDENTIALS_DIRECTORY = "/run/credentials";
|
||||
TACKYGRAM_CALL_IP = config.asxpio.publicIPv4;
|
||||
TACKYGRAM_CALL_PORTS = callPorts;
|
||||
};
|
||||
environmentFiles = [ "${state}/tackygram/env" ];
|
||||
volumes = [
|
||||
"xmpp_tackygram:/var/lib/tackygram"
|
||||
"${state}/tackygram/key:/run/credentials/gateway-key:ro"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
asxpio.waitForData = [
|
||||
"podman-xmpp-ejabberd"
|
||||
"podman-xmpp-apushd"
|
||||
"podman-xmpp-tackygram"
|
||||
];
|
||||
|
||||
networking.firewall.allowedTCPPorts = [
|
||||
5222
|
||||
5223
|
||||
5269
|
||||
5443
|
||||
8448
|
||||
3478
|
||||
7777
|
||||
];
|
||||
networking.firewall.allowedUDPPorts = [ 3478 ];
|
||||
networking.firewall.allowedUDPPortRanges = [
|
||||
{ from = 49160; to = 49199; }
|
||||
{ from = 50000; to = 50099; }
|
||||
];
|
||||
};
|
||||
}
|
||||
13
nixos/hosts/asxpio-services/xray.nix
Normal file
13
nixos/hosts/asxpio-services/xray.nix
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Xray VLESS Reality on :443. The whole config is a secret (keys, UUIDs).
|
||||
{ config, unstable, ... }:
|
||||
{
|
||||
sops.secrets."xray/config" = { };
|
||||
|
||||
services.xray = {
|
||||
enable = true;
|
||||
package = unstable.xray; # 26.05 has 26.3, production runs 26.11
|
||||
settingsFile = config.sops.secrets."xray/config".path;
|
||||
};
|
||||
systemd.services.xray.restartTriggers = [ config.sops.secrets."xray/config".sopsFile ];
|
||||
networking.firewall.allowedTCPPorts = [ 443 ];
|
||||
}
|
||||
Loading…
Reference in a new issue