2024-05-20 20:52:57 -04:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
let
|
2024-06-24 11:38:28 -04:00
|
|
|
cfg = config.aux.system.services.nginx;
|
2024-05-20 20:52:57 -04:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2024-06-24 11:38:28 -04:00
|
|
|
aux.system.services.nginx = {
|
2024-05-20 20:52:57 -04:00
|
|
|
autostart = lib.mkEnableOption (lib.mdDoc "Whether to autostart Nginx at boot.");
|
|
|
|
enable = lib.mkEnableOption (lib.mdDoc "Enable the Nginx web server.");
|
|
|
|
|
|
|
|
virtualHosts = lib.mkOption {
|
|
|
|
default = { };
|
|
|
|
type = lib.types.attrs;
|
|
|
|
description = "Virtualhost configurations for Nginx.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-02 16:19:15 -04:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
2024-05-20 20:52:57 -04:00
|
|
|
|
2024-07-02 16:19:15 -04:00
|
|
|
# Use recommended settings per https://nixos.wiki/wiki/Nginx#Hardened_setup_with_TLS_and_HSTS_preloading
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedTlsSettings = true;
|
2024-05-20 20:52:57 -04:00
|
|
|
|
2024-07-02 16:19:15 -04:00
|
|
|
virtualHosts = cfg.virtualHosts;
|
|
|
|
};
|
2024-05-20 20:52:57 -04:00
|
|
|
|
2024-07-02 16:19:15 -04:00
|
|
|
# Open ports
|
|
|
|
networking.firewall = {
|
|
|
|
enable = true;
|
|
|
|
allowedTCPPorts = [
|
|
|
|
80
|
|
|
|
443
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
# Disable autostart if configured
|
|
|
|
systemd.services.nginx = lib.mkIf (!cfg.autostart) { wantedBy = lib.mkForce [ ]; };
|
|
|
|
};
|
2024-05-20 20:52:57 -04:00
|
|
|
}
|