1 { config, lib, pkgs, ... }:
3 cfg = config.services.heartbeat;
5 heartbeatYml = pkgs.writeText "heartbeat.yml" ''
7 tags: ${builtins.toJSON cfg.tags}
16 services.heartbeat = {
18 enable = lib.mkEnableOption "heartbeat, uptime monitoring";
20 package = lib.mkPackageOption pkgs "heartbeat" {
21 example = "heartbeat7";
26 default = "heartbeat";
27 description = "Name of the beat";
31 type = lib.types.listOf lib.types.str;
33 description = "Tags to place on the shipped log messages";
36 stateDir = lib.mkOption {
38 default = "/var/lib/heartbeat";
39 description = "The state directory. heartbeat's own logs and other data are stored here.";
42 extraConfig = lib.mkOption {
43 type = lib.types.lines;
47 urls: ["http://localhost:9200"]
48 schedule: '@every 10s'
50 description = "Any other configuration options you want to add";
56 config = lib.mkIf cfg.enable {
58 systemd.tmpfiles.rules = [
59 "d '${cfg.stateDir}' - nobody nogroup - -"
62 systemd.services.heartbeat = with pkgs; {
63 description = "heartbeat log shipper";
64 wantedBy = [ "multi-user.target" ];
66 mkdir -p "${cfg.stateDir}"/{data,logs}
70 AmbientCapabilities = "cap_net_raw";
71 ExecStart = "${cfg.package}/bin/heartbeat -c \"${heartbeatYml}\" -path.data \"${cfg.stateDir}/data\" -path.logs \"${cfg.stateDir}/logs\"";