1 import ../make-test-python.nix ({ lib, pkgs, ... }:
4 inherit (lib) mkMerge nameValuePair maintainers;
10 analytics.reporting_enabled = false;
18 admin_user = "testadmin";
19 admin_password = "snakeoilpwd";
28 socket = { config, ... }: {
29 services.grafana.settings.server = {
31 socket = "/run/grafana/sock";
32 socket_gid = config.users.groups.nginx.gid;
35 users.users.grafana.extraGroups = [ "nginx" ];
39 recommendedProxySettings = true;
40 virtualHosts."_".locations."/".proxyPass = "http://unix:/run/grafana/sock";
44 declarativePlugins = {
45 services.grafana.declarativePlugins = [ pkgs.grafanaPlugins.grafana-clock-panel ];
49 services.grafana.settings.database = {
53 services.postgresql = {
55 ensureDatabases = [ "grafana" ];
58 ensureDBOwnership = true;
61 systemd.services.grafana.after = [ "postgresql.service" ];
65 services.grafana.settings.database.user = "grafana";
68 ensureDatabases = [ "grafana" ];
71 ensurePermissions."grafana.*" = "ALL PRIVILEGES";
73 package = pkgs.mariadb;
75 systemd.services.grafana.after = [ "mysql.service" ];
79 nodes = builtins.mapAttrs (_: val: mkMerge [ val baseGrafanaConf ]) extraNodeConfs;
81 name = "grafana-basic";
83 meta = with maintainers; {
84 maintainers = [ willibutz ];
92 with subtest("Declarative plugins installed"):
93 declarativePlugins.wait_for_unit("grafana.service")
94 declarativePlugins.wait_for_open_port(3000, addr="::1")
95 declarativePlugins.succeed(
96 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/plugins | grep grafana-clock-panel"
98 declarativePlugins.shutdown()
100 with subtest("Successful API query as admin user with sqlite db"):
101 sqlite.wait_for_unit("grafana.service")
102 sqlite.wait_for_open_port(3000)
103 print(sqlite.succeed(
104 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/org/users -i"
107 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/org/users | grep admin\@localhost"
111 with subtest("Successful API query as admin user with sqlite db listening on socket"):
112 socket.wait_for_unit("grafana.service")
113 socket.wait_for_open_port(80)
114 print(socket.succeed(
115 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]/api/org/users -i"
118 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]/api/org/users | grep admin\@localhost"
122 with subtest("Successful API query as admin user with postgresql db"):
123 postgresql.wait_for_unit("grafana.service")
124 postgresql.wait_for_unit("postgresql.service")
125 postgresql.wait_for_open_port(3000)
126 postgresql.wait_for_open_port(5432)
128 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/org/users | grep admin\@localhost"
130 postgresql.shutdown()
132 with subtest("Successful API query as admin user with mysql db"):
133 mysql.wait_for_unit("grafana.service")
134 mysql.wait_for_unit("mysql.service")
135 mysql.wait_for_open_port(3000)
136 mysql.wait_for_open_port(3306)
138 "curl -sSfN -u testadmin:snakeoilpwd http://[::1]:3000/api/org/users | grep admin\@localhost"