2021-02-14 12:06:45 +01:00
|
|
|
# Part of config shamelessly stolen from:
|
|
|
|
#
|
|
|
|
# https://github.com/delroth/infra.delroth.net
|
|
|
|
{
|
2022-04-10 11:54:58 +02:00
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit
|
|
|
|
(lib)
|
2023-12-05 09:20:13 +01:00
|
|
|
mkEnableOption
|
2022-04-10 11:54:58 +02:00
|
|
|
mkIf
|
|
|
|
;
|
2023-12-05 09:20:13 +01:00
|
|
|
|
|
|
|
cfg = config.my.services.nginx;
|
2022-04-10 11:54:58 +02:00
|
|
|
in {
|
2023-12-05 09:20:13 +01:00
|
|
|
options.my.services.nginx = {
|
|
|
|
enable = mkEnableOption "Nginx reverse proxy";
|
|
|
|
};
|
|
|
|
|
2021-02-14 12:06:45 +01:00
|
|
|
# Whenever something defines an nginx vhost, ensure that nginx defaults are
|
|
|
|
# properly set.
|
2023-12-05 09:20:13 +01:00
|
|
|
config = mkIf (cfg.enable) {
|
2021-02-14 12:06:45 +01:00
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
statusPage = true; # For monitoring scraping.
|
|
|
|
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedTlsSettings = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
};
|
|
|
|
|
2022-04-10 11:54:58 +02:00
|
|
|
networking.firewall.allowedTCPPorts = [80 443];
|
2021-07-13 00:57:33 +02:00
|
|
|
|
2021-07-13 15:58:43 +02:00
|
|
|
services.prometheus = {
|
|
|
|
exporters.nginx = {
|
|
|
|
enable = true;
|
|
|
|
listenAddress = "127.0.0.1";
|
|
|
|
};
|
|
|
|
|
|
|
|
scrapeConfigs = [
|
|
|
|
{
|
|
|
|
job_name = "nginx";
|
2022-04-10 11:54:58 +02:00
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = ["127.0.0.1:${toString config.services.prometheus.exporters.nginx.port}"];
|
|
|
|
labels = {
|
|
|
|
instance = config.networking.hostName;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2021-07-13 15:58:43 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2021-07-13 00:57:33 +02:00
|
|
|
security.acme = {
|
|
|
|
acceptTerms = true;
|
2022-02-07 17:24:33 +01:00
|
|
|
defaults.email = "antoine97.martin@gmail.com";
|
2021-07-13 00:57:33 +02:00
|
|
|
|
2022-04-10 11:54:58 +02:00
|
|
|
certs = let
|
|
|
|
domain = config.networking.domain;
|
2022-06-12 17:18:58 +02:00
|
|
|
hostname = config.networking.hostName;
|
|
|
|
fqdn = "${hostname}.${domain}";
|
2022-04-10 11:54:58 +02:00
|
|
|
gandiKey = config.my.secrets.gandiKey;
|
|
|
|
in {
|
2022-06-12 17:18:58 +02:00
|
|
|
"${fqdn}" = {
|
2022-04-10 11:54:58 +02:00
|
|
|
dnsProvider = "gandiv5";
|
|
|
|
credentialsFile = config.age.secrets."gandi/api-key".path;
|
|
|
|
group = "nginx";
|
2021-07-13 00:57:33 +02:00
|
|
|
};
|
2022-04-10 11:54:58 +02:00
|
|
|
};
|
2021-07-13 00:57:33 +02:00
|
|
|
};
|
2021-02-14 12:06:45 +01:00
|
|
|
};
|
|
|
|
}
|