9 cfg = config.services.turn-rs;
10 format = pkgs.formats.toml { };
13 options.services.turn-rs = {
14 enable = lib.mkEnableOption "turn-rs server";
15 package = lib.mkPackageOption pkgs "turn-rs" { };
17 secretFile = lib.mkOption {
18 type = lib.types.nullOr lib.types.path;
20 example = "/run/keys/turn-rs.env";
22 Environment variables from this file will be interpolated into the
23 final config file using envsubst with this syntax: `$ENVIRONMENT` or
25 The file should contain lines formatted as `SECRET_VAR=SECRET_VALUE`.
26 This is useful to avoid putting secrets into the nix store.
30 settings = lib.mkOption {
31 type = lib.types.submodule {
32 freeformType = format.type;
34 description = "Turn-rs server config file";
42 bind = "127.0.0.1:3478";
43 external = "127.0.0.1:3478";
47 bind = "127.0.0.1:3478";
48 external = "127.0.0.1:3478";
53 auth.static_credentials = {
61 config = lib.mkIf cfg.enable {
62 services.turn-rs.settings = {
63 api.bind = lib.mkDefault "127.0.0.1:3000";
64 log.level = lib.mkDefault "info";
67 systemd.services.turn-rs = {
69 wantedBy = [ "multi-user.target" ];
70 description = "Turn-rs Server Daemon";
73 configFile = format.generate "turn-rs-config.toml" cfg.settings;
76 ${lib.getExe pkgs.envsubst} -i "${configFile}" -o /run/turn-rs/config.toml
79 RuntimeDirectory = "turn-rs";
80 EnvironmentFile = lib.optional (cfg.secretFile != null) cfg.secretFile;
81 ExecStart = "${lib.getExe cfg.package} --config=/run/turn-rs/config.toml";