2024-12-10 20:29:24 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
2024-01-28 12:55:05 +08:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.services.realm;
|
|
|
|
configFormat = pkgs.formats.json { };
|
|
|
|
configFile = configFormat.generate "config.json" cfg.config;
|
|
|
|
inherit (lib)
|
2024-12-10 20:29:24 +01:00
|
|
|
mkEnableOption
|
|
|
|
mkPackageOption
|
|
|
|
mkOption
|
|
|
|
mkIf
|
|
|
|
types
|
|
|
|
getExe
|
|
|
|
;
|
2024-01-28 12:55:05 +08:00
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ ocfox ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.realm = {
|
|
|
|
enable = mkEnableOption "A simple, high performance relay server written in rust";
|
|
|
|
package = mkPackageOption pkgs "realm" { };
|
|
|
|
config = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = configFormat.type;
|
|
|
|
};
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
The realm configuration, see <https://github.com/zhboner/realm#overview> for documentation.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.realm = {
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ExecStart = "${getExe cfg.package} --config ${configFile}";
|
2024-12-10 20:29:24 +01:00
|
|
|
AmbientCapabilities = [
|
|
|
|
"CAP_NET_ADMIN"
|
|
|
|
"CAP_NET_BIND_SERVICE"
|
|
|
|
];
|
2024-01-28 12:55:05 +08:00
|
|
|
};
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|