2021-01-01 15:51:18 +00:00
|
|
|
{ lib, pkgs, config, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.grafana-image-renderer;
|
|
|
|
|
|
|
|
format = pkgs.formats.json { };
|
|
|
|
|
|
|
|
configFile = format.generate "grafana-image-renderer-config.json" cfg.settings;
|
|
|
|
in {
|
|
|
|
options.services.grafana-image-renderer = {
|
2022-08-28 19:18:44 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "grafana-image-renderer");
|
2021-01-01 15:51:18 +00:00
|
|
|
|
|
|
|
chromium = mkOption {
|
|
|
|
type = types.package;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-01-01 15:51:18 +00:00
|
|
|
The chromium to use for image rendering.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-08-28 19:18:44 +00:00
|
|
|
verbose = mkEnableOption (lib.mdDoc "verbosity for the service");
|
2021-01-01 15:51:18 +00:00
|
|
|
|
2022-08-28 19:18:44 +00:00
|
|
|
provisionGrafana = mkEnableOption (lib.mdDoc "Grafana configuration for grafana-image-renderer");
|
2021-01-01 15:51:18 +00:00
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = format.type;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
service = {
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8081;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-01-01 15:51:18 +00:00
|
|
|
The TCP port to use for the rendering server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
logging.level = mkOption {
|
|
|
|
type = types.enum [ "error" "warning" "info" "debug" ];
|
|
|
|
default = "info";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
The log-level of the {file}`grafana-image-renderer.service`-unit.
|
2021-01-01 15:51:18 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
rendering = {
|
|
|
|
width = mkOption {
|
|
|
|
default = 1000;
|
|
|
|
type = types.ints.positive;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-01-01 15:51:18 +00:00
|
|
|
Width of the PNG used to display the alerting graph.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
height = mkOption {
|
|
|
|
default = 500;
|
|
|
|
type = types.ints.positive;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-01-01 15:51:18 +00:00
|
|
|
Height of the PNG used to display the alerting graph.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
mode = mkOption {
|
|
|
|
default = "default";
|
|
|
|
type = types.enum [ "default" "reusable" "clustered" ];
|
2022-08-29 21:34:22 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Rendering mode of `grafana-image-renderer`:
|
|
|
|
|
|
|
|
- `default:` Creates on browser-instance
|
|
|
|
per rendering request.
|
|
|
|
- `reusable:` One browser instance
|
|
|
|
will be started and reused for each rendering request.
|
|
|
|
- `clustered:` allows to precisely
|
2021-01-01 15:51:18 +00:00
|
|
|
configure how many browser-instances are supposed to be used. The values
|
2022-08-29 21:34:22 +00:00
|
|
|
for that mode can be declared in `rendering.clustering`.
|
2021-01-01 15:51:18 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
args = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "--no-sandbox" ];
|
2022-08-15 05:16:25 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
List of CLI flags passed to `chromium`.
|
2021-01-01 15:51:18 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
default = {};
|
|
|
|
|
2022-08-15 05:16:25 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Configuration attributes for `grafana-image-renderer`.
|
2021-01-01 15:51:18 +00:00
|
|
|
|
2022-08-15 05:16:25 +00:00
|
|
|
See <https://github.com/grafana/grafana-image-renderer/blob/ce1f81438e5f69c7fd7c73ce08bab624c4c92e25/default.json>
|
2021-01-01 15:51:18 +00:00
|
|
|
for supported values.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
{ assertion = cfg.provisionGrafana -> config.services.grafana.enable;
|
|
|
|
message = ''
|
|
|
|
To provision a Grafana instance to use grafana-image-renderer,
|
|
|
|
`services.grafana.enable` must be set to `true`!
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2022-10-11 23:17:42 +00:00
|
|
|
services.grafana.settings.rendering = mkIf cfg.provisionGrafana {
|
|
|
|
url = "http://localhost:${toString cfg.settings.service.port}/render";
|
|
|
|
callback_url = "http://localhost:${toString config.services.grafana.port}";
|
2021-01-01 15:51:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.grafana-image-renderer.chromium = mkDefault pkgs.chromium;
|
|
|
|
|
|
|
|
services.grafana-image-renderer.settings = {
|
|
|
|
rendering = mapAttrs (const mkDefault) {
|
|
|
|
chromeBin = "${cfg.chromium}/bin/chromium";
|
|
|
|
verboseLogging = cfg.verbose;
|
|
|
|
timezone = config.time.timeZone;
|
|
|
|
};
|
|
|
|
|
2021-01-18 17:40:30 +00:00
|
|
|
service = {
|
2021-01-01 15:51:18 +00:00
|
|
|
logging.level = mkIf cfg.verbose (mkDefault "debug");
|
|
|
|
metrics.enabled = mkDefault false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.grafana-image-renderer = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
description = " A Grafana backend plugin that handles rendering of panels & dashboards to PNGs using headless browser (Chromium/Chrome)";
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = "true";
|
|
|
|
};
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ExecStart = "${pkgs.grafana-image-renderer}/bin/grafana-image-renderer server --config=${configFile}";
|
|
|
|
Restart = "always";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ ma27 ];
|
|
|
|
}
|