Skip to content

Commit

Permalink
feat: Add options.declarativePlugins to grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
conscious-puppet authored and shivaraj-bh committed Oct 10, 2024
1 parent a5b0c00 commit 4ee18d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions nix/services/grafana.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ in
'';
};

declarativePlugins = lib.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 = "with pkgs.grafanaPlugins; [ grafana-piechart-panel ]";
# Make sure each plugin is added only once; otherwise building
# the link farm fails, since the same path is added multiple
# times.
apply = x: if lib.isList x then lib.unique x else x;
};

providers = lib.mkOption {
type = types.listOf yamlFormat.type;
description = ''
Expand Down Expand Up @@ -129,6 +140,7 @@ in
mkdir -p $out/plugins
'';
};
declarativePlugins = pkgs.linkFarm "grafana-plugins" (builtins.map (pkg: { name = pkg.pname; path = pkg; }) config.declarativePlugins);
startScript = pkgs.writeShellApplication {
name = "start-grafana";
runtimeInputs =
Expand All @@ -140,6 +152,7 @@ in
grafana server --config ${grafanaConfigIni} \
--homepath ${config.package}/share/grafana \
cfg:paths.data="$(readlink -m ${config.dataDir})" \
${lib.optionalString (config.declarativePlugins != null) "cfg:paths.plugins=${declarativePlugins}"} \
cfg:paths.provisioning="${provisioningConfig}"
'';
};
Expand Down
5 changes: 4 additions & 1 deletion nix/services/grafana_test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ in
};
}
];
declarativePlugins = with pkgs.grafanaPlugins; [ grafana-clickhouse-datasource ];
};

settings.processes.test =
Expand All @@ -71,7 +72,7 @@ in
{
# Tests based on: https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/grafana/basic.nix
command = pkgs.writeShellApplication {
runtimeInputs = [ cfg.package pkgs.gnugrep pkgs.curl pkgs.uutils-coreutils-noprefix ];
runtimeInputs = [ cfg.package pkgs.gnugrep pkgs.curl pkgs.uutils-coreutils-noprefix pkgs.jq ];
text =
''
ADMIN=${cfg.extraConf.security.admin_user}
Expand All @@ -83,6 +84,8 @@ in
# The dashboard provisioner was used to create a dashboard.
curl -sSfN -u $ADMIN:$PASSWORD $ROOT_URL/api/dashboards/uid/${dashboardUid} -i
curl -sSfN -u $ADMIN:$PASSWORD $ROOT_URL/api/dashboards/uid/${dashboardUid} | grep '"title":"${dashboardTitle}"'
# Test for extra plugins added to grafana.
curl -sSfN -u $ADMIN:$PASSWORD $ROOT_URL/api/plugins | jq '.[] | select(.id == "grafana-clickhouse-datasource") | .enabled' | grep "true"
'';
name = "grafana-test";
};
Expand Down

0 comments on commit 4ee18d6

Please sign in to comment.