flake/users/guanranwang/nixos/profiles/opt-in/clash-meta-client.nix

64 lines
1.7 KiB
Nix
Raw Normal View History

2023-09-19 00:17:43 +00:00
{
pkgs,
config,
inputs,
...
2023-11-23 06:23:03 +00:00
}: {
2023-11-04 10:02:11 +00:00
### sops-nix
sops.secrets."clash-config" = {
owner = config.users.users."clash-meta".name;
group = config.users.groups."clash-meta".name;
restartUnits = ["clash-meta.service"];
2023-11-23 06:23:03 +00:00
path = "/etc/clash-meta/config.yaml";
2023-11-04 10:02:11 +00:00
};
2023-10-14 09:40:12 +00:00
### System proxy settings
networking.proxy.default = "http://127.0.0.1:7890/";
2023-09-19 00:17:43 +00:00
2023-10-14 09:40:12 +00:00
### User running proxy service
users.groups."clash-meta" = {};
users.users."clash-meta" = {
isSystemUser = true;
group = config.users.groups."clash-meta".name;
};
### Proxy service
2023-09-19 00:17:43 +00:00
systemd.services."clash-meta" = {
2023-11-04 10:02:11 +00:00
description = "Clash.Meta Client";
after = ["network-online.target"];
2023-11-04 10:02:11 +00:00
wantedBy = ["multi-user.target"];
2023-11-04 10:02:11 +00:00
2023-09-19 00:17:43 +00:00
serviceConfig = {
Type = "simple";
2023-11-23 06:23:03 +00:00
WorkingDirectory = "/etc/clash-meta";
User = [config.users.users."clash-meta".name];
Group = [config.users.groups."clash-meta".name];
2023-11-23 06:23:03 +00:00
ExecStart = "${pkgs.clash-meta}/bin/clash-meta -d /etc/clash-meta";
2023-09-19 00:17:43 +00:00
Restart = "on-failure";
CapabilityBoundingSet = [
"CAP_NET_ADMIN"
"CAP_NET_BIND_SERVICE"
2023-11-04 10:02:11 +00:00
"CAP_NET_RAW"
];
AmbientCapabilities = [
"CAP_NET_ADMIN"
"CAP_NET_BIND_SERVICE"
2023-11-04 10:02:11 +00:00
"CAP_NET_RAW"
];
2023-09-19 00:17:43 +00:00
};
};
2023-10-14 07:53:25 +00:00
### Local Clash WebUI
# You can also use the following website, just in case:
# - metacubexd:
# - GH Pages Custom Domain: http://d.metacubex.one
# - GH Pages: https://metacubex.github.io/metacubexd
# - Cloudflare Pages: https://metacubexd.pages.dev
# - yacd (Yet Another Clash Dashboard):
# - https://yacd.haishan.me
# - clash-dashboard (buggy):
# - https://clash.razord.top
2023-12-13 05:54:34 +00:00
environment.etc."clash-meta/metacubexd".source = inputs.self.packages.${pkgs.system}.metacubexd;
}