2023-10-01 22:50:54 +02:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
let
|
2024-10-12 18:19:43 +02:00
|
|
|
inherit (lib)
|
|
|
|
attrsToList
|
|
|
|
concatStringsSep
|
|
|
|
filterAttrs
|
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
|
|
|
;
|
|
|
|
|
|
|
|
inherit (lib.types) attrsOf port;
|
2023-10-01 22:50:54 +02:00
|
|
|
|
|
|
|
cfg = config.dgn-web;
|
2024-02-02 10:51:31 +01:00
|
|
|
in
|
|
|
|
{
|
2023-10-01 22:50:54 +02:00
|
|
|
options.dgn-web = {
|
|
|
|
enable = mkEnableOption "sane defaults for web services.";
|
2024-10-12 18:19:43 +02:00
|
|
|
|
|
|
|
internalPorts = mkOption {
|
|
|
|
type = attrsOf port;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
Map from the web services to their internal ports, it should avoid port clashes.
|
|
|
|
'';
|
|
|
|
};
|
2023-10-01 22:50:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2024-10-12 18:19:43 +02:00
|
|
|
assertions = [
|
|
|
|
(
|
|
|
|
let
|
|
|
|
duplicates = builtins.attrValues (
|
|
|
|
builtins.mapAttrs (p: serv: "${p}: ${concatStringsSep ", " serv}") (
|
|
|
|
filterAttrs (_: ls: builtins.length ls != 1) (
|
|
|
|
builtins.foldl' (
|
|
|
|
rev:
|
|
|
|
{ name, value }:
|
|
|
|
let
|
|
|
|
str = builtins.toString value;
|
|
|
|
in
|
|
|
|
rev // { ${str} = (rev.${str} or [ ]) ++ [ name ]; }
|
|
|
|
) { } (attrsToList cfg.internalPorts)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
in
|
|
|
|
{
|
|
|
|
assertion = duplicates == [ ];
|
|
|
|
message = ''
|
|
|
|
Internal ports cannot be used for multiple services, the clashes are:
|
|
|
|
${concatStringsSep "\n " duplicates}
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|
|
|
|
];
|
|
|
|
|
2023-10-01 22:50:54 +02:00
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
recommendedBrotliSettings = true;
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
recommendedTlsSettings = true;
|
|
|
|
recommendedZstdSettings = true;
|
|
|
|
};
|
|
|
|
|
2024-02-02 10:51:31 +01:00
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
80
|
|
|
|
443
|
|
|
|
];
|
2023-10-01 22:50:54 +02:00
|
|
|
};
|
|
|
|
}
|