From 83fda1a391610ba499eada43080d851159bc6381 Mon Sep 17 00:00:00 2001 From: niten Date: Fri, 14 Jan 2022 16:07:04 -0800 Subject: [PATCH] Changes for Prometheus --- lib/fudo/domains.nix | 4 ++-- lib/fudo/prometheus.nix | 20 +++++++++++------ lib/lib/dns.nix | 42 +++++++++-------------------------- lib/types/network-host.nix | 9 +------- lib/types/zone-definition.nix | 16 ++++++------- 5 files changed, 33 insertions(+), 58 deletions(-) diff --git a/lib/fudo/domains.nix b/lib/fudo/domains.nix index e7a7264..83f714e 100644 --- a/lib/fudo/domains.nix +++ b/lib/fudo/domains.nix @@ -49,9 +49,9 @@ let }; gssapi-realm = mkOption { - type = str; + type = nullOr str; description = "GSSAPI (i.e. Kerberos) realm of this domain."; - default = toUpper domain; + default = null; }; kerberos-master = mkOption { diff --git a/lib/fudo/prometheus.nix b/lib/fudo/prometheus.nix index 450baaf..e74a343 100644 --- a/lib/fudo/prometheus.nix +++ b/lib/fudo/prometheus.nix @@ -7,11 +7,11 @@ let in { - options.fudo.prometheus = { + options.fudo.prometheus = with types; { enable = mkEnableOption "Fudo Prometheus Data-Gathering Server"; service-discovery-dns = mkOption { - type = with types; attrsOf (listOf str); + type = attrsOf (listOf str); description = '' A map of exporter type to a list of domains to use for service discovery. ''; @@ -28,7 +28,7 @@ in { }; static-targets = mkOption { - type = with types; attrsOf (listOf str); + type = attrsOf (listOf str); description = '' A map of exporter type to a list of host:ports from which to collect metrics. ''; @@ -44,7 +44,7 @@ in { }; docker-hosts = mkOption { - type = with types; listOf str; + type = listOf str; description = '' A list of explicit docker targets from which to gather node data. ''; @@ -52,7 +52,7 @@ in { }; push-url = mkOption { - type = with types; nullOr str; + type = nullOr str; description = '' The that services can use to manually push data. ''; @@ -60,7 +60,7 @@ in { }; push-address = mkOption { - type = with types; nullOr str; + type = nullOr str; description = '' The address on which to listen for incoming data. ''; @@ -68,10 +68,16 @@ in { }; hostname = mkOption { - type = with types; str; + type = str; description = "The hostname upon which Prometheus will serve."; example = "my-metrics-server.fudo.org"; }; + + state-directory = mkOption { + type = str; + description = "Directory at which to store Prometheus state."; + default = "/var/lib/prometheus"; + }; }; config = mkIf cfg.enable { diff --git a/lib/lib/dns.nix b/lib/lib/dns.nix index 983fd77..4adcf9b 100644 --- a/lib/lib/dns.nix +++ b/lib/lib/dns.nix @@ -51,13 +51,11 @@ let lines = splitString "\n" zonedata; in concatStringsSep "\n" (map formatter lines); - makeSrvRecords = protocol: service: records: let - service-blah = service; - record-blah = records; - in join-lines (map (record: - "_${service}._${protocol} IN SRV ${toString record.priority} ${ - toString record.weight - } ${toString record.port} ${record.host}.") records); + makeSrvRecords = protocol: service: records: + join-lines (map (record: + "_${service}._${protocol} IN SRV ${toString record.priority} ${ + toString record.weight + } ${toString record.port} ${record.host}.") records); makeSrvProtocolRecords = protocol: services: join-lines (mapAttrsToList (makeSrvRecords protocol) services); @@ -96,13 +94,10 @@ let "${hostname} IN A ${nethost-data.ipv4-address}"; aaaa-record = optional (nethost-data.ipv6-address != null) "${hostname} IN AAAA ${nethost-data.ipv6-address}"; - cname-record = optional (nethost-data.authoritative-hostname != null) - "${hostname} IN CNAME ${nethost-data.authoritative-hostname}"; description-record = optional (nethost-data.description != null) ''${hostname} IN TXT "${nethost-data.description}"''; in join-lines (a-record ++ aaaa-record ++ - cname-record ++ sshfp-records ++ description-record); @@ -114,26 +109,11 @@ let mxRecords = mxs: map (mx: "@ IN MX 10 ${mx}.") mxs; - nsRecords = domain: ns-hosts: - mapAttrsToList (host: _: "@ IN NS ${host}.${domain}.") ns-hosts; + nsRecords = map (ns-host: "@ IN NS ${ns-host}"); flatmapAttrsToList = f: attrs: foldr (a: b: a ++ b) [] (mapAttrsToList f attrs); - # nsARecords = _: ns-hosts: let - # a-record = host: hostOpts: optional (hostOpts.ipv4-address != null) - # "${host} IN A ${hostOpts.ipv4-address}"; - # aaaa-record = host: hostOpts: optional (hostOpts.ipv6-address != null) - # "${host} IN AAAA ${hostOpts.ipv6-address}"; - # description-record = host: hostOpts: optional (hostOpts.description != null) - # ''${host} IN TXT "${hostOpts.description}"''; - # in flatmapAttrsToList - # (host: hostOpts: - # (a-record host hostOpts) ++ - # (aaaa-record host hostOpts) ++ - # (description-record host hostOpts)) - # ns-hosts; - srvRecordPair = domain: protocol: service: record: { "_${service}._${protocol}.${domain}" = @@ -142,7 +122,7 @@ let } ${record.host}."; }; - domain-record = dom: zone: '' + domain-records = dom: zone: '' $ORIGIN ${dom}. $TTL ${zone.default-ttl} @@ -156,9 +136,7 @@ let ${optionalString (zone.gssapi-realm != null) ''_kerberos IN TXT "${zone.gssapi-realm}"''} - ${join-lines (nsRecords dom zone.nameservers)} - - ${join-lines (mapAttrsToList hostRecords zone.nameservers)} + ${join-lines (nsRecords zone.nameservers)} ${join-lines (mapAttrsToList makeSrvProtocolRecords zone.srv-records)} @@ -171,7 +149,7 @@ let ${join-lines zone.verbatim-dns-records} ${join-lines (mapAttrsToList - (subdom: subdomCfg: domain-record "${subdom}.${dom}" subdomCfg) + (subdom: subdomCfg: domain-records "${subdom}.${dom}" subdomCfg) zone.subdomains)} ''; @@ -203,6 +181,6 @@ in rec { 3w 5m) - ${domain-record dom zone} + ${domain-records dom zone} ''); } diff --git a/lib/types/network-host.nix b/lib/types/network-host.nix index 78b4400..87339ac 100644 --- a/lib/types/network-host.nix +++ b/lib/types/network-host.nix @@ -16,16 +16,9 @@ with lib; }; mac-address = mkOption { - type = nullOr types.str; - description = - "The MAC address of a given host, if desired for IP reservation."; - default = null; - }; - - authoritative-hostname = mkOption { type = nullOr str; description = - "The 'real' hostname of this host, i.e. CNAME. Prefer aliases!"; + "The MAC address of a given host, if desired for IP reservation."; default = null; }; diff --git a/lib/types/zone-definition.nix b/lib/types/zone-definition.nix index 9602bc2..fc8dc6c 100644 --- a/lib/types/zone-definition.nix +++ b/lib/types/zone-definition.nix @@ -48,15 +48,13 @@ let }; nameservers = mkOption { - type = attrsOf (submodule networkHostOpts); - description = "Map of domain nameservers to host data."; - example = { - "ns1" = { - ipv4-address = "1.1.1.1"; - ipv6-address = "1::1"; - }; - }; - default = {}; + type = listOf str; + description = "List of zone nameservers."; + example = [ + "ns1.fudo.org." + "10.0.0.1" + ]; + default = []; }; srv-records = mkOption {