at 23.11-pre 2.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.heartbeat; 7 8 heartbeatYml = pkgs.writeText "heartbeat.yml" '' 9 name: ${cfg.name} 10 tags: ${builtins.toJSON cfg.tags} 11 12 ${cfg.extraConfig} 13 ''; 14 15in 16{ 17 options = { 18 19 services.heartbeat = { 20 21 enable = mkEnableOption (lib.mdDoc "heartbeat"); 22 23 package = mkOption { 24 type = types.package; 25 default = pkgs.heartbeat; 26 defaultText = literalExpression "pkgs.heartbeat"; 27 example = literalExpression "pkgs.heartbeat7"; 28 description = lib.mdDoc '' 29 The heartbeat package to use. 30 ''; 31 }; 32 33 name = mkOption { 34 type = types.str; 35 default = "heartbeat"; 36 description = lib.mdDoc "Name of the beat"; 37 }; 38 39 tags = mkOption { 40 type = types.listOf types.str; 41 default = []; 42 description = lib.mdDoc "Tags to place on the shipped log messages"; 43 }; 44 45 stateDir = mkOption { 46 type = types.str; 47 default = "/var/lib/heartbeat"; 48 description = lib.mdDoc "The state directory. heartbeat's own logs and other data are stored here."; 49 }; 50 51 extraConfig = mkOption { 52 type = types.lines; 53 default = '' 54 heartbeat.monitors: 55 - type: http 56 urls: ["http://localhost:9200"] 57 schedule: '@every 10s' 58 ''; 59 description = lib.mdDoc "Any other configuration options you want to add"; 60 }; 61 62 }; 63 }; 64 65 config = mkIf cfg.enable { 66 67 systemd.tmpfiles.rules = [ 68 "d '${cfg.stateDir}' - nobody nogroup - -" 69 ]; 70 71 systemd.services.heartbeat = with pkgs; { 72 description = "heartbeat log shipper"; 73 wantedBy = [ "multi-user.target" ]; 74 preStart = '' 75 mkdir -p "${cfg.stateDir}"/{data,logs} 76 ''; 77 serviceConfig = { 78 User = "nobody"; 79 AmbientCapabilities = "cap_net_raw"; 80 ExecStart = "${cfg.package}/bin/heartbeat -c \"${heartbeatYml}\" -path.data \"${cfg.stateDir}/data\" -path.logs \"${cfg.stateDir}/logs\""; 81 }; 82 }; 83 }; 84}