2024-06-11 10:19:43 +00:00
|
|
|
{ config, lib, ... }:
|
2024-04-16 08:48:56 +00:00
|
|
|
let
|
2024-06-11 10:19:43 +00:00
|
|
|
awsHosts = [ "tok-00 "];
|
2024-04-16 08:48:56 +00:00
|
|
|
bwgHosts = [ "la-00" ];
|
|
|
|
in
|
2023-10-06 14:05:19 +00:00
|
|
|
{
|
2023-11-28 13:38:50 +00:00
|
|
|
imports = [
|
|
|
|
../sops.nix
|
2024-06-11 10:19:43 +00:00
|
|
|
./bandwagon.nix
|
|
|
|
./lightsail.nix
|
2023-11-28 13:38:50 +00:00
|
|
|
];
|
|
|
|
|
2023-12-19 13:32:40 +00:00
|
|
|
|
2023-12-06 14:54:22 +00:00
|
|
|
config = {
|
2024-04-16 08:48:56 +00:00
|
|
|
isBandwagon = builtins.elem config.networking.hostName bwgHosts;
|
|
|
|
isLightsail = builtins.elem config.networking.hostName awsHosts;
|
2023-12-19 13:32:40 +00:00
|
|
|
sops = {
|
|
|
|
secrets = {
|
|
|
|
wg_private_key = {
|
|
|
|
owner = "root";
|
|
|
|
sopsFile = ./secrets + "/${config.networking.hostName}.yaml";
|
|
|
|
};
|
|
|
|
wg_ipv6_local_addr = {
|
|
|
|
owner = "root";
|
|
|
|
sopsFile = ./secrets + "/${config.networking.hostName}.yaml";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-12-06 14:54:22 +00:00
|
|
|
boot.kernel.sysctl = {
|
|
|
|
"net.core.default_qdisc" = "fq";
|
|
|
|
"net.ipv4.tcp_congestion_control" = "bbr";
|
|
|
|
};
|
2023-11-28 13:38:50 +00:00
|
|
|
|
2023-12-06 14:54:22 +00:00
|
|
|
networking.firewall.trustedInterfaces = [ "tun0" ];
|
2023-11-28 13:38:50 +00:00
|
|
|
|
2023-12-06 14:54:22 +00:00
|
|
|
security.acme = {
|
|
|
|
acceptTerms = true;
|
2023-12-19 13:32:40 +00:00
|
|
|
certs.${config.deployment.targetHost} = {
|
2023-12-06 14:54:22 +00:00
|
|
|
email = "me@namely.icu";
|
|
|
|
listenHTTP = ":80";
|
|
|
|
};
|
2023-11-28 13:38:50 +00:00
|
|
|
};
|
2023-12-06 14:54:22 +00:00
|
|
|
networking.firewall.allowedTCPPorts = [ 80 8080 ];
|
|
|
|
networking.firewall.allowedUDPPorts = [ ] ++ (lib.range 6311 6314);
|
2023-10-06 14:05:19 +00:00
|
|
|
|
2023-12-20 03:13:20 +00:00
|
|
|
custom.prometheus = {
|
2024-03-07 04:03:59 +00:00
|
|
|
enable = false;
|
2024-04-16 08:48:56 +00:00
|
|
|
exporters.enable = false;
|
2023-12-20 03:13:20 +00:00
|
|
|
grafana = {
|
2024-04-16 08:48:56 +00:00
|
|
|
enable = false;
|
2023-12-20 03:13:20 +00:00
|
|
|
password_file = config.sops.secrets.grafana_cloud_api.path;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-09 04:27:51 +00:00
|
|
|
custom.kanidm-client = {
|
|
|
|
enable = true;
|
|
|
|
uri = "https://auth.xinyang.life/";
|
|
|
|
asSSHAuth = {
|
|
|
|
enable = true;
|
|
|
|
allowedGroups = [ "linux_users" ];
|
|
|
|
};
|
|
|
|
sudoers = [ "xin@auth.xinyang.life" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.openssh = {
|
|
|
|
settings = {
|
|
|
|
PasswordAuthentication = false;
|
|
|
|
KbdInteractiveAuthentication = false;
|
|
|
|
PermitRootLogin = lib.mkForce "no";
|
|
|
|
GSSAPIAuthentication = "no";
|
|
|
|
KerberosAuthentication = "no";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
services.fail2ban.enable = true;
|
2024-01-13 02:47:37 +00:00
|
|
|
programs.mosh.enable = true;
|
2024-01-09 04:27:51 +00:00
|
|
|
|
|
|
|
security.sudo = {
|
|
|
|
execWheelOnly = true;
|
|
|
|
wheelNeedsPassword = false;
|
|
|
|
};
|
|
|
|
|
2024-01-13 02:47:37 +00:00
|
|
|
nix.settings = {
|
|
|
|
trusted-users = config.users.groups.wheel.members;
|
|
|
|
};
|
|
|
|
|
2023-12-19 13:32:40 +00:00
|
|
|
services.sing-box = let
|
|
|
|
singTls = {
|
|
|
|
enabled = true;
|
|
|
|
server_name = config.deployment.targetHost;
|
|
|
|
key_path = config.security.acme.certs.${config.deployment.targetHost}.directory + "/key.pem";
|
|
|
|
certificate_path = config.security.acme.certs.${config.deployment.targetHost}.directory + "/cert.pem";
|
|
|
|
};
|
|
|
|
password = {
|
|
|
|
_secret = config.sops.secrets.singbox_password.path;
|
|
|
|
};
|
|
|
|
uuid = {
|
|
|
|
_secret = config.sops.secrets.singbox_uuid.path;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2023-12-06 14:54:22 +00:00
|
|
|
enable = true;
|
|
|
|
settings = {
|
2023-12-19 13:32:40 +00:00
|
|
|
dns = {
|
|
|
|
servers = [
|
|
|
|
{
|
|
|
|
address = "1.1.1.1";
|
|
|
|
detour = "wg-out";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2023-12-06 14:54:22 +00:00
|
|
|
inbounds = [
|
|
|
|
{
|
|
|
|
tag = "sg0";
|
|
|
|
type = "trojan";
|
|
|
|
listen = "::";
|
|
|
|
listen_port = 8080;
|
|
|
|
users = [
|
|
|
|
{ name = "proxy";
|
2023-12-19 13:32:40 +00:00
|
|
|
password = password;
|
2023-12-06 14:54:22 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
tls = singTls;
|
|
|
|
}
|
|
|
|
] ++ lib.forEach (lib.range 6311 6314) (port: {
|
|
|
|
tag = "sg" + toString (port - 6310);
|
|
|
|
type = "tuic";
|
|
|
|
listen = "::";
|
|
|
|
listen_port = port;
|
|
|
|
congestion_control = "bbr";
|
|
|
|
users = [
|
|
|
|
{ name = "proxy";
|
2023-12-19 13:32:40 +00:00
|
|
|
uuid = uuid;
|
|
|
|
password = password;
|
2023-12-06 14:54:22 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
tls = singTls;
|
|
|
|
});
|
2023-12-19 13:32:40 +00:00
|
|
|
outbounds = [
|
|
|
|
{
|
|
|
|
type = "wireguard";
|
|
|
|
tag = "wg-out";
|
|
|
|
private_key = {
|
|
|
|
_secret = config.sops.secrets.wg_private_key.path;
|
|
|
|
};
|
|
|
|
local_address = [
|
|
|
|
"172.16.0.2/32"
|
|
|
|
{ _secret = config.sops.secrets.wg_ipv6_local_addr.path; }
|
|
|
|
];
|
|
|
|
peers = [
|
|
|
|
{ public_key= "bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=";
|
|
|
|
allowed_ips = [ "0.0.0.0/0" "::/0" ];
|
|
|
|
server = "162.159.192.1";
|
|
|
|
server_port = 500;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
type = "direct";
|
|
|
|
tag = "direct";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
type = "dns";
|
|
|
|
tag = "dns-out";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
route = {
|
|
|
|
rules = [
|
|
|
|
{
|
|
|
|
outbound = "dns-out";
|
|
|
|
protocol = "dns";
|
|
|
|
}
|
|
|
|
{
|
2024-02-27 04:56:45 +00:00
|
|
|
inbound = "sg4";
|
2023-12-19 13:32:40 +00:00
|
|
|
outbound = "direct";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2023-12-06 14:54:22 +00:00
|
|
|
};
|
2023-10-06 14:05:19 +00:00
|
|
|
};
|
|
|
|
};
|
2023-12-06 14:54:22 +00:00
|
|
|
|
2023-10-06 14:05:19 +00:00
|
|
|
}
|