1 { config, pkgs, name, ... }:
3 # CREATE INDEX ON LOGS (tag);
4 # CREATE INDEX ON LOGS (time);
5 # CREATE INDEX ON LOGS (((data->>'PRIORITY')::int));
6 # CREATE INDEX ON LOGS ((data->>'_SYSTEMD_UNIT'));
7 # CREATE INDEX ON LOGS ((data->>'SYSLOG_IDENTIFIER'));
14 tag = "${name}.systemd";
15 DB = "/var/lib/fluentbit/fluent-bit.db";
21 match = "${name}.systemd";
23 labels = "job=fluentbit, server=${name}, priority=$PRIORITY, syslog_identifier=$SYSLOG_IDENTIFIER, systemd_unit=$_SYSTEMD_UNIT";
28 host = "/run/postgresql";
31 database = "fluentbit";
32 timestamp_key = "event_timestamp";
37 yamlFormat = pkgs.formats.yaml {};
38 psqlVersion = pkgs.postgresql_16.psqlSchema;
41 disko.devices.zpool.zfast.datasets."root/persist/var/lib/loki" =
42 { type = "zfs_fs"; mountpoint = "/persist/zfast/var/lib/loki"; options.mountpoint = "legacy"; };
43 disko.devices.zpool.zfast.datasets."root/persist/var/lib/fluentbit" =
44 { type = "zfs_fs"; mountpoint = "/persist/zfast/var/lib/fluentbit"; options.mountpoint = "legacy"; };
45 disko.devices.zpool.zfast.datasets."root/persist/var/lib/postgresql" =
46 { type = "zfs_fs"; mountpoint = "/persist/zfast/var/lib/postgresql"; options.mountpoint = "legacy"; };
47 disko.devices.zpool.zfast.datasets."root/persist/var/lib/postgresql/${psqlVersion}" =
48 { type = "zfs_fs"; mountpoint = "/persist/zfast/var/lib/postgresql/${psqlVersion}"; options.mountpoint = "legacy"; };
49 environment.persistence."/persist/zfast".directories = [
51 directory = "/var/lib/postgresql";
52 user = config.users.users.postgres.name;
53 group = config.users.users.postgres.group;
57 directory = "/var/lib/postgresql/${psqlVersion}";
58 user = config.users.users.postgres.name;
59 group = config.users.users.postgres.group;
63 directory = "/var/lib/fluentbit";
64 user = config.users.users.fluentbit.name;
65 group = config.users.users.fluentbit.group;
69 directory = "/var/lib/loki";
70 user = config.users.users.loki.name;
71 group = config.users.users.loki.group;
76 ids.uids.fluentbit = 500;
77 ids.gids.fluentbit = 500;
78 users.users.fluentbit = {
80 home = "/var/lib/fluentbit";
81 uid = config.ids.uids.fluentbit;
84 extraGroups = [ "systemd-journal" ];
86 users.groups.fluentbit.gid = config.ids.gids.fluentbit;
93 ring.kvstore.store = "inmemory";
94 ring.instance_addr = "127.0.0.1";
95 replication_factor = 1;
96 path_prefix = "/var/lib/loki";
98 server.log_level = "warn";
100 reject_old_samples = false;
101 ingestion_rate_mb = 100;
102 ingestion_burst_size_mb = 200;
103 per_stream_rate_limit = "100MB";
104 per_stream_rate_limit_burst = "200MB";
107 schema_config.configs = [
110 store = "boltdb-shipper";
111 object_store = "filesystem";
113 index.prefix = "index_";
114 index.period = "24h";
119 systemd.services.postgresql.after = [
120 "var-lib-postgresql.mount"
121 "var-lib-postgresql-16.mount"
122 "persist-zfast-var-lib-postgresql.mount"
123 "persist-zfast-var-lib-postgresql-16.mount"
125 systemd.services.postgresql.unitConfig = {
127 "var-lib-postgresql.mount"
128 "var-lib-postgresql-16.mount"
129 "persist-zfast-var-lib-postgresql.mount"
130 "persist-zfast-var-lib-postgresql-16.mount"
134 services.postgresql = {
136 package = pkgs.postgresql_16;
137 ensureDatabases = [ "fluentbit" ];
141 ensureDBOwnership = true;
146 environment.systemPackages = [
149 systemd.services.fluent-bit = {
150 description = "Fluent-bit daemon";
151 wantedBy = [ "multi-user.target" ];
153 ExecStart = "${pkgs.fluent-bit}/bin/fluent-bit -c ${yamlFormat.generate "fluent.yaml" fluent-bit-config}";
156 SupplementaryGroups = [ "systemd-journal" ];