Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add options.declarativePlugins to grafana #356

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
srid marked this conversation as resolved.
Show resolved Hide resolved
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