25 inherit (utils) escapeSystemdExecArgs;
27 cfg = config.services.netbird.server.signal;
31 options.services.netbird.server.signal = {
32 enable = mkEnableOption "Netbird's Signal Service";
34 package = mkPackageOption pkgs "netbird" { };
36 enableNginx = mkEnableOption "Nginx reverse-proxy for the netbird signal service";
40 description = "The domain name for the signal service.";
46 description = "Internal port of the signal server.";
49 metricsPort = mkOption {
52 description = "Internal port of the metrics server.";
55 extraOptions = mkOption {
59 Additional options given to netbird-signal as commandline arguments.
71 description = "Log level of the netbird signal service.";
75 config = mkIf cfg.enable {
79 assertion = cfg.port != cfg.metricsPort;
80 message = "The primary listen port cannot be the same as the listen port for the metrics endpoint";
84 systemd.services.netbird-signal = {
85 after = [ "network.target" ];
86 wantedBy = [ "multi-user.target" ];
89 ExecStart = escapeSystemdExecArgs (
91 (getExe' cfg.package "netbird-signal")
96 # Port the internal prometheus server listens on
110 RuntimeDirectory = "netbird-mgmt";
111 StateDirectory = "netbird-mgmt";
112 WorkingDirectory = "/var/lib/netbird-mgmt";
115 LockPersonality = true;
116 MemoryDenyWriteExecute = true;
117 NoNewPrivileges = true;
118 PrivateMounts = true;
121 ProtectControlGroups = true;
123 ProtectHostname = true;
124 ProtectKernelLogs = true;
125 ProtectKernelModules = true;
126 ProtectKernelTunables = true;
127 ProtectSystem = true;
129 RestrictNamespaces = true;
130 RestrictRealtime = true;
131 RestrictSUIDSGID = true;
134 stopIfChanged = false;
137 services.nginx = mkIf cfg.enableNginx {
140 virtualHosts.${cfg.domain} = {
141 locations."/signalexchange.SignalExchange/".extraConfig = ''
142 # This is necessary so that grpc connections do not get closed early
143 # see https://stackoverflow.com/a/67805465
144 client_body_timeout 1d;
146 grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
148 grpc_pass grpc://localhost:${builtins.toString cfg.port};
149 grpc_read_timeout 1d;
150 grpc_send_timeout 1d;
151 grpc_socket_keepalive on;