flake/nixos/profiles/sing-box-server/default.nix

60 lines
1.3 KiB
Nix
Raw Normal View History

2024-08-29 18:17:30 +00:00
{ lib, config, ... }:
2024-09-21 20:19:03 +00:00
let
inherit (config.networking) fqdn;
in
2024-08-27 21:02:01 +00:00
{
2024-09-21 20:19:03 +00:00
sops.secrets."sing-box/auth" = {
restartUnits = [ "sing-box.service" ];
sopsFile = ./secrets.yaml;
};
2024-09-20 17:38:01 +00:00
networking.firewall.allowedTCPPorts = [ 27253 ];
2024-08-27 21:02:01 +00:00
services.sing-box = {
enable = true;
settings = {
log = {
level = "info";
};
inbounds = [
{
type = "vless";
tag = "inbound";
listen = "0.0.0.0";
listen_port = 27253;
users = {
2024-09-06 13:20:24 +00:00
_secret = config.sops.secrets."sing-box/auth".path;
2024-08-27 21:02:01 +00:00
quote = false;
};
tls = {
enabled = true;
2024-09-21 20:19:03 +00:00
server_name = fqdn;
2024-08-27 21:02:01 +00:00
certificate_path = "/run/credentials/sing-box.service/cert";
key_path = "/run/credentials/sing-box.service/key";
};
}
];
2024-08-29 18:17:30 +00:00
outbounds = lib.singleton {
type = "direct";
tag = "direct";
};
2024-08-27 21:02:01 +00:00
route = {
final = "direct";
};
};
};
systemd.services."sing-box".serviceConfig.LoadCredential =
let
2024-09-21 20:19:03 +00:00
# FIXME: remove somewhat hardcoded path
path = "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory";
2024-08-27 21:02:01 +00:00
in
[
2024-09-21 20:19:03 +00:00
"cert:${path}/${fqdn}/${fqdn}.crt"
"key:${path}/${fqdn}/${fqdn}.key"
2024-08-27 21:02:01 +00:00
];
}