flake/nixos/profiles/common/opt-in/_hysteria2-server.nix

56 lines
1.3 KiB
Nix
Raw Normal View History

{
pkgs,
config,
...
}: let
2023-11-04 10:02:11 +00:00
port = 43956;
in {
2023-11-04 10:02:11 +00:00
### Firewall
networking.firewall = {
allowedTCPPorts = [port 80 443];
allowedUDPPorts = [port 80 443];
2023-11-04 10:02:11 +00:00
};
#### sops-nix
sops.secrets."hysteria-config" = {
owner = config.users.users."hysteria".name;
group = config.users.groups."hysteria".name;
restartUnits = ["hysteria-server.service"];
2023-11-23 06:23:03 +00:00
path = "/etc/hysteria/config.yaml";
2023-11-04 10:02:11 +00:00
};
### User running proxy service
users.groups."hysteria" = {};
users.users."hysteria" = {
isSystemUser = true;
group = config.users.groups."hysteria".name;
};
### Proxy service
systemd.services."hysteria-server" = {
description = "Hysteria Server";
after = ["network.target"];
2023-11-04 10:02:11 +00:00
wantedBy = ["multi-user.target"];
2023-11-04 10:02:11 +00:00
serviceConfig = {
Type = "simple";
2023-11-23 06:23:03 +00:00
WorkingDirectory = "/etc/hysteria";
User = [config.users.users."hysteria".name];
Group = [config.users.groups."hysteria".name];
2023-11-23 06:23:03 +00:00
ExecStart = "${pkgs.hysteria}/bin/hysteria server --config /etc/hysteria/config.yaml";
2023-11-04 10:02:11 +00:00
Restart = "on-failure";
CapabilityBoundingSet = [
"CAP_NET_ADMIN"
"CAP_NET_BIND_SERVICE"
"CAP_NET_RAW"
];
AmbientCapabilities = [
"CAP_NET_ADMIN"
"CAP_NET_BIND_SERVICE"
"CAP_NET_RAW"
];
};
};
}