From ad0a3f8cc2a631fba05421f89961f6a3df86e60d Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 4 Jun 2023 23:29:13 +0200 Subject: [PATCH] cluster/services/websites: refactor and register blackbox check --- cluster/services/websites/default.nix | 49 ++++++++++++++++++++++++--- cluster/services/websites/host.nix | 36 -------------------- 2 files changed, 45 insertions(+), 40 deletions(-) delete mode 100644 cluster/services/websites/host.nix diff --git a/cluster/services/websites/default.nix b/cluster/services/websites/default.nix index 4aca73e..f91bdfd 100644 --- a/cluster/services/websites/default.nix +++ b/cluster/services/websites/default.nix @@ -1,10 +1,51 @@ +{ depot, lib, tools, ... }: + +let + inherit (tools.meta) domain; + + importWebsites = expr: import expr { + tools = tools.nginx; + inherit (depot) packages; + }; + + websites = tools.nginx.mappers.mapSubdomains (importWebsites ./websites.nix); + + acmeUseDNS = name: conf: { + name = conf.useACMEHost or conf.serverName or name; + value = { + dnsProvider = "pdns"; + webroot = null; + }; + }; + + isACME = _: conf: conf ? enableACME && conf.enableACME; +in + { services.websites = { - nodes = { - host = [ "checkmate" "thunderskin" "VEGAS" "prophet" ]; + nodes.host = [ "checkmate" "thunderskin" "VEGAS" "prophet" ]; + nixos.host = { + services.nginx.virtualHosts = websites; + security.acme.certs = lib.mapAttrs' acmeUseDNS (lib.filterAttrs isACME websites); + consul.services.nginx = { + mode = "external"; + definition = { + name = "static-lb"; + address = depot.reflection.interfaces.primary.addrPublic; + port = 443; + checks = lib.singleton { + interval = "60s"; + tcp = "127.0.0.1:80"; + }; + }; + }; }; - nixos = { - host = ./host.nix; + }; + + monitoring.blackbox.targets = { + web = { + address = "https://www.${domain}"; + module = "https2xx"; }; }; } diff --git a/cluster/services/websites/host.nix b/cluster/services/websites/host.nix deleted file mode 100644 index d23b7c6..0000000 --- a/cluster/services/websites/host.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ depot, lib, tools, ... }: - -let - importWebsites = expr: import expr { - tools = tools.nginx; - inherit (depot) packages; - }; - - websites = tools.nginx.mappers.mapSubdomains (importWebsites ./websites.nix); - - acmeUseDNS = name: conf: { - name = conf.useACMEHost or conf.serverName or name; - value = { - dnsProvider = "pdns"; - webroot = null; - }; - }; - - isACME = _: conf: conf ? enableACME && conf.enableACME; -in { - services.nginx.virtualHosts = websites; - security.acme.certs = lib.mapAttrs' acmeUseDNS (lib.filterAttrs isACME websites); - - consul.services.nginx = { - mode = "external"; - definition = { - name = "static-lb"; - address = depot.reflection.interfaces.primary.addrPublic; - port = 443; - checks = lib.singleton { - interval = "60s"; - tcp = "127.0.0.1:80"; - }; - }; - }; -}