1 { lib, pkgs, config, ... }:
6 cfg = config.services.grafana-image-renderer;
8 format = pkgs.formats.json { };
10 configFile = format.generate "grafana-image-renderer-config.json" cfg.settings;
12 options.services.grafana-image-renderer = {
13 enable = mkEnableOption (lib.mdDoc "grafana-image-renderer");
17 description = lib.mdDoc ''
18 The chromium to use for image rendering.
22 verbose = mkEnableOption (lib.mdDoc "verbosity for the service");
24 provisionGrafana = mkEnableOption (lib.mdDoc "Grafana configuration for grafana-image-renderer");
27 type = types.submodule {
28 freeformType = format.type;
35 description = lib.mdDoc ''
36 The TCP port to use for the rendering server.
39 logging.level = mkOption {
40 type = types.enum [ "error" "warning" "info" "debug" ];
42 description = lib.mdDoc ''
43 The log-level of the {file}`grafana-image-renderer.service`-unit.
50 type = types.ints.positive;
51 description = lib.mdDoc ''
52 Width of the PNG used to display the alerting graph.
57 type = types.ints.positive;
58 description = lib.mdDoc ''
59 Height of the PNG used to display the alerting graph.
64 type = types.enum [ "default" "reusable" "clustered" ];
65 description = lib.mdDoc ''
66 Rendering mode of `grafana-image-renderer`:
68 - `default:` Creates on browser-instance
69 per rendering request.
70 - `reusable:` One browser instance
71 will be started and reused for each rendering request.
72 - `clustered:` allows to precisely
73 configure how many browser-instances are supposed to be used. The values
74 for that mode can be declared in `rendering.clustering`.
78 type = types.listOf types.str;
79 default = [ "--no-sandbox" ];
80 description = lib.mdDoc ''
81 List of CLI flags passed to `chromium`.
90 description = lib.mdDoc ''
91 Configuration attributes for `grafana-image-renderer`.
93 See <https://github.com/grafana/grafana-image-renderer/blob/ce1f81438e5f69c7fd7c73ce08bab624c4c92e25/default.json>
99 config = mkIf cfg.enable {
101 { assertion = cfg.provisionGrafana -> config.services.grafana.enable;
103 To provision a Grafana instance to use grafana-image-renderer,
104 `services.grafana.enable` must be set to `true`!
109 services.grafana.settings.rendering = mkIf cfg.provisionGrafana {
110 url = "http://localhost:${toString cfg.settings.service.port}/render";
111 callback_url = "http://localhost:${toString config.services.grafana.port}";
114 services.grafana-image-renderer.chromium = mkDefault pkgs.chromium;
116 services.grafana-image-renderer.settings = {
117 rendering = mapAttrs (const mkDefault) {
118 chromeBin = "${cfg.chromium}/bin/chromium";
119 verboseLogging = cfg.verbose;
120 timezone = config.time.timeZone;
124 logging.level = mkIf cfg.verbose (mkDefault "debug");
125 metrics.enabled = mkDefault false;
129 systemd.services.grafana-image-renderer = {
130 wantedBy = [ "multi-user.target" ];
131 after = [ "network.target" ];
132 description = " A Grafana backend plugin that handles rendering of panels & dashboards to PNGs using headless browser (Chromium/Chrome)";
135 PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = "true";
141 ExecStart = "${pkgs.grafana-image-renderer}/bin/grafana-image-renderer server --config=${configFile}";
147 meta.maintainers = with maintainers; [ ma27 ];