1 { config, lib, pkgs, ... }:
3 cfg = config.services.centrifugo;
5 settingsFormat = pkgs.formats.json { };
7 configFile = settingsFormat.generate "centrifugo.json" cfg.settings;
10 options.services.centrifugo = {
11 enable = lib.mkEnableOption "Centrifugo messaging server";
13 package = lib.mkPackageOption pkgs "centrifugo" { };
15 settings = lib.mkOption {
16 type = settingsFormat.type;
19 Declarative Centrifugo configuration. See the [Centrifugo
20 documentation] for a list of options.
22 [Centrifugo documentation]: https://centrifugal.dev/docs/server/configuration
26 credentials = lib.mkOption {
27 type = lib.types.attrsOf lib.types.path;
30 CENTRIFUGO_UNI_GRPC_TLS_KEY = "/run/keys/centrifugo-uni-grpc-tls.key";
33 Environment variables with absolute paths to credentials files to load
38 environmentFiles = lib.mkOption {
39 type = lib.types.listOf lib.types.path;
42 Files to load environment variables from. Options set via environment
43 variables take precedence over {option}`settings`.
45 See the [Centrifugo documentation] for the environment variable name
48 [Centrifugo documentation]: https://centrifugal.dev/docs/server/configuration#os-environment-variables
52 extraGroups = lib.mkOption {
53 type = lib.types.listOf lib.types.str;
55 example = [ "redis-centrifugo" ];
57 Additional groups for the systemd service.
62 config = lib.mkIf cfg.enable {
63 systemd.services.centrifugo = {
64 description = "Centrifugo messaging server";
65 wantedBy = [ "multi-user.target" ];
66 after = [ "network.target" ];
71 ExecStartPre = "${lib.getExe cfg.package} checkconfig --config ${configFile}";
72 ExecStart = "${lib.getExe cfg.package} --config ${configFile}";
73 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
78 # Copy files to the credentials directory with file name being the
79 # environment variable name. Note that "%d" specifier expands to the
80 # path of the credentials directory.
81 LoadCredential = lib.mapAttrsToList (name: value: "${name}:${value}") cfg.credentials;
82 Environment = lib.mapAttrsToList (name: _: "${name}=%d/${name}") cfg.credentials;
84 EnvironmentFile = cfg.environmentFiles;
86 SupplementaryGroups = cfg.extraGroups;
92 ProtectProc = "invisible";
95 ProtectHostname = true;
96 ProtectControlGroups = true;
97 ProtectKernelLogs = true;
98 ProtectKernelModules = true;
99 ProtectKernelTunables = true;
101 PrivateDevices = true;
102 RestrictRealtime = true;
103 RestrictNamespaces = true;
104 RestrictAddressFamilies = [
109 DeviceAllow = [ "" ];
110 DevicePolicy = "closed";
111 CapabilityBoundingSet = [ "" ];
112 MemoryDenyWriteExecute = true;
113 LockPersonality = true;
114 SystemCallArchitectures = "native";
115 SystemCallErrorNumber = "EPERM";