nixfmt all

This commit is contained in:
Noa Aarts 2024-11-07 20:48:01 +01:00
parent 980500842d
commit 42238dc24f
Signed by: noa
GPG key ID: 1850932741EFF672
20 changed files with 333 additions and 245 deletions

View file

@ -1,106 +1,103 @@
{ config, options, lib, ... }:
{
config,
options,
lib,
...
}:
let
cfg = config.modules.websites;
in
{
options.modules.websites =
{
enable = lib.mkEnableOption "enable web hosting";
certMail = lib.mkOption {
type = lib.types.str;
description = "the email address the certificate will be requested to";
};
mainDomains = lib.mkOption {
description = "nginx domains for which a certificate is needed";
type = with lib.types; attrsOf (submodule {
options.modules.websites = {
enable = lib.mkEnableOption "enable web hosting";
certMail = lib.mkOption {
type = lib.types.str;
description = "the email address the certificate will be requested to";
};
mainDomains = lib.mkOption {
description = "nginx domains for which a certificate is needed";
type =
with lib.types;
attrsOf (submodule {
options =
let
proxyOption = lib.mkOption { type = str; description = "what url to proxy the requests to"; };
proxyOption = lib.mkOption {
type = str;
description = "what url to proxy the requests to";
};
in
{
enable = lib.mkEnableOption "enable this website";
extra_sites = lib.mkOption {
description = "extra sites that use this certificate";
type = attrsOf
(submodule {
options = {
enable = lib.mkEnableOption "enable this website";
proxy = proxyOption;
};
});
type = attrsOf (submodule {
options = {
enable = lib.mkEnableOption "enable this website";
proxy = proxyOption;
};
});
};
proxy = proxyOption;
};
});
};
};
};
config = lib.mkIf cfg.enable (
let
hostnames = lib.lists.flatten (
lib.attrsets.mapAttrsToList
(
name: config:
[ name ] ++ lib.attrsets.mapAttrsToList (n: c: lib.mkIf c.enable n) config.extra_sites
)
cfg.mainDomains
lib.attrsets.mapAttrsToList (
name: config: [ name ] ++ lib.attrsets.mapAttrsToList (n: c: lib.mkIf c.enable n) config.extra_sites
) cfg.mainDomains
);
certs = lib.attrsets.mapAttrs
(
name: config:
lib.mkIf config.enable {
extraDomainNames = lib.attrsets.mapAttrsToList
(
domain_name: domain_config: lib.mkIf domain_config.enable domain_name
)
config.extra_sites;
webroot = lib.traceVal "/var/lib/acme/acme-challenge/${name}";
}
)
cfg.mainDomains;
hosts = lib.attrsets.concatMapAttrs
(
name: config:
let
extra = ''
client_max_body_size 50000M;
certs = lib.attrsets.mapAttrs (
name: config:
lib.mkIf config.enable {
extraDomainNames = lib.attrsets.mapAttrsToList (
domain_name: domain_config: lib.mkIf domain_config.enable domain_name
) config.extra_sites;
webroot = lib.traceVal "/var/lib/acme/acme-challenge/${name}";
}
) cfg.mainDomains;
hosts = lib.attrsets.concatMapAttrs (
name: config:
let
extra = ''
client_max_body_size 50000M;
proxy_redirect off;
proxy_redirect off;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
send_timeout 600s;'';
proxy = url: {
forceSSL = true;
useACMEHost = name;
extraConfig = extra;
locations."/" = {
proxyWebsockets = true;
proxyPass = url;
};
};
in
lib.trace name (lib.mkIf config.enable (
lib.mkMerge [
{
${name} = {
forceSSL = true;
enableACME = true;
extraConfig = extra;
locations."/" = {
proxyWebsockets = true;
proxyPass = config.proxy;
};
proxy_read_timeout 600s;
proxy_send_timeout 600s;
send_timeout 600s;'';
proxy = url: {
forceSSL = true;
useACMEHost = name;
extraConfig = extra;
locations."/" = {
proxyWebsockets = true;
proxyPass = url;
};
};
in
lib.trace name (
lib.mkIf config.enable (
lib.mkMerge [
{
${name} = {
forceSSL = true;
enableACME = true;
extraConfig = extra;
locations."/" = {
proxyWebsockets = true;
proxyPass = config.proxy;
};
}
(lib.attrsets.mapAttrs
(n: c:
lib.traceSeq c (proxy c.proxy)
)
config.extra_sites)
]
))
};
}
(lib.attrsets.mapAttrs (n: c: lib.traceSeq c (proxy c.proxy)) config.extra_sites)
]
)
)
cfg.mainDomains;
) cfg.mainDomains;
in
{
networking.hosts = {