166 lines
4.8 KiB
Nix
Raw Normal View History

2024-02-08 23:21:10 +03:00
{ dnsmasq-list ? [], ... }:
2023-06-27 01:25:28 +03:00
let
nodeAddress = "192.168.0.5";
2024-01-21 16:32:37 +03:00
upstream-dns = "100.64.0.1";
2023-06-27 01:25:28 +03:00
in {
services.headscale-auth.blocky = {
ephemeral = true;
outPath = "/tmp/blocky-authkey";
2024-01-21 16:32:37 +03:00
before = [ "container@blocky.service" ];
};
2023-01-26 00:43:11 +03:00
containers.blocky = {
autoStart = true;
2024-01-21 16:32:37 +03:00
enableTun = true;
2023-01-26 00:43:11 +03:00
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 = [ "/" ];
2024-01-21 16:32:37 +03:00
bindMounts."/tmp/blocky-authkey".hostPath = "/tmp/blocky-authkey";
2024-02-08 23:21:10 +03:00
config = { config, lib, ... }:
2023-06-27 01:25:28 +03:00
let
grafanaPort = config.services.grafana.settings.server.http_port;
2023-12-18 02:08:29 +03:00
blockyPort = config.services.blocky.settings.ports.dns;
blockyHttpPort = config.services.blocky.settings.ports.http;
2023-06-27 01:25:28 +03:00
in {
2023-01-26 00:43:11 +03:00
networking = {
defaultGateway = "192.168.0.1";
hostName = "blocky-node";
2024-01-21 16:32:37 +03:00
nameservers = [ "127.0.0.1" ];
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
};
2024-01-21 20:36:34 +03:00
hosts = {
"192.168.0.10" = [ "wg.ataraxiadev.com" ];
};
2023-12-18 02:08:29 +03:00
};
2024-01-21 16:32:37 +03:00
# ephemeral tailscale node
services.tailscale = {
enable = true;
useRoutingFeatures = "client";
authKeyFile = "/tmp/blocky-authkey";
2024-01-21 20:36:34 +03:00
extraUpFlags = [
"--login-server=https://wg.ataraxiadev.com"
"--accept-dns=false"
"--advertise-exit-node=false"
];
2024-01-21 16:32:37 +03:00
};
systemd.services.tailscaled.serviceConfig.Environment = let
cfg = config.services.tailscale;
in lib.mkForce [
"PORT=${toString cfg.port}"
''"FLAGS=--tun ${lib.escapeShellArg cfg.interfaceName} --state=mem:"''
];
2023-12-18 02:08:29 +03:00
services.dnsmasq = {
enable = true;
alwaysKeepRunning = true;
resolveLocalQueries = false;
settings = {
port = 5353;
no-resolv = true;
no-hosts = true;
listen-address = "127.0.0.1";
no-dhcp-interface = "";
2024-01-21 17:40:07 +03:00
address = dnsmasq-list ++ [];
2023-12-18 02:08:29 +03:00
};
2023-01-26 00:43:11 +03:00
};
services.blocky = {
enable = true;
settings = {
2024-01-21 16:32:37 +03:00
upstream.default = [ upstream-dns ];
2023-12-18 02:08:29 +03:00
upstreamTimeout = "10s";
2024-01-21 17:40:23 +03:00
blocking = {
blackLists.telemetry = [ ../../misc/telemetry.hosts ];
clientGroupsBlock.default = [ "telemetry" ];
};
conditional = {
fallbackUpstream = true;
mapping = {
"ataraxiadev.com" = "127.0.0.1:5353";
};
};
# drop ipv6 requests
filtering.queryTypes = [ "AAAA" ];
2023-06-27 01:25:28 +03:00
caching = {
2023-12-18 02:08:29 +03:00
minTime = "0m";
2023-06-27 01:25:28 +03:00
maxTime = "12h";
cacheTimeNegative = "1m";
prefetching = true;
2023-01-26 00:43:11 +03:00
};
2023-12-18 02:08:29 +03:00
ports = {
dns = 53;
http = "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";
2023-12-18 02:08:29 +03:00
};
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-12-18 02:08:29 +03:00
targets = [ blockyHttpPort ];
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-12-18 02:08:29 +03:00
server = {
2023-06-27 01:25:28 +03:00
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
};
};
2024-01-21 16:32:37 +03:00
system.stateVersion = "23.11";
2023-01-26 00:43:11 +03:00
};
};
}