forked from DGNum/infrastructure
feat(modules): Generalize redirections
This commit is contained in:
parent
dd10a8e2fe
commit
3f928ce90b
4 changed files with 143 additions and 103 deletions
64
modules/dgn-redirections/default.nix
Normal file
64
modules/dgn-redirections/default.nix
Normal file
|
@ -0,0 +1,64 @@
|
|||
{ 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);
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue