infrastructure/modules/dgn-redirections/default.nix

65 lines
1.3 KiB
Nix
Raw Permalink Normal View History

2024-04-23 22:02:04 +02:00
{ config, lib, ... }:
let
inherit (lib) mkOption;
inherit (lib.types) attrsOf listOf str;
mkRetired =
hosts:
builtins.listToAttrs (
builtins.map (name: {
inherit name;
value = {
enableACME = true;
forceSSL = true;
locations."/".return = "301 https://${cfg.retiredHost}/${name}";
};
}) hosts
);
mkRedirection = _: globalRedirect: {
inherit globalRedirect;
enableACME = true;
forceSSL = true;
};
cfg = config.dgn-redirections;
in
{
options.dgn-redirections = {
redirections = mkOption {
type = attrsOf str;
default = { };
description = ''
Attribute set of redirections, for:
{ a = b; },
a redirection from a to b will be made.
'';
};
retired = mkOption {
type = listOf str;
default = [ ];
description = ''
List of retired domains, they will we redirected to `retired.dgnum.eu/$host`.
'';
};
retiredHost = mkOption {
type = str;
default = "retired.dgnum.eu";
description = ''
Host used for the redirections of retired services.
'';
};
};
config = {
services.nginx.virtualHosts =
(builtins.mapAttrs mkRedirection cfg.redirections) // (mkRetired cfg.retired);
};
}