8 cfg = config.services.tigerbeetle;
12 maintainers = with lib.maintainers; [ danielsidhion ];
13 doc = ./tigerbeetle.md;
14 buildDocsInSandbox = true;
18 services.tigerbeetle = with lib; {
19 enable = mkEnableOption "TigerBeetle server";
21 package = mkPackageOption pkgs "tigerbeetle" { };
23 clusterId = mkOption {
24 type = types.either types.ints.unsigned (types.strMatching "[0-9]+");
27 The 128-bit cluster ID used to create the replica data file (if needed).
28 Since Nix only supports integers up to 64 bits, you need to pass a string to this if the cluster ID can't fit in 64 bits.
29 Otherwise, you can pass the cluster ID as either an integer or a string.
33 replicaIndex = mkOption {
34 type = types.ints.unsigned;
37 The index (starting at 0) of the replica in the cluster.
41 replicaCount = mkOption {
42 type = types.ints.unsigned;
45 The number of replicas participating in replication of the cluster.
49 cacheGridSize = mkOption {
50 type = types.strMatching "[0-9]+(K|M|G)iB";
54 The grid cache acts like a page cache for TigerBeetle.
55 It is recommended to set this as large as possible.
59 addresses = mkOption {
60 type = types.listOf types.nonEmptyStr;
63 The addresses of all replicas in the cluster.
64 This should be a list of IPv4/IPv6 addresses with port numbers.
65 Either the address or port number (but not both) may be omitted, in which case a default of 127.0.0.1 or 3001 will be used.
66 The first address in the list corresponds to the address for replica 0, the second address for replica 1, and so on.
72 config = lib.mkIf cfg.enable {
75 numAddresses = builtins.length cfg.addresses;
79 assertion = cfg.replicaIndex < cfg.replicaCount;
80 message = "the TigerBeetle replica index must fit the configured replica count";
83 assertion = cfg.replicaCount == numAddresses;
85 if cfg.replicaCount < numAddresses then
86 "TigerBeetle must not have more addresses than the configured number of replicas"
88 "TigerBeetle must be configured with the addresses of all replicas";
92 systemd.services.tigerbeetle =
94 replicaDataPath = "/var/lib/tigerbeetle/${builtins.toString cfg.clusterId}_${builtins.toString cfg.replicaIndex}.tigerbeetle";
97 description = "TigerBeetle server";
99 wantedBy = [ "multi-user.target" ];
100 after = [ "network.target" ];
103 if ! test -e "${replicaDataPath}"; then
104 ${lib.getExe cfg.package} format --cluster="${builtins.toString cfg.clusterId}" --replica="${builtins.toString cfg.replicaIndex}" --replica-count="${builtins.toString cfg.replicaCount}" "${replicaDataPath}"
109 DevicePolicy = "closed";
111 ExecStart = "${lib.getExe cfg.package} start --cache-grid=${cfg.cacheGridSize} --addresses=${lib.escapeShellArg (builtins.concatStringsSep "," cfg.addresses)} ${replicaDataPath}";
112 LockPersonality = true;
114 ProtectControlGroups = true;
116 ProtectHostname = true;
117 ProtectKernelLogs = true;
118 ProtectKernelModules = true;
119 ProtectKernelTunables = true;
120 ProtectProc = "noaccess";
121 ProtectSystem = "strict";
122 RestrictAddressFamilies = [
126 RestrictNamespaces = true;
127 RestrictRealtime = true;
128 RestrictSUIDSGID = true;
129 StateDirectory = "tigerbeetle";
130 StateDirectoryMode = 700;
135 environment.systemPackages = [ cfg.package ];