From 519e9072784f8ce4c330ba5a68126d91cb717839 Mon Sep 17 00:00:00 2001 From: daragh Date: Tue, 21 May 2024 02:23:10 +0100 Subject: [PATCH 1/7] Initial grafana setup --- applications/grafana.nix | 63 ++++++++++++++++++++++++++++++++++++++++ machines/_base.nix | 11 +++++++ machines/marvin.nix | 10 +++++++ 3 files changed, 84 insertions(+) create mode 100644 applications/grafana.nix diff --git a/applications/grafana.nix b/applications/grafana.nix new file mode 100644 index 0000000..cf99e11 --- /dev/null +++ b/applications/grafana.nix @@ -0,0 +1,63 @@ +{lib, ...}: +with lib; let + name = "grafana-server"; + cfg = config.server.grafana; +in { + imports = [ + ./acme.nix + ./dns.nix + ]; + + options.services.skynet.grafana = { + enable = mkEnableOption "Grafana Server"; + + host = { + ip = mkOption { + type = types.str; + }; + name = mkOption { + type = types.str; + }; + }; + + ip = mkOption { + type = types.str; + default = cfg.host.ip; + }; + + port = mkOption { + type = types.port; + default = 4444; + }; + }; + + config = { + services.grafana = { + enable = true; + domain = "grafana.skynet.ie"; + port = cfg.port; + addr = cfg.host.ip; + }; + + services.nginx.virtualHosts."${name}.skynet.ie" = { + forceSSL = true; + useACMEHost = "skynet"; + locations."/" = { + proxyPass = "https://localhost:${toString cfg.port}"; + proxyWebsockets = true; + }; + }; + + skynet_dns.records = [ + { + record = "${name}"; + r_type = "CNAME"; + value = cfg.host.name; + } + ]; + + skynet_acme.domains = [ + "${name}.skynet.ie" + ]; + }; +} diff --git a/machines/_base.nix b/machines/_base.nix index d83e75b..c3d3915 100644 --- a/machines/_base.nix +++ b/machines/_base.nix @@ -116,6 +116,17 @@ in { ]; }; + services.prometheus = { + exporters = { + node = { + enable = true; + # most of the collectors should be on by default + enabledCollectors = ["systemd"]; + port = 9002; + }; + }; + }; + # time on vendetta is strangely out of sync networking.timeServers = options.networking.timeServers.default ++ ["ie.pool.ntp.org"]; services.ntp.enable = true; diff --git a/machines/marvin.nix b/machines/marvin.nix index 1c4f57b..fdf59b1 100644 --- a/machines/marvin.nix +++ b/machines/marvin.nix @@ -25,6 +25,7 @@ Notes: groups_trusted = map (x: "@${x}") groups; in { imports = [ + ../applications/grafana.nix ]; deployment = { @@ -49,6 +50,15 @@ in { sudo_groups = groups; }; + services.skynet.grafana = { + enable = true; + + host = { + ip = ip_pub; + name = name; + }; + }; + skynet_dns.records = [ { record = name; -- 2.46.1 From 115535c386ed1eb72c34e62c7ffb2fd0eb1abfee Mon Sep 17 00:00:00 2001 From: daragh Date: Tue, 21 May 2024 02:25:37 +0100 Subject: [PATCH 2/7] fix cfg variable --- applications/grafana.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/grafana.nix b/applications/grafana.nix index cf99e11..2c6a575 100644 --- a/applications/grafana.nix +++ b/applications/grafana.nix @@ -1,7 +1,7 @@ {lib, ...}: with lib; let name = "grafana-server"; - cfg = config.server.grafana; + cfg = config.services.skynet.grafana; in { imports = [ ./acme.nix -- 2.46.1 From 70b1d6324db18d56bcd7006dd06690df0ce7448a Mon Sep 17 00:00:00 2001 From: daragh Date: Tue, 21 May 2024 02:51:15 +0100 Subject: [PATCH 3/7] rename grafana-server, move some things around --- applications/grafana.nix | 49 +++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/applications/grafana.nix b/applications/grafana.nix index 2c6a575..d8679ba 100644 --- a/applications/grafana.nix +++ b/applications/grafana.nix @@ -1,14 +1,19 @@ -{lib, ...}: +{ + lib, + config, + ... +}: with lib; let - name = "grafana-server"; + name = "grafana"; cfg = config.services.skynet.grafana; + port = 4444; in { imports = [ ./acme.nix ./dns.nix ]; - options.services.skynet.grafana = { + options.services.skynet."${name}" = { enable = mkEnableOption "Grafana Server"; host = { @@ -27,27 +32,11 @@ in { port = mkOption { type = types.port; - default = 4444; + default = port; }; }; - config = { - services.grafana = { - enable = true; - domain = "grafana.skynet.ie"; - port = cfg.port; - addr = cfg.host.ip; - }; - - services.nginx.virtualHosts."${name}.skynet.ie" = { - forceSSL = true; - useACMEHost = "skynet"; - locations."/" = { - proxyPass = "https://localhost:${toString cfg.port}"; - proxyWebsockets = true; - }; - }; - + config = mkIf cfg.enable { skynet_dns.records = [ { record = "${name}"; @@ -59,5 +48,23 @@ in { skynet_acme.domains = [ "${name}.skynet.ie" ]; + + services.grafana = { + enable = true; + domain = "grafana.skynet.ie"; + port = cfg.port; + addr = cfg.host.ip; + }; + + services.nginx.virtualHosts = { + "${name}.skynet.ie" = { + forceSSL = true; + useACMEHost = "skynet"; + locations."/" = { + proxyPass = "https://localhost:${toString cfg.port}"; + proxyWebsockets = true; + }; + }; + }; }; } -- 2.46.1 From 961509ddc8a16f3082581f09012c28ed93536790 Mon Sep 17 00:00:00 2001 From: daragh Date: Tue, 21 May 2024 02:57:32 +0100 Subject: [PATCH 4/7] fix: https to http --- applications/grafana.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/grafana.nix b/applications/grafana.nix index d8679ba..6eec760 100644 --- a/applications/grafana.nix +++ b/applications/grafana.nix @@ -61,7 +61,7 @@ in { forceSSL = true; useACMEHost = "skynet"; locations."/" = { - proxyPass = "https://localhost:${toString cfg.port}"; + proxyPass = "http://localhost:${toString cfg.port}"; proxyWebsockets = true; }; }; -- 2.46.1 From 739529caae46cb290b2842aab14bab01fb27d264 Mon Sep 17 00:00:00 2001 From: daragh Date: Tue, 21 May 2024 03:02:37 +0100 Subject: [PATCH 5/7] change grafana to {name} everywhere* --- applications/grafana.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/grafana.nix b/applications/grafana.nix index 6eec760..b120e89 100644 --- a/applications/grafana.nix +++ b/applications/grafana.nix @@ -5,7 +5,7 @@ }: with lib; let name = "grafana"; - cfg = config.services.skynet.grafana; + cfg = config.services.skynet."${name}"; port = 4444; in { imports = [ @@ -51,7 +51,7 @@ in { services.grafana = { enable = true; - domain = "grafana.skynet.ie"; + domain = "${name}.skynet.ie"; port = cfg.port; addr = cfg.host.ip; }; -- 2.46.1 From 2a605151f80d36dac1910407bdfdb83597d11bae Mon Sep 17 00:00:00 2001 From: daragh Date: Tue, 21 May 2024 03:21:50 +0100 Subject: [PATCH 6/7] remove prometheus from base --- machines/_base.nix | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/machines/_base.nix b/machines/_base.nix index c3d3915..d83e75b 100644 --- a/machines/_base.nix +++ b/machines/_base.nix @@ -116,17 +116,6 @@ in { ]; }; - services.prometheus = { - exporters = { - node = { - enable = true; - # most of the collectors should be on by default - enabledCollectors = ["systemd"]; - port = 9002; - }; - }; - }; - # time on vendetta is strangely out of sync networking.timeServers = options.networking.timeServers.default ++ ["ie.pool.ntp.org"]; services.ntp.enable = true; -- 2.46.1 From 4ce0f69fb3d18a1ea97afdf445b8b16b7afb597e Mon Sep 17 00:00:00 2001 From: daragh Date: Tue, 21 May 2024 03:40:58 +0100 Subject: [PATCH 7/7] remove redudnant options --- applications/grafana.nix | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/applications/grafana.nix b/applications/grafana.nix index b120e89..e3057d1 100644 --- a/applications/grafana.nix +++ b/applications/grafana.nix @@ -24,16 +24,6 @@ in { type = types.str; }; }; - - ip = mkOption { - type = types.str; - default = cfg.host.ip; - }; - - port = mkOption { - type = types.port; - default = port; - }; }; config = mkIf cfg.enable { @@ -52,7 +42,7 @@ in { services.grafana = { enable = true; domain = "${name}.skynet.ie"; - port = cfg.port; + port = port; addr = cfg.host.ip; }; @@ -61,7 +51,7 @@ in { forceSSL = true; useACMEHost = "skynet"; locations."/" = { - proxyPass = "http://localhost:${toString cfg.port}"; + proxyPass = "http://localhost:${toString port}"; proxyWebsockets = true; }; }; -- 2.46.1