Add nixos-module
This commit is contained in:
parent
4710df2523
commit
2c3456e66b
2 changed files with 203 additions and 14 deletions
27
flake.nix
27
flake.nix
|
|
@ -50,7 +50,6 @@
|
||||||
# }
|
# }
|
||||||
# // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
|
# // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
|
||||||
# nixos-module = pkgs.testers.runNixOSTest (import ./nixos-test.nix self);
|
# nixos-module = pkgs.testers.runNixOSTest (import ./nixos-test.nix self);
|
||||||
# nixos-module-server = pkgs.testers.runNixOSTest (import ./nixos-test-server.nix self);
|
|
||||||
# }
|
# }
|
||||||
#);
|
#);
|
||||||
|
|
||||||
|
|
@ -62,19 +61,19 @@
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
#nixosModules.default =
|
nixosModules.default =
|
||||||
# {
|
{
|
||||||
# config,
|
lib,
|
||||||
# lib,
|
pkgs,
|
||||||
# pkgs,
|
...
|
||||||
# ...
|
}:
|
||||||
# }:
|
{
|
||||||
# {
|
imports = [ ./nixos-module.nix ];
|
||||||
# imports = [ ./nixos-module.nix ];
|
services.prometheus.exporters.dnstt.package =
|
||||||
# services.prometheus.exporters.dnstt.package =
|
lib.mkDefault
|
||||||
# lib.mkDefault
|
self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||||
# self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
};
|
||||||
|
|
||||||
# };
|
nixosModules.dnstt-exporter = self.nixosModules.default;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
190
nixos-module.nix
Normal file
190
nixos-module.nix
Normal file
|
|
@ -0,0 +1,190 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.services.prometheus.exporters.dnstt;
|
||||||
|
inherit (lib)
|
||||||
|
escapeShellArgs
|
||||||
|
mkDefault
|
||||||
|
mkEnableOption
|
||||||
|
mkIf
|
||||||
|
mkOption
|
||||||
|
optionals
|
||||||
|
types
|
||||||
|
;
|
||||||
|
|
||||||
|
listenAddress = "${cfg.listenAddress}:${toString cfg.port}";
|
||||||
|
args = [
|
||||||
|
"-web.listen-address"
|
||||||
|
listenAddress
|
||||||
|
"-web.telemetry-path"
|
||||||
|
cfg.telemetryPath
|
||||||
|
"-dnstt.port"
|
||||||
|
(toString cfg.dnsttPort)
|
||||||
|
]
|
||||||
|
++ lib.concatMap (domain: [
|
||||||
|
"-dnstt.domain"
|
||||||
|
domain
|
||||||
|
]) cfg.domains
|
||||||
|
++ optionals (cfg.geoip.countryDatabase != null) [
|
||||||
|
"-geoip.country-database"
|
||||||
|
cfg.geoip.countryDatabase
|
||||||
|
]
|
||||||
|
++ optionals (cfg.geoip.asnDatabase != null) [
|
||||||
|
"-geoip.asn-database"
|
||||||
|
cfg.geoip.asnDatabase
|
||||||
|
]
|
||||||
|
++ cfg.extraFlags;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.services.prometheus.exporters.dnstt = {
|
||||||
|
enable = mkEnableOption "the Prometheus DNSTT exporter";
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
description = ''
|
||||||
|
Package providing the `dnstt_exporter` binary.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
domains = mkOption {
|
||||||
|
type = types.nonEmptyListOf types.str;
|
||||||
|
example = [ "tunnel.example.com" ];
|
||||||
|
description = ''
|
||||||
|
DNSTT tunnel domains to observe. The exporter matches DNS query names
|
||||||
|
below these domains and decodes DNSTT session IDs from the query prefix.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
dnsttPort = mkOption {
|
||||||
|
type = types.port;
|
||||||
|
default = 53;
|
||||||
|
description = ''
|
||||||
|
UDP port where DNSTT DNS traffic is observed.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
port = mkOption {
|
||||||
|
type = types.port;
|
||||||
|
default = 9713;
|
||||||
|
description = ''
|
||||||
|
Port to listen on for Prometheus metrics.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
listenAddress = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "0.0.0.0";
|
||||||
|
description = ''
|
||||||
|
Address to listen on for Prometheus metrics.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
telemetryPath = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "/metrics";
|
||||||
|
description = ''
|
||||||
|
HTTP path under which to expose Prometheus metrics.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
geoip = {
|
||||||
|
countryDatabase = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
example = "/var/lib/GeoIP/GeoLite2-Country.mmdb";
|
||||||
|
description = ''
|
||||||
|
Optional MaxMind GeoIP2 or GeoLite2 Country database path. When set,
|
||||||
|
exported DNSTT metrics include a `country` label for the resolver
|
||||||
|
address seen by the server.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
asnDatabase = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
example = "/var/lib/GeoIP/GeoLite2-ASN.mmdb";
|
||||||
|
description = ''
|
||||||
|
Optional MaxMind GeoIP2 or GeoLite2 ASN database path. When set,
|
||||||
|
exported DNSTT metrics include an `asn` label for the resolver address
|
||||||
|
seen by the server.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
extraFlags = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
Extra command line flags to pass to `dnstt_exporter`.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
openFirewall = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Open the exporter metrics port in the firewall.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = cfg.domains != [ ];
|
||||||
|
message = "services.prometheus.exporters.dnstt.domains must contain at least one DNSTT domain.";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
|
||||||
|
|
||||||
|
systemd.services.prometheus-dnstt-exporter = {
|
||||||
|
description = "Prometheus DNSTT exporter";
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [ "network.target" ];
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = "${cfg.package}/bin/dnstt_exporter ${escapeShellArgs args}";
|
||||||
|
Restart = "always";
|
||||||
|
DynamicUser = true;
|
||||||
|
|
||||||
|
AmbientCapabilities = [ "CAP_NET_RAW" ];
|
||||||
|
CapabilityBoundingSet = [ "CAP_NET_RAW" ];
|
||||||
|
NoNewPrivileges = true;
|
||||||
|
|
||||||
|
LockPersonality = true;
|
||||||
|
MemoryDenyWriteExecute = true;
|
||||||
|
PrivateDevices = mkDefault false;
|
||||||
|
PrivateTmp = true;
|
||||||
|
ProtectClock = true;
|
||||||
|
ProtectControlGroups = true;
|
||||||
|
ProtectHome = true;
|
||||||
|
ProtectHostname = true;
|
||||||
|
ProtectKernelLogs = true;
|
||||||
|
ProtectKernelModules = true;
|
||||||
|
ProtectKernelTunables = true;
|
||||||
|
ProtectSystem = "strict";
|
||||||
|
RemoveIPC = true;
|
||||||
|
RestrictAddressFamilies = [
|
||||||
|
"AF_INET"
|
||||||
|
"AF_INET6"
|
||||||
|
"AF_PACKET"
|
||||||
|
];
|
||||||
|
RestrictNamespaces = true;
|
||||||
|
RestrictRealtime = true;
|
||||||
|
RestrictSUIDSGID = true;
|
||||||
|
SystemCallArchitectures = "native";
|
||||||
|
UMask = "0077";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
meta.maintainers = [ ];
|
||||||
|
meta.doc = false;
|
||||||
|
meta.buildDocsInSandbox = false;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue