Skip to content

Commit

Permalink
make root_url an internal option
Browse files Browse the repository at this point in the history
  • Loading branch information
conscious-puppet committed Feb 21, 2024
1 parent a4f3ae8 commit 1760bc1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
30 changes: 23 additions & 7 deletions nix/grafana/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand All @@ -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";
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions nix/grafana/grafana_test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
services.grafana."gf1" =
{
enable = true;
port = 3000;
http_port = 3000;
extraConf = {
security.admin_user = "patato";
security.admin_password = "potato";
Expand All @@ -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";
};
Expand Down

0 comments on commit 1760bc1

Please sign in to comment.