119 lines
3.4 KiB
Nix
Raw Normal View History

2023-06-27 01:25:28 +03:00
{ config, dns-mapping ? {}, ... }:
let
nodeAddress = "192.168.0.5";
wgAddress = "10.100.0.1";
wgConf = config.secrets.wg-hypervisor-dns.decrypted;
in {
boot.kernelModules = [ "wireguard" ];
secrets.wg-hypervisor-dns.services = [ "container@blocky.service" ];
2023-01-26 00:43:11 +03:00
containers.blocky = {
autoStart = true;
ephemeral = true;
privateNetwork = true;
hostBridge = "br0";
2023-06-27 01:25:28 +03:00
localAddress = "${nodeAddress}/24";
2023-01-26 00:43:11 +03:00
tmpfs = [ "/" ];
2023-06-27 01:25:28 +03:00
bindMounts."/var/secrets/${wgConf}" = {
hostPath = wgConf;
isReadOnly = true;
};
config = { config, pkgs, ... }:
let
grafanaPort = config.services.grafana.settings.server.http_port;
blockyPort = config.services.blocky.settings.port;
in {
2023-01-26 00:43:11 +03:00
networking = {
defaultGateway = "192.168.0.1";
hostName = "blocky-node";
2023-06-27 01:25:28 +03:00
nameservers = [];
2023-01-26 00:43:11 +03:00
enableIPv6 = false;
useHostResolvConf = false;
firewall = {
enable = true;
2023-06-27 01:25:28 +03:00
allowedTCPPorts = [ blockyPort grafanaPort ];
allowedUDPPorts = [ blockyPort ];
2023-01-26 00:43:11 +03:00
};
2023-06-27 01:25:28 +03:00
wg-quick.interfaces.wg0.configFile = "/var/secrets/${wgConf}";
2023-01-26 00:43:11 +03:00
};
services.blocky = {
enable = true;
settings = {
2023-06-27 01:25:28 +03:00
upstream.default = [ wgAddress ];
upstreamTimeout = "15s";
caching = {
minTime = "0m"; # TTL
maxTime = "12h";
cacheTimeNegative = "1m";
prefetching = true;
2023-01-26 00:43:11 +03:00
};
port = 53;
2023-06-27 01:25:28 +03:00
httpPort = "127.0.0.1:4000";
2023-01-26 00:43:11 +03:00
prometheus.enable = true;
2023-06-27 01:25:28 +03:00
queryLog.type = "console";
} // dns-mapping;
2023-01-26 00:43:11 +03:00
};
services.prometheus = {
2023-06-27 01:25:28 +03:00
enable = true;
listenAddress = "127.0.0.1";
globalConfig.scrape_interval = "15s";
globalConfig.evaluation_interval = "15s";
2023-01-26 00:43:11 +03:00
scrapeConfigs = [{
job_name = "blocky";
static_configs = [{
2023-06-27 01:25:28 +03:00
targets = [ config.services.blocky.settings.httpPort ];
2023-01-26 00:43:11 +03:00
}];
}];
};
services.grafana = {
2023-06-27 01:25:28 +03:00
enable = true;
2023-01-26 00:43:11 +03:00
settings = {
analytics.reporting_enabled = false;
2023-06-27 01:25:28 +03:00
server = rec {
domain = "${nodeAddress}:${toString grafanaPort}";
http_addr = nodeAddress;
2023-01-26 00:43:11 +03:00
enable_gzip = true;
};
2023-06-27 01:25:28 +03:00
panels.disable_sanitize_html = true;
2023-01-26 00:43:11 +03:00
};
2023-06-27 01:25:28 +03:00
provision = {
enable = true;
datasources.settings = {
datasources = [{
name = "Prometheus";
type = "prometheus";
access = "proxy";
orgId = 1;
uid = "Y4SSG429DWCGDQ3R";
url = "http://127.0.0.1:${toString config.services.prometheus.port}";
isDefault = true;
jsonData = {
graphiteVersion = "1.1";
tlsAuth = false;
tlsAuthWithCACert = false;
};
version = 1;
editable = true;
}];
};
dashboards = {
settings = {
providers = [{
name = "My Dashboards";
options.path = "/etc/grafana-dashboards";
}];
2023-01-26 00:43:11 +03:00
};
2023-06-27 01:25:28 +03:00
};
2023-01-26 00:43:11 +03:00
};
};
2023-06-27 01:25:28 +03:00
environment.etc = {
"grafana-dashboards/blocky_rev3.json" = {
source = ../../misc/grafana_blocky_rev3.json;
group = "grafana";
user = "grafana";
2023-01-26 00:43:11 +03:00
};
};
system.stateVersion = "23.05";
};
};
}