2021-02-14 12:06:45 +01:00
|
|
|
# Part of config shamelessly stolen from:
|
|
|
|
#
|
|
|
|
# https://github.com/delroth/infra.delroth.net
|
2021-07-13 00:57:33 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2021-02-14 12:06:45 +01:00
|
|
|
{
|
|
|
|
# Whenever something defines an nginx vhost, ensure that nginx defaults are
|
|
|
|
# properly set.
|
2021-06-01 14:28:42 +02:00
|
|
|
config = lib.mkIf ((builtins.attrNames config.services.nginx.virtualHosts) != [ "localhost" ]) {
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
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";
|
|
|
|
static_configs = [{
|
|
|
|
targets = [ "127.0.0.1:${toString config.services.prometheus.exporters.nginx.port}" ];
|
|
|
|
labels = {
|
|
|
|
instance = config.networking.hostName;
|
|
|
|
};
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2021-07-13 00:57:33 +02:00
|
|
|
security.acme = {
|
|
|
|
acceptTerms = true;
|
|
|
|
email = "antoine97.martin@gmail.com";
|
|
|
|
|
|
|
|
certs =
|
|
|
|
let
|
|
|
|
domain = config.networking.domain;
|
|
|
|
gandiKey = config.my.secrets.gandiKey;
|
|
|
|
in {
|
|
|
|
"${domain}" = {
|
|
|
|
extraDomainNames = [ "*.${domain}" ];
|
|
|
|
dnsProvider = "gandiv5";
|
|
|
|
credentialsFile = pkgs.writeText "gandi-creds.env" gandiKey;
|
|
|
|
group = "nginx";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-02-14 12:06:45 +01:00
|
|
|
};
|
|
|
|
}
|