infra/config/services/nginx.nix

42 lines
1.3 KiB
Nix
Raw Normal View History

{pkgs, ...}: 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 {
2023-05-06 06:49:46 +02:00
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 444;";
2023-05-06 06:49:46 +02:00
locations."/.well-known/acme-challenge".root = "/var/lib/acme/acme-challenge";
};
"defaultDummy404ssl" = {
2023-05-06 06:49:46 +02:00
default = true;
serverName = "_";
locations."/".extraConfig = "return 444;";
2023-05-06 06:49:46 +02:00
locations."/.well-known/acme-challenge".root = "/var/lib/acme/acme-challenge";
# Dummy SSL config
onlySSL = true;
sslCertificate = "${snakeoilCert}/cert.pem";
sslCertificateKey = "${snakeoilCert}/cert.key";
};
};
};
2023-05-06 06:49:46 +02:00
networking.firewall.allowedTCPPorts = [80 443];
# allow nginx to access Acme secrets
2023-05-06 06:49:46 +02:00
users.users.nginx.extraGroups = ["acme"];
}