caddy support multi domain

This commit is contained in:
pazpi 2025-01-06 18:24:12 +01:00
parent f15e521895
commit fdcc829acf
13 changed files with 344 additions and 141 deletions

View file

@ -15,6 +15,14 @@ in
options.my.monitoring.grafana = {
enable = lib.mkEnableOption "Enable grafana as a data visualization";
adminPasswordFile = lib.mkOption {
default = "";
type = lib.types.str;
description = ''
Path to the file containing the admin password for Grafana
'';
};
proxy = {
enable = lib.mkEnableOption "Set the proxy entry for this service";
@ -26,6 +34,14 @@ in
'';
};
subdomain = lib.mkOption {
default = "grafana";
type = lib.types.str;
description = ''
The subdomain where Grafana is reachable
'';
};
host = lib.mkOption {
default = "localhost";
type = lib.types.str;
@ -41,13 +57,6 @@ in
config = lib.mkMerge [
(lib.mkIf cfg.enable {
age.secrets = {
grafana-admin-pwd = {
file = ../../secrets/grafana-admin-pwd.age;
owner = "grafana";
};
};
services = {
grafana = {
@ -63,13 +72,14 @@ in
};
security = {
admin_user = "pazpi";
admin_password = "$__file{${config.age.secrets.grafana-admin-pwd.path}}";
admin_password = "$__file{${cfg.adminPasswordFile}}";
};
server = {
domain = "grafana.neon-dory.ts.net";
# domain = "grafana.neon-dory.ts.net";
domain = cfg.proxy.domain;
http_addr = "0.0.0.0";
http_port = 3000;
# root_url = "https://grafana.${cfg.proxy.domain}";
root_url = "https://${cfg.proxy.subdomain}.${cfg.proxy.domain}";
enable_gzip = true;
};
users = {
@ -111,9 +121,9 @@ in
(lib.mkIf cfg.proxy.enable {
services.caddy = with cfg.proxy; {
virtualHosts."grafana.${domain}".extraConfig = ''
virtualHosts."${subdomain}.${domain}".extraConfig = ''
reverse_proxy http://${host}:3000
import cloudflare
import cloudflare_${domain}
'';
};
})

View file

@ -26,6 +26,14 @@ in
'';
};
subdomain = lib.mkOption {
default = "prometheus";
type = lib.types.str;
description = ''
The subdomain where Prometheus is reachable
'';
};
host = lib.mkOption {
default = "localhost";
type = lib.types.str;
@ -94,9 +102,9 @@ in
(lib.mkIf cfg.proxy.enable {
services.caddy = with cfg.proxy; {
virtualHosts."prometheus.${domain}".extraConfig = ''
virtualHosts."${subdomain}.${domain}".extraConfig = ''
reverse_proxy http://${host}:9090
import cloudflare
import cloudflare_${domain}
'';
};
})

View file

@ -52,7 +52,7 @@ in
services.caddy = with cfg.proxy; {
virtualHosts."up.${domain}".extraConfig = ''
reverse_proxy http://${host}:${port}
import cloudflare
import cloudflare_${domain}
'';
};
})