diff --git a/nix/grafana/default.nix b/nix/grafana/default.nix index 76471569..2a188e3f 100644 --- a/nix/grafana/default.nix +++ b/nix/grafana/default.nix @@ -12,12 +12,30 @@ in package = lib.mkPackageOption pkgs "grafana" { }; - port = lib.mkOption { + http_port = lib.mkOption { type = types.int; description = "Which port to run grafana on."; default = 3000; }; + domain = lib.mkOption { + type = types.str; + description = "The public facing domain name used to access grafana from a browser."; + default = "localhost"; + }; + + protocol = lib.mkOption { + type = types.str; + description = "Protocol (http, https, h2, socket)."; + default = "http"; + }; + + root_url = lib.mkOption { + type = types.str; + description = "The full public facing url."; + default = "${config.protocol}://${config.domain}:${builtins.toString config.http_port}"; + }; + dataDir = lib.mkOption { type = types.str; description = "Directory where grafana stores its logs and data."; @@ -44,14 +62,12 @@ in processes."${name}" = let grafanaConfig = lib.recursiveUpdate + config.extraConf { server = { - protocol = "http"; - http_port = config.port; - domain = "localhost"; + inherit (config) protocol http_port domain root_url; }; - } - config.extraConf; + }; grafanaConfigIni = iniFormat.generate "defaults.ini" grafanaConfig; startScript = pkgs.writeShellApplication { name = "start-grafana"; @@ -66,7 +82,7 @@ in { command = startScript; readiness_probe = { - exec.command = "${pkgs.curl}/bin/curl -f ${grafanaConfig.server.protocol}://${grafanaConfig.server.domain}:${builtins.toString grafanaConfig.server.http_port}/api/health"; + exec.command = "${pkgs.curl}/bin/curl -f ${config.root_url}/api/health"; initial_delay_seconds = 15; period_seconds = 10; timeout_seconds = 2; diff --git a/nix/grafana/grafana_test.nix b/nix/grafana/grafana_test.nix index 20145303..58936bbc 100644 --- a/nix/grafana/grafana_test.nix +++ b/nix/grafana/grafana_test.nix @@ -2,7 +2,7 @@ services.grafana."gf1" = { enable = true; - port = 3000; + http_port = 3000; extraConf = { security.admin_user = "patato"; security.admin_password = "potato"; @@ -21,8 +21,8 @@ '' ADMIN=${cfg.extraConf.security.admin_user} PASSWORD=${cfg.extraConf.security.admin_password} - curl -sSfN -u $ADMIN:$PASSWORD http://127.0.0.1:3000/api/org/users -i - curl -sSfN -u $ADMIN:$PASSWORD http://127.0.0.1:3000/api/org/users | grep admin\@localhost + curl -sSfN -u $ADMIN:$PASSWORD ${cfg.root_url}/api/org/users -i + curl -sSfN -u $ADMIN:$PASSWORD ${cfg.root_url}/api/org/users | grep admin\@localhost ''; name = "grafana-test"; };