1 { lib, pkgs, config, ... }:
3 cfg = config.services.grafana-image-renderer;
5 format = pkgs.formats.json { };
7 configFile = format.generate "grafana-image-renderer-config.json" cfg.settings;
9 options.services.grafana-image-renderer = {
10 enable = lib.mkEnableOption "grafana-image-renderer";
12 chromium = lib.mkOption {
13 type = lib.types.package;
15 The chromium to use for image rendering.
19 verbose = lib.mkEnableOption "verbosity for the service";
21 provisionGrafana = lib.mkEnableOption "Grafana configuration for grafana-image-renderer";
23 settings = lib.mkOption {
24 type = lib.types.submodule {
25 freeformType = format.type;
30 type = lib.types.port;
33 The TCP port to use for the rendering server.
36 logging.level = lib.mkOption {
37 type = lib.types.enum [ "error" "warning" "info" "debug" ];
40 The log-level of the {file}`grafana-image-renderer.service`-unit.
45 width = lib.mkOption {
47 type = lib.types.ints.positive;
49 Width of the PNG used to display the alerting graph.
52 height = lib.mkOption {
54 type = lib.types.ints.positive;
56 Height of the PNG used to display the alerting graph.
61 type = lib.types.enum [ "default" "reusable" "clustered" ];
63 Rendering mode of `grafana-image-renderer`:
65 - `default:` Creates on browser-instance
66 per rendering request.
67 - `reusable:` One browser instance
68 will be started and reused for each rendering request.
69 - `clustered:` allows to precisely
70 configure how many browser-instances are supposed to be used. The values
71 for that mode can be declared in `rendering.clustering`.
75 type = lib.types.listOf lib.types.str;
76 default = [ "--no-sandbox" ];
78 List of CLI flags passed to `chromium`.
88 Configuration attributes for `grafana-image-renderer`.
90 See <https://github.com/grafana/grafana-image-renderer/blob/ce1f81438e5f69c7fd7c73ce08bab624c4c92e25/default.json>
96 config = lib.mkIf cfg.enable {
98 { assertion = cfg.provisionGrafana -> config.services.grafana.enable;
100 To provision a Grafana instance to use grafana-image-renderer,
101 `services.grafana.enable` must be set to `true`!
106 services.grafana.settings.rendering = lib.mkIf cfg.provisionGrafana {
107 server_url = "http://localhost:${toString cfg.settings.service.port}/render";
108 callback_url = "http://${config.services.grafana.settings.server.http_addr}:${toString config.services.grafana.settings.server.http_port}";
111 services.grafana-image-renderer.chromium = lib.mkDefault pkgs.chromium;
113 services.grafana-image-renderer.settings = {
114 rendering = lib.mapAttrs (lib.const lib.mkDefault) {
115 chromeBin = "${cfg.chromium}/bin/chromium";
116 verboseLogging = cfg.verbose;
117 timezone = config.time.timeZone;
121 logging.level = lib.mkIf cfg.verbose (lib.mkDefault "debug");
122 metrics.enabled = lib.mkDefault false;
126 systemd.services.grafana-image-renderer = {
127 wantedBy = [ "multi-user.target" ];
128 after = [ "network.target" ];
129 description = " A Grafana backend plugin that handles rendering of panels & dashboards to PNGs using headless browser (Chromium/Chrome)";
132 PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = "true";
138 ExecStart = "${pkgs.grafana-image-renderer}/bin/grafana-image-renderer server --config=${configFile}";
144 meta.maintainers = with lib.maintainers; [ ma27 ];