fieldpoc/nix/modules/yate.nix
2023-06-18 21:51:21 +02:00

57 lines
1.5 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.yate;
in {
options = {
services.yate = {
enable = mkEnableOption "yate";
config = mkOption {
type = with types; attrsOf anything;
default = { };
};
};
};
config = mkIf cfg.enable {
environment.etc = mapAttrs' (name: config: nameValuePair "yate/${name}.conf" { text = (if (isAttrs config) then generators.toINI {} config else config); }) cfg.config;
systemd.services.yate = {
description = "YATE Telephony Server";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" "postgresql.service" ];
environment = { PWLIB_ASSERT_ACTION = "C"; };
serviceConfig = {
Type = "forking";
ExecStart =
"${pkgs.yate}/bin/yate -d -p /run/yate/yate.pid -c /etc/yate -F -s -vvv -DF -r -l /var/lib/yate/yate.log";
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
User = "yate";
Group = "yate";
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
RuntimeDirectory = "yate";
RuntimeDirectoryMode = "0755";
ConfigurationDirectory = "yate";
StateDirectory = "yate";
StateDirectoryMode = "0700";
PIDFile = "/run/yate/yate.pid";
TimeoutSec = 30;
};
reloadTriggers = map (name: config.environment.etc."yate/${name}.conf".source) (attrNames cfg.config);
};
users.users.yate = {
isSystemUser = true;
group = "yate";
};
users.groups.yate = { };
};
}