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
65
nixos/modules/wireguard.nix
Normal file
65
nixos/modules/wireguard.nix
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# WireGuard, the admin network (10.20.0.0/24). asxpio-ops is the hub
|
||||
# every peer connects to; everything else is a spoke with ops as its
|
||||
# only peer. Keys come from sops: wireguard/private_key and, per peer,
|
||||
# wireguard/psk/<name>.
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
cfg = config.asxpio.wireguard;
|
||||
in
|
||||
{
|
||||
options.asxpio.wireguard = {
|
||||
interface = lib.mkOption { type = lib.types.str; };
|
||||
address = lib.mkOption { type = lib.types.listOf lib.types.str; };
|
||||
listenPort = lib.mkOption { type = lib.types.port; };
|
||||
hub = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Forward between peers, and masquerade what leaves by the public interface.";
|
||||
};
|
||||
peers = lib.mkOption {
|
||||
type = lib.types.listOf (
|
||||
lib.types.submodule {
|
||||
options = {
|
||||
name = lib.mkOption { type = lib.types.str; };
|
||||
publicKey = lib.mkOption { type = lib.types.str; };
|
||||
allowedIPs = lib.mkOption { type = lib.types.listOf lib.types.str; };
|
||||
endpoint = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
sops.secrets = {
|
||||
"wireguard/private_key" = { };
|
||||
}
|
||||
// lib.listToAttrs (map (p: lib.nameValuePair "wireguard/psk/${p.name}" { }) cfg.peers);
|
||||
|
||||
networking.wireguard.interfaces.${cfg.interface} = {
|
||||
ips = cfg.address;
|
||||
listenPort = cfg.listenPort;
|
||||
privateKeyFile = config.sops.secrets."wireguard/private_key".path;
|
||||
peers = map (p: {
|
||||
inherit (p) name publicKey allowedIPs endpoint;
|
||||
presharedKeyFile = config.sops.secrets."wireguard/psk/${p.name}".path;
|
||||
persistentKeepalive = 25;
|
||||
}) cfg.peers;
|
||||
};
|
||||
networking.firewall.allowedUDPPorts = [ cfg.listenPort ];
|
||||
|
||||
boot.kernel.sysctl = lib.mkIf cfg.hub {
|
||||
"net.ipv4.ip_forward" = 1;
|
||||
"net.ipv6.conf.all.forwarding" = 1;
|
||||
};
|
||||
networking.nat = lib.mkIf cfg.hub {
|
||||
enable = true;
|
||||
enableIPv6 = true;
|
||||
internalInterfaces = [ cfg.interface ];
|
||||
externalInterface = "enp1s0";
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue