infra/config/services/nginx.nix
2023-07-03 03:46:06 +02:00

38 lines
1.3 KiB
Nix

{pkgs, ...}: {
services.nginx = {
enable = true;
package = pkgs.nginxMainline;
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
# https://github.com/NixOS/nixpkgs/issues/180980#issuecomment-1179723811
virtualHosts = {
"defaultDummy404" = {
default = true;
serverName = "_";
locations."/".extraConfig = "return 404;";
locations."/.well-known/acme-challenge".root = "/var/lib/acme/acme-challenge";
};
"defaultDummy404ssl" = let
snakeoilCert = pkgs.runCommand "nginx-snakeoil-cert" {buildInputs = [pkgs.openssl];} ''
mkdir "$out"
openssl req -newkey rsa:4096 -x509 -sha256 -days 36500 -subj '/CN=Snakeoil CA' -nodes -out "$out/cert.pem" -keyout "$out/cert.key"
'';
in {
default = true;
serverName = "_";
locations."/".extraConfig = "return 404;";
locations."/.well-known/acme-challenge".root = "/var/lib/acme/acme-challenge";
# Dummy SSL config
onlySSL = true;
sslCertificate = "${snakeoilCert}/cert.pem";
sslCertificateKey = "${snakeoilCert}/cert.key";
};
};
};
networking.firewall.allowedTCPPorts = [80 443];
users.users.nginx.extraGroups = ["acme"];
}