2023-11-05 22:10:23 +08:00
|
|
|
{
|
2024-08-08 09:02:42 +08:00
|
|
|
inputs,
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: {
|
|
|
|
disabledModules = ["services/web-servers/traefik.nix"];
|
2023-11-05 22:10:23 +08:00
|
|
|
|
|
|
|
imports = [
|
|
|
|
"${inputs.nixpkgs-unstable}/nixos/modules/services/web-servers/traefik.nix"
|
2023-11-18 16:59:16 +08:00
|
|
|
./routers.nix
|
2023-12-19 09:21:05 +08:00
|
|
|
./middlewares.nix
|
2023-11-18 16:59:16 +08:00
|
|
|
./services.nix
|
2023-11-05 22:10:23 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
age.secrets.traefik = {
|
2024-06-03 21:18:56 +08:00
|
|
|
# Environment variables for porkbun dns challenge
|
2024-01-21 21:00:06 +08:00
|
|
|
rekeyFile = ./environment.age;
|
2023-11-05 22:10:23 +08:00
|
|
|
owner = "traefik";
|
|
|
|
group = "traefik";
|
|
|
|
};
|
|
|
|
|
2023-11-18 16:59:16 +08:00
|
|
|
systemd.services.traefik.serviceConfig = {
|
|
|
|
User = "traefik";
|
|
|
|
Group = "traefik";
|
|
|
|
LogsDirectory = "traefik";
|
|
|
|
LogsDirectoryMode = "0750";
|
|
|
|
};
|
|
|
|
|
2023-11-05 22:10:23 +08:00
|
|
|
# Reverse proxy and load balancer for HTTP and TCP-based applications
|
|
|
|
services.traefik = {
|
|
|
|
enable = true;
|
|
|
|
package = pkgs.unstable.traefik;
|
|
|
|
dataDir = "/var/lib/traefik";
|
|
|
|
environmentFiles = [
|
|
|
|
config.age.secrets.traefik.path
|
|
|
|
];
|
|
|
|
|
|
|
|
# The startup configuration
|
|
|
|
staticConfigOptions = {
|
|
|
|
api = {
|
|
|
|
# Enable the API in secure mode
|
|
|
|
insecure = false;
|
|
|
|
# Enable the dashboard
|
|
|
|
dashboard = true;
|
|
|
|
};
|
|
|
|
|
2023-11-18 16:59:16 +08:00
|
|
|
log = {
|
|
|
|
filePath = "/var/log/traefik/traefik.log";
|
2024-03-03 09:57:30 +08:00
|
|
|
level = "ERROR";
|
2023-11-18 16:59:16 +08:00
|
|
|
};
|
|
|
|
accessLog = {
|
|
|
|
filePath = "/var/log/traefik/access.log";
|
2023-11-20 12:06:51 +08:00
|
|
|
format = "json";
|
2023-11-18 16:59:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
# Install plugins
|
|
|
|
experimental.plugins = {
|
2024-06-20 22:16:50 +08:00
|
|
|
# Block or allow requests based on their country of origin.
|
2023-11-18 16:59:16 +08:00
|
|
|
geoblock = {
|
|
|
|
moduleName = "github.com/PascalMinder/geoblock";
|
|
|
|
version = "v0.2.7";
|
|
|
|
};
|
2024-06-20 22:16:50 +08:00
|
|
|
|
|
|
|
# Authorize or block requests from IPs based on there reputation and behaviour.
|
|
|
|
bouncer = {
|
|
|
|
moduleName = "github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin";
|
|
|
|
version = "v1.3.2";
|
|
|
|
};
|
2023-11-18 16:59:16 +08:00
|
|
|
};
|
|
|
|
|
2023-11-05 22:10:23 +08:00
|
|
|
# Network entry points into Traefik
|
|
|
|
entryPoints = {
|
|
|
|
# Hypertext Transfer Protocol
|
|
|
|
web = {
|
|
|
|
address = ":80";
|
|
|
|
# Redirect all incoming HTTP requests to HTTPS
|
|
|
|
http.redirections.entryPoint = {
|
|
|
|
to = "websecure";
|
|
|
|
scheme = "https";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
# Hypertext Transfer Protocol Secure
|
|
|
|
websecure = {
|
|
|
|
address = ":443";
|
|
|
|
# Requests wildcard SSL certs for our services
|
|
|
|
http.tls = {
|
|
|
|
certResolver = "lets-encrypt";
|
|
|
|
# List of domains in our network
|
|
|
|
domains = [
|
|
|
|
# Internal services
|
2024-08-08 09:02:42 +08:00
|
|
|
{
|
|
|
|
main = "kanto.dev";
|
|
|
|
sans = ["*.kanto.dev"];
|
2023-11-05 22:10:23 +08:00
|
|
|
}
|
|
|
|
# Public services
|
2024-08-08 09:02:42 +08:00
|
|
|
{
|
|
|
|
main = "sajenim.dev";
|
|
|
|
sans = ["*.sajenim.dev"];
|
2023-11-05 22:10:23 +08:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2024-06-06 20:45:31 +08:00
|
|
|
# Used to expose metrics
|
|
|
|
metrics = {
|
|
|
|
address = ":8082";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# Provide metrics for the prometheus backend
|
|
|
|
metrics = {
|
|
|
|
prometheus = {
|
|
|
|
entryPoint = "metrics";
|
2024-08-08 09:02:42 +08:00
|
|
|
buckets = ["0.1" "0.3" "1.2" "5.0"];
|
2024-06-06 20:45:31 +08:00
|
|
|
addEntryPointsLabels = true;
|
|
|
|
addRoutersLabels = true;
|
|
|
|
addServicesLabels = true;
|
|
|
|
};
|
2023-11-05 22:10:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
# Retrieve certificates from an ACME server
|
|
|
|
certificatesResolvers = {
|
|
|
|
# Setup a lets-encrypt environment
|
|
|
|
lets-encrypt.acme = {
|
|
|
|
# Email address used for registration
|
|
|
|
email = "its.jassy@pm.me";
|
|
|
|
# File or key used for certificate storage
|
|
|
|
storage = "/var/lib/traefik/acme.json";
|
|
|
|
# Certificate authority server to use
|
|
|
|
caServer = "https://acme-v02.api.letsencrypt.org/directory";
|
|
|
|
# Use a DNS-01 ACME challenge
|
|
|
|
dnsChallenge = {
|
2024-06-03 21:18:56 +08:00
|
|
|
provider = "porkbun";
|
2023-11-05 22:10:23 +08:00
|
|
|
resolvers = [
|
|
|
|
"1.1.1.1:53"
|
|
|
|
"8.8.8.8:53"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
# Disables SSL certificate verification between our traefik instance and our backend
|
|
|
|
serversTransport = {
|
|
|
|
insecureSkipVerify = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-01-21 21:00:06 +08:00
|
|
|
|
2024-06-06 20:45:31 +08:00
|
|
|
# Scrape our traefik metrics
|
|
|
|
services.prometheus.scrapeConfigs = [
|
|
|
|
{
|
|
|
|
job_name = "traefik";
|
2024-08-08 09:02:42 +08:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["127.0.0.1:8082"];
|
|
|
|
}
|
|
|
|
];
|
2024-06-06 20:45:31 +08:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-01-21 21:00:06 +08:00
|
|
|
# Persist our traefik data & logs
|
|
|
|
environment.persistence."/persist" = {
|
|
|
|
directories = [
|
2024-08-08 09:02:42 +08:00
|
|
|
{
|
|
|
|
directory = "/var/lib/traefik";
|
|
|
|
user = "traefik";
|
|
|
|
group = "traefik";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
directory = "/var/log/traefik";
|
|
|
|
user = "traefik";
|
|
|
|
group = "traefik";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
directory = "/plugins-storage";
|
|
|
|
user = "traefik";
|
|
|
|
group = "traefik";
|
|
|
|
}
|
2024-01-21 21:00:06 +08:00
|
|
|
];
|
2024-01-23 09:47:32 +08:00
|
|
|
hideMounts = true;
|
2024-01-21 21:00:06 +08:00
|
|
|
};
|
2023-11-05 22:10:23 +08:00
|
|
|
}
|