2024-04-22 21:01:38 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
2024-07-09 13:03:42 +00:00
|
|
|
pkgs,
|
|
|
|
utils,
|
2024-04-22 21:01:38 +00:00
|
|
|
...
|
2024-08-25 15:02:35 +00:00
|
|
|
}:
|
|
|
|
let
|
2024-04-22 21:01:38 +00:00
|
|
|
cfg = config.services.hysteria;
|
2024-08-25 15:02:35 +00:00
|
|
|
settingsFormat = pkgs.formats.json { };
|
|
|
|
in
|
|
|
|
{
|
2024-04-22 21:01:38 +00:00
|
|
|
options.services.hysteria = {
|
|
|
|
enable = lib.mkEnableOption "Hysteria, a powerful, lightning fast and censorship resistant proxy";
|
|
|
|
|
2024-08-25 15:02:35 +00:00
|
|
|
package = lib.mkPackageOption pkgs "hysteria" { };
|
2024-04-22 21:01:38 +00:00
|
|
|
|
|
|
|
mode = lib.mkOption {
|
2024-08-25 15:02:35 +00:00
|
|
|
type = lib.types.enum [
|
|
|
|
"server"
|
|
|
|
"client"
|
|
|
|
];
|
2024-04-22 21:01:38 +00:00
|
|
|
default = "server";
|
2024-05-01 00:20:34 +00:00
|
|
|
description = "Whether to use Hysteria as a client or a server.";
|
2024-04-22 21:01:38 +00:00
|
|
|
};
|
|
|
|
|
2024-07-09 13:03:42 +00:00
|
|
|
settings = lib.mkOption {
|
|
|
|
type = lib.types.submodule {
|
|
|
|
freeformType = settingsFormat.type;
|
|
|
|
};
|
2024-08-25 15:02:35 +00:00
|
|
|
default = { };
|
2024-05-01 00:20:34 +00:00
|
|
|
description = ''
|
2024-07-09 13:03:42 +00:00
|
|
|
The Hysteria configuration, see https://hysteria.network/ for documentation.
|
2024-05-01 00:20:34 +00:00
|
|
|
|
2024-07-09 13:03:42 +00:00
|
|
|
Options containing secret data should be set to an attribute set
|
|
|
|
containing the attribute `_secret` - a string pointing to a file
|
|
|
|
containing the value the option should be set to.
|
|
|
|
|
|
|
|
Ignored when `services.hysteria.configFile` is set.
|
2024-05-01 00:20:34 +00:00
|
|
|
'';
|
2024-04-22 21:01:38 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
systemd.services."hysteria" = {
|
|
|
|
description = "Hysteria daemon, a powerful, lightning fast and censorship resistant proxy.";
|
2024-08-25 15:02:35 +00:00
|
|
|
documentation = [ "https://hysteria.network/" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
2024-07-09 13:03:42 +00:00
|
|
|
preStart = utils.genJqSecretsReplacementSnippet cfg.settings "/var/lib/private/hysteria/config.json";
|
2024-04-22 21:01:38 +00:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = lib.concatStringsSep " " [
|
|
|
|
(lib.getExe cfg.package)
|
|
|
|
cfg.mode
|
2024-07-09 13:03:42 +00:00
|
|
|
"--config /var/lib/private/hysteria/config.json"
|
2024-04-22 21:01:38 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
DynamicUser = true;
|
|
|
|
StateDirectory = "hysteria";
|
|
|
|
|
|
|
|
### Hardening
|
2024-08-25 15:02:35 +00:00
|
|
|
AmbientCapabilities = [
|
|
|
|
"CAP_NET_ADMIN"
|
|
|
|
"CAP_NET_BIND_SERVICE"
|
|
|
|
"CAP_NET_RAW"
|
|
|
|
];
|
|
|
|
CapabilityBoundingSet = [
|
|
|
|
"CAP_NET_ADMIN"
|
|
|
|
"CAP_NET_BIND_SERVICE"
|
|
|
|
"CAP_NET_RAW"
|
|
|
|
];
|
2024-04-22 21:01:38 +00:00
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProcSubset = "pid";
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
SystemCallArchitectures = "native";
|
2024-05-01 00:20:34 +00:00
|
|
|
SystemCallFilter = "@system-service";
|
2024-04-22 21:01:38 +00:00
|
|
|
UMask = "0077";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|