at 23.11-pre 3.4 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.trickster; 7in 8{ 9 imports = [ 10 (mkRenamedOptionModule [ "services" "trickster" "origin" ] [ "services" "trickster" "origin-url" ]) 11 ]; 12 13 options = { 14 services.trickster = { 15 enable = mkOption { 16 type = types.bool; 17 default = false; 18 description = lib.mdDoc '' 19 Enable Trickster. 20 ''; 21 }; 22 23 package = mkOption { 24 type = types.package; 25 default = pkgs.trickster; 26 defaultText = literalExpression "pkgs.trickster"; 27 description = lib.mdDoc '' 28 Package that should be used for trickster. 29 ''; 30 }; 31 32 configFile = mkOption { 33 type = types.nullOr types.path; 34 default = null; 35 description = lib.mdDoc '' 36 Path to configuration file. 37 ''; 38 }; 39 40 instance-id = mkOption { 41 type = types.nullOr types.int; 42 default = null; 43 description = lib.mdDoc '' 44 Instance ID for when running multiple processes (default null). 45 ''; 46 }; 47 48 log-level = mkOption { 49 type = types.str; 50 default = "info"; 51 description = lib.mdDoc '' 52 Level of Logging to use (debug, info, warn, error) (default "info"). 53 ''; 54 }; 55 56 metrics-port = mkOption { 57 type = types.port; 58 default = 8082; 59 description = lib.mdDoc '' 60 Port that the /metrics endpoint will listen on. 61 ''; 62 }; 63 64 origin-type = mkOption { 65 type = types.enum [ "prometheus" "influxdb" ]; 66 default = "prometheus"; 67 description = lib.mdDoc '' 68 Type of origin (prometheus, influxdb) 69 ''; 70 }; 71 72 origin-url = mkOption { 73 type = types.str; 74 default = "http://prometheus:9090"; 75 description = lib.mdDoc '' 76 URL to the Origin. Enter it like you would in grafana, e.g., http://prometheus:9090 (default http://prometheus:9090). 77 ''; 78 }; 79 80 profiler-port = mkOption { 81 type = types.nullOr types.port; 82 default = null; 83 description = lib.mdDoc '' 84 Port that the /debug/pprof endpoint will listen on. 85 ''; 86 }; 87 88 proxy-port = mkOption { 89 type = types.port; 90 default = 9090; 91 description = lib.mdDoc '' 92 Port that the Proxy server will listen on. 93 ''; 94 }; 95 96 }; 97 }; 98 99 config = mkIf cfg.enable { 100 systemd.services.trickster = { 101 description = "Reverse proxy cache and time series dashboard accelerator"; 102 after = [ "network.target" ]; 103 wantedBy = [ "multi-user.target" ]; 104 serviceConfig = { 105 DynamicUser = true; 106 ExecStart = '' 107 ${cfg.package}/bin/trickster \ 108 -log-level ${cfg.log-level} \ 109 -metrics-port ${toString cfg.metrics-port} \ 110 -origin-type ${cfg.origin-type} \ 111 -origin-url ${cfg.origin-url} \ 112 -proxy-port ${toString cfg.proxy-port} \ 113 ${optionalString (cfg.configFile != null) "-config ${cfg.configFile}"} \ 114 ${optionalString (cfg.profiler-port != null) "-profiler-port ${cfg.profiler-port}"} \ 115 ${optionalString (cfg.instance-id != null) "-instance-id ${cfg.instance-id}"} 116 ''; 117 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 118 Restart = "always"; 119 }; 120 }; 121 }; 122 123 meta.maintainers = with maintainers; [ _1000101 ]; 124 125}