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

105 lines
2.2 KiB
Nix
Raw Normal View History

2024-08-24 08:10:54 +00:00
{
2024-08-27 21:02:01 +00:00
lib,
2024-08-24 08:10:54 +00:00
pkgs,
config,
...
}:
{
2024-08-24 08:10:54 +00:00
services.sing-box = {
enable = true;
settings = {
2024-08-24 08:58:06 +00:00
log = {
level = "info";
};
2024-08-29 18:17:30 +00:00
inbounds = lib.singleton {
type = "http";
tag = "inbound";
listen = "127.0.0.1";
listen_port = 1080;
sniff = true;
sniff_override_destination = true;
};
2024-08-24 08:10:54 +00:00
outbounds = [
{
2024-08-27 21:02:01 +00:00
type = "vless";
2024-08-24 08:10:54 +00:00
tag = "tyo0";
server = "tyo0.ny4.dev";
2024-08-27 21:02:01 +00:00
server_port = 27253;
uuid = "29e54ee5-43f5-4891-b750-ca73c7e3b2b3";
flow = "xtls-rprx-vision";
2024-08-24 08:10:54 +00:00
tls.enabled = true;
}
{
type = "direct";
tag = "direct";
}
];
route = {
rules = [
{
2024-08-24 13:11:27 +00:00
rule_set = [
"geoip-cn"
"geosite-cn"
];
outbound = "direct";
}
{
rule_set = [
"geosite-private"
];
ip_is_private = true;
2024-08-24 08:10:54 +00:00
outbound = "direct";
}
];
2024-08-24 13:11:27 +00:00
2024-08-24 08:10:54 +00:00
rule_set = [
{
tag = "geoip-cn";
type = "local";
format = "binary";
path = "${pkgs.sing-geoip}/share/sing-box/rule-set/geoip-cn.srs";
}
{
tag = "geosite-cn";
type = "local";
format = "binary";
path = "${pkgs.sing-geosite}/share/sing-box/rule-set/geosite-cn.srs";
}
2024-08-24 13:11:27 +00:00
{
tag = "geosite-private";
type = "local";
format = "binary";
path = "${pkgs.sing-geosite}/share/sing-box/rule-set/geosite-private.srs";
}
2024-08-24 08:10:54 +00:00
];
2024-08-24 13:11:27 +00:00
2024-08-27 21:02:01 +00:00
final = lib.mkDefault "tyo0";
2024-08-24 08:10:54 +00:00
};
};
};
### System proxy settings
2024-08-24 08:58:06 +00:00
networking.proxy = {
httpProxy = "http://127.0.0.1:1080/";
httpsProxy = "http://127.0.0.1:1080/";
};
2024-08-24 13:11:27 +00:00
2024-08-27 21:44:22 +00:00
programs.fish.shellAliases =
let
inherit (config.networking.proxy) httpProxy httpsProxy;
in
{
"setproxy" = "export http_proxy=${httpProxy} https_proxy=${httpsProxy}";
"unsetproxy" = "set -e http_proxy https_proxy";
};
2024-08-24 08:10:54 +00:00
### sops-nix
sops.secrets."sing-box/tyo0" = {
restartUnits = [ "sing-box.service" ];
2024-08-24 08:10:54 +00:00
sopsFile = ./secrets.yaml;
};
}