summary refs log tree commit diff
diff options
context:
space:
mode:
authorLuke Granger-Brown <git@lukegb.com>2020-12-30 17:59:52 +0000
committerLuke Granger-Brown <git@lukegb.com>2020-12-30 17:59:52 +0000
commitd0a9e1ec8324bf4943b6aa680d8c0ac47b0b164e (patch)
tree91c761c152b59cda0a678921bab75285001cb8de
parentfafe7b24bfb32678084442906366e5304860d911 (diff)
downloadnixpkgs-d0a9e1ec8324bf4943b6aa680d8c0ac47b0b164e.tar
nixpkgs-d0a9e1ec8324bf4943b6aa680d8c0ac47b0b164e.tar.gz
nixpkgs-d0a9e1ec8324bf4943b6aa680d8c0ac47b0b164e.tar.bz2
nixpkgs-d0a9e1ec8324bf4943b6aa680d8c0ac47b0b164e.tar.lz
nixpkgs-d0a9e1ec8324bf4943b6aa680d8c0ac47b0b164e.tar.xz
nixpkgs-d0a9e1ec8324bf4943b6aa680d8c0ac47b0b164e.tar.zst
nixpkgs-d0a9e1ec8324bf4943b6aa680d8c0ac47b0b164e.zip
nixos/grafana: add support for declarative plugin installation
-rw-r--r--nixos/modules/services/monitoring/grafana.nix9
-rw-r--r--nixos/tests/grafana.nix14
2 files changed, 21 insertions, 2 deletions
diff --git a/nixos/modules/services/monitoring/grafana.nix b/nixos/modules/services/monitoring/grafana.nix
index b0c81a46d4d..c8515c4b898 100644
--- a/nixos/modules/services/monitoring/grafana.nix
+++ b/nixos/modules/services/monitoring/grafana.nix
@@ -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.";
diff --git a/nixos/tests/grafana.nix b/nixos/tests/grafana.nix
index 4b453ece7f1..4ba091b893f 100644
--- a/nixos/tests/grafana.nix
+++ b/nixos/tests/grafana.nix
@@ -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)