at master 2.7 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.services.vector; 9in 10{ 11 options.services.vector = { 12 enable = lib.mkEnableOption "Vector, a high-performance observability data pipeline"; 13 14 package = lib.mkPackageOption pkgs "vector" { }; 15 16 journaldAccess = lib.mkOption { 17 type = lib.types.bool; 18 default = false; 19 description = '' 20 Enable Vector to access journald. 21 ''; 22 }; 23 24 gracefulShutdownLimitSecs = lib.mkOption { 25 type = lib.types.ints.positive; 26 default = 60; 27 description = '' 28 Set the duration in seconds to wait for graceful shutdown after SIGINT or SIGTERM are received. 29 After the duration has passed, Vector will force shutdown. 30 ''; 31 }; 32 33 validateConfig = lib.mkOption { 34 type = lib.types.bool; 35 default = true; 36 description = '' 37 Enable the checking of the vector config during build time. This should be disabled when interpolating environment variables. 38 ''; 39 }; 40 41 settings = lib.mkOption { 42 type = (pkgs.formats.json { }).type; 43 default = { }; 44 description = '' 45 Specify the configuration for Vector in Nix. 46 ''; 47 }; 48 }; 49 50 config = lib.mkIf cfg.enable { 51 # for cli usage 52 environment.systemPackages = [ cfg.package ]; 53 54 systemd.services.vector = { 55 description = "Vector event and log aggregator"; 56 wantedBy = [ "multi-user.target" ]; 57 after = [ "network-online.target" ]; 58 requires = [ "network-online.target" ]; 59 serviceConfig = 60 let 61 format = pkgs.formats.toml { }; 62 conf = format.generate "vector.toml" cfg.settings; 63 validatedConfig = 64 file: 65 pkgs.runCommand "validate-vector-conf" 66 { 67 nativeBuildInputs = [ cfg.package ]; 68 } 69 '' 70 vector validate --no-environment "${file}" 71 ln -s "${file}" "$out" 72 ''; 73 in 74 { 75 ExecStart = "${lib.getExe cfg.package} --config ${ 76 if cfg.validateConfig then (validatedConfig conf) else conf 77 } --graceful-shutdown-limit-secs ${builtins.toString cfg.gracefulShutdownLimitSecs}"; 78 DynamicUser = true; 79 Restart = "always"; 80 StateDirectory = "vector"; 81 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 82 AmbientCapabilities = "CAP_NET_BIND_SERVICE"; 83 # This group is required for accessing journald. 84 SupplementaryGroups = lib.mkIf cfg.journaldAccess "systemd-journal"; 85 }; 86 unitConfig = { 87 StartLimitIntervalSec = 10; 88 StartLimitBurst = 5; 89 }; 90 }; 91 }; 92}