tlaternet-server/modules/nginxExtensions.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.6 KiB
Nix
Raw Normal View History

2024-08-18 19:41:20 +01:00
{
config,
pkgs,
lib,
...
}:
{
2024-04-13 03:34:53 +01:00
options = {
services.nginx.domain = lib.mkOption {
type = lib.types.str;
description = "The base domain name to append to virtual domain names";
};
services.nginx.virtualHosts =
let
extraVirtualHostOptions =
2024-08-18 19:41:20 +01:00
{ name, config, ... }:
{
2024-04-13 03:34:53 +01:00
options = {
enableHSTS = lib.mkEnableOption "Enable HSTS";
addAccessLog = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Add special logging to `/var/log/nginx/''${serverName}`
'';
};
};
config = {
extraConfig = lib.concatStringsSep "\n" [
(lib.optionalString config.enableHSTS ''
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
'')
(lib.optionalString config.addAccessLog ''
access_log /var/log/nginx/${name}/access.log upstream_time;
'')
];
};
};
in
2024-08-18 19:41:20 +01:00
lib.mkOption { type = lib.types.attrsOf (lib.types.submodule extraVirtualHostOptions); };
2024-04-13 03:34:53 +01:00
};
config = {
# Don't attempt to run acme if the domain name is not tlater.net
systemd.services =
let
confirm = ''[[ "tlater.net" = ${config.services.nginx.domain} ]]'';
in
2024-08-18 19:41:20 +01:00
lib.mapAttrs' (
cert: _:
lib.nameValuePair "acme-${cert}" {
serviceConfig.ExecCondition = ''${pkgs.runtimeShell} -c '${confirm}' '';
}
) config.security.acme.certs;
2024-04-13 03:34:53 +01:00
};
}