nixos/services.grafana-image-renderer: remove with lib;

This commit is contained in:
Felix Buehler
2024-08-30 00:46:57 +02:00
parent e86917ad30
commit f1019c7adb

View File

@@ -1,7 +1,4 @@
{ lib, pkgs, config, ... }: { lib, pkgs, config, ... }:
with lib;
let let
cfg = config.services.grafana-image-renderer; cfg = config.services.grafana-image-renderer;
@@ -10,34 +7,34 @@ let
configFile = format.generate "grafana-image-renderer-config.json" cfg.settings; configFile = format.generate "grafana-image-renderer-config.json" cfg.settings;
in { in {
options.services.grafana-image-renderer = { options.services.grafana-image-renderer = {
enable = mkEnableOption "grafana-image-renderer"; enable = lib.mkEnableOption "grafana-image-renderer";
chromium = mkOption { chromium = lib.mkOption {
type = types.package; type = lib.types.package;
description = '' description = ''
The chromium to use for image rendering. The chromium to use for image rendering.
''; '';
}; };
verbose = mkEnableOption "verbosity for the service"; verbose = lib.mkEnableOption "verbosity for the service";
provisionGrafana = mkEnableOption "Grafana configuration for grafana-image-renderer"; provisionGrafana = lib.mkEnableOption "Grafana configuration for grafana-image-renderer";
settings = mkOption { settings = lib.mkOption {
type = types.submodule { type = lib.types.submodule {
freeformType = format.type; freeformType = format.type;
options = { options = {
service = { service = {
port = mkOption { port = lib.mkOption {
type = types.port; type = lib.types.port;
default = 8081; default = 8081;
description = '' description = ''
The TCP port to use for the rendering server. The TCP port to use for the rendering server.
''; '';
}; };
logging.level = mkOption { logging.level = lib.mkOption {
type = types.enum [ "error" "warning" "info" "debug" ]; type = lib.types.enum [ "error" "warning" "info" "debug" ];
default = "info"; default = "info";
description = '' description = ''
The log-level of the {file}`grafana-image-renderer.service`-unit. The log-level of the {file}`grafana-image-renderer.service`-unit.
@@ -45,23 +42,23 @@ in {
}; };
}; };
rendering = { rendering = {
width = mkOption { width = lib.mkOption {
default = 1000; default = 1000;
type = types.ints.positive; type = lib.types.ints.positive;
description = '' description = ''
Width of the PNG used to display the alerting graph. Width of the PNG used to display the alerting graph.
''; '';
}; };
height = mkOption { height = lib.mkOption {
default = 500; default = 500;
type = types.ints.positive; type = lib.types.ints.positive;
description = '' description = ''
Height of the PNG used to display the alerting graph. Height of the PNG used to display the alerting graph.
''; '';
}; };
mode = mkOption { mode = lib.mkOption {
default = "default"; default = "default";
type = types.enum [ "default" "reusable" "clustered" ]; type = lib.types.enum [ "default" "reusable" "clustered" ];
description = '' description = ''
Rendering mode of `grafana-image-renderer`: Rendering mode of `grafana-image-renderer`:
@@ -74,8 +71,8 @@ in {
for that mode can be declared in `rendering.clustering`. for that mode can be declared in `rendering.clustering`.
''; '';
}; };
args = mkOption { args = lib.mkOption {
type = types.listOf types.str; type = lib.types.listOf lib.types.str;
default = [ "--no-sandbox" ]; default = [ "--no-sandbox" ];
description = '' description = ''
List of CLI flags passed to `chromium`. List of CLI flags passed to `chromium`.
@@ -96,7 +93,7 @@ in {
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
assertions = [ assertions = [
{ assertion = cfg.provisionGrafana -> config.services.grafana.enable; { assertion = cfg.provisionGrafana -> config.services.grafana.enable;
message = '' message = ''
@@ -106,23 +103,23 @@ in {
} }
]; ];
services.grafana.settings.rendering = mkIf cfg.provisionGrafana { services.grafana.settings.rendering = lib.mkIf cfg.provisionGrafana {
server_url = "http://localhost:${toString cfg.settings.service.port}/render"; server_url = "http://localhost:${toString cfg.settings.service.port}/render";
callback_url = "http://${config.services.grafana.settings.server.http_addr}:${toString config.services.grafana.settings.server.http_port}"; callback_url = "http://${config.services.grafana.settings.server.http_addr}:${toString config.services.grafana.settings.server.http_port}";
}; };
services.grafana-image-renderer.chromium = mkDefault pkgs.chromium; services.grafana-image-renderer.chromium = lib.mkDefault pkgs.chromium;
services.grafana-image-renderer.settings = { services.grafana-image-renderer.settings = {
rendering = mapAttrs (const mkDefault) { rendering = lib.mapAttrs (lib.const lib.mkDefault) {
chromeBin = "${cfg.chromium}/bin/chromium"; chromeBin = "${cfg.chromium}/bin/chromium";
verboseLogging = cfg.verbose; verboseLogging = cfg.verbose;
timezone = config.time.timeZone; timezone = config.time.timeZone;
}; };
service = { service = {
logging.level = mkIf cfg.verbose (mkDefault "debug"); logging.level = lib.mkIf cfg.verbose (lib.mkDefault "debug");
metrics.enabled = mkDefault false; metrics.enabled = lib.mkDefault false;
}; };
}; };
@@ -144,5 +141,5 @@ in {
}; };
}; };
meta.maintainers = with maintainers; [ ma27 ]; meta.maintainers = with lib.maintainers; [ ma27 ];
} }