mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-22 14:45:27 +00:00
nixos/grafana: add support for declarative plugin installation
This commit is contained in:
parent
fafe7b24bf
commit
d0a9e1ec83
|
@ -5,10 +5,11 @@ with lib;
|
|||
let
|
||||
cfg = config.services.grafana;
|
||||
opt = options.services.grafana;
|
||||
declarativePlugins = pkgs.linkFarm "grafana-plugins" (builtins.map (pkg: { name = pkg.pname; path = pkg; }) cfg.declarativePlugins);
|
||||
|
||||
envOptions = {
|
||||
PATHS_DATA = cfg.dataDir;
|
||||
PATHS_PLUGINS = "${cfg.dataDir}/plugins";
|
||||
PATHS_PLUGINS = if builtins.isNull cfg.declarativePlugins then "${cfg.dataDir}/plugins" else declarativePlugins;
|
||||
PATHS_LOGS = "${cfg.dataDir}/log";
|
||||
|
||||
SERVER_PROTOCOL = cfg.protocol;
|
||||
|
@ -260,6 +261,12 @@ in {
|
|||
defaultText = "pkgs.grafana";
|
||||
type = types.package;
|
||||
};
|
||||
declarativePlugins = mkOption {
|
||||
type = with types; nullOr (listOf path);
|
||||
default = null;
|
||||
description = "If non-null, then a list of packages containing Grafana plugins to install. If set, plugins cannot be manually installed.";
|
||||
example = literalExample "with pkgs.grafanaPlugins; [ grafana-piechart-panel ]";
|
||||
};
|
||||
|
||||
dataDir = mkOption {
|
||||
description = "Data directory.";
|
||||
|
|
|
@ -17,6 +17,10 @@ let
|
|||
};
|
||||
|
||||
extraNodeConfs = {
|
||||
declarativePlugins = {
|
||||
services.grafana.declarativePlugins = [ pkgs.grafanaPlugins.grafana-clock-panel ];
|
||||
};
|
||||
|
||||
postgresql = {
|
||||
services.grafana.database = {
|
||||
host = "127.0.0.1:5432";
|
||||
|
@ -52,7 +56,7 @@ let
|
|||
nameValuePair dbName (mkMerge [
|
||||
baseGrafanaConf
|
||||
(extraNodeConfs.${dbName} or {})
|
||||
])) [ "sqlite" "postgresql" "mysql" ]);
|
||||
])) [ "sqlite" "declarativePlugins" "postgresql" "mysql" ]);
|
||||
|
||||
in {
|
||||
name = "grafana";
|
||||
|
@ -66,6 +70,14 @@ in {
|
|||
testScript = ''
|
||||
start_all()
|
||||
|
||||
with subtest("Declarative plugins installed"):
|
||||
declarativePlugins.wait_for_unit("grafana.service")
|
||||
declarativePlugins.wait_for_open_port(3000)
|
||||
declarativePlugins.succeed(
|
||||
"curl -sSfN -u testadmin:snakeoilpwd http://127.0.0.1:3000/api/plugins | grep -q grafana-clock-panel"
|
||||
)
|
||||
declarativePlugins.shutdown()
|
||||
|
||||
with subtest("Successful API query as admin user with sqlite db"):
|
||||
sqlite.wait_for_unit("grafana.service")
|
||||
sqlite.wait_for_open_port(3000)
|
||||
|
|
Loading…
Reference in a new issue