at 17.09-beta 1.9 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.journalbeat; 7 8 journalbeatYml = pkgs.writeText "journalbeat.yml" '' 9 name: ${cfg.name} 10 tags: ${builtins.toJSON cfg.tags} 11 12 journalbeat.cursor_state_file: ${cfg.stateDir}/cursor-state 13 14 ${cfg.extraConfig} 15 ''; 16 17in 18{ 19 options = { 20 21 services.journalbeat = { 22 23 enable = mkEnableOption "journalbeat"; 24 25 name = mkOption { 26 type = types.str; 27 default = "journalbeat"; 28 description = "Name of the beat"; 29 }; 30 31 tags = mkOption { 32 type = types.listOf types.str; 33 default = []; 34 description = "Tags to place on the shipped log messages"; 35 }; 36 37 stateDir = mkOption { 38 type = types.str; 39 default = "/var/lib/journalbeat"; 40 description = "The state directory. Journalbeat's own logs and other data are stored here."; 41 }; 42 43 extraConfig = mkOption { 44 type = types.lines; 45 default = '' 46 journalbeat: 47 seek_position: cursor 48 cursor_seek_fallback: tail 49 write_cursor_state: true 50 cursor_flush_period: 5s 51 clean_field_names: true 52 convert_to_numbers: false 53 move_metadata_to_field: journal 54 default_type: journal 55 ''; 56 description = "Any other configuration options you want to add"; 57 }; 58 59 }; 60 }; 61 62 config = mkIf cfg.enable { 63 64 systemd.services.journalbeat = with pkgs; { 65 description = "Journalbeat log shipper"; 66 wantedBy = [ "multi-user.target" ]; 67 preStart = '' 68 mkdir -p ${cfg.stateDir}/data 69 mkdir -p ${cfg.stateDir}/logs 70 ''; 71 serviceConfig = { 72 ExecStart = "${pkgs.journalbeat}/bin/journalbeat -c ${journalbeatYml} -path.data ${cfg.stateDir}/data -path.logs ${cfg.stateDir}/logs"; 73 }; 74 }; 75 }; 76}