modules: services: use new nginx wrapper
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
And when not possible, document why. Note for the future: there is some repetition in some modules to configure the correct value of the subdomain, which I happen to know will line up correctly thanks to the nginx wrapper. A good way to refactor this in the future would involve avoiding this repetition, allowing use to query the correct domain in some way...
This commit is contained in:
parent
81e12969eb
commit
7032ddef37
19 changed files with 187 additions and 254 deletions
|
|
@ -4,28 +4,12 @@ let
|
|||
cfg = config.my.services.blog;
|
||||
domain = config.networking.domain;
|
||||
|
||||
makeHostInfo = name: {
|
||||
name = "${name}.${domain}";
|
||||
value = "/var/www/${name}";
|
||||
makeHostInfo = subdomain: {
|
||||
inherit subdomain;
|
||||
root = "/var/www/${subdomain}";
|
||||
};
|
||||
|
||||
hostsInfo = [
|
||||
{
|
||||
name = domain;
|
||||
value = "/var/www/blog";
|
||||
}
|
||||
] ++ builtins.map makeHostInfo [ "cv" "dev" "key" ];
|
||||
|
||||
hosts = builtins.listToAttrs hostsInfo;
|
||||
|
||||
makeVirtualHost = with lib.attrsets;
|
||||
name: root: nameValuePair "${name}" {
|
||||
forceSSL = true;
|
||||
useACMEHost = domain;
|
||||
inherit root;
|
||||
# Make my blog the default landing site
|
||||
default = (name == domain);
|
||||
};
|
||||
hostsInfo = map makeHostInfo [ "cv" "dev" "key" ];
|
||||
in
|
||||
{
|
||||
options.my.services.blog = {
|
||||
|
|
@ -33,7 +17,17 @@ in
|
|||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
services.nginx.virtualHosts = with lib.attrsets;
|
||||
mapAttrs' makeVirtualHost hosts;
|
||||
services.nginx.virtualHosts = {
|
||||
# This is not a subdomain, cannot use my nginx wrapper module
|
||||
${domain} = {
|
||||
forceSSL = true;
|
||||
useACMEHost = domain;
|
||||
root = "/var/www/blog";
|
||||
default = true; # Redirect to my blog
|
||||
};
|
||||
};
|
||||
|
||||
# Those are all subdomains, no problem
|
||||
my.services.nginx.virtualHosts = hostsInfo;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue