feat(nixos/nginx): add pages option to nginx module

This commit is contained in:
Mohammad Rafiq 2025-06-22 19:28:55 +08:00
parent b3a5441e8b
commit 5f7cfd5d24
No known key found for this signature in database
3 changed files with 49 additions and 1 deletions

View file

@ -8,7 +8,7 @@ let
singleton
;
inherit (lib.types) listOf submodule attrs;
inherit (lib.pantheon) mkStrOption mkRootDomain;
inherit (lib.pantheon) mkStrOption mkPathOption mkRootDomain;
inherit (builtins) listToAttrs map;
cfg = config.server.web-servers.nginx;
sslCheck = good: bad: if config.server.web-servers.enableSSL then good else bad;
@ -21,6 +21,21 @@ let
};
};
};
pages = listToAttrs (
map (page: {
name = page.domain;
value = {
addSSL = sslCheck true false;
useACMEHost = sslCheck (mkRootDomain page.domain) null;
acmeRoot = null; # needed for DNS validation
locations = {
"/" = {
inherit (page) root;
} // page.extraConfig;
} // page.locations;
};
}) cfg.pages
);
proxyPasses = listToAttrs (
map (proxy: {
name = proxy.source;
@ -46,6 +61,23 @@ in
enableDefaultSink = mkEnableOption "" // {
default = true;
};
pages = mkOption {
default = [ ];
type = listOf (submodule {
options = {
domain = mkStrOption;
root = mkPathOption "";
extraConfig = lib.mkOption {
type = attrs;
default = { };
};
locations = lib.mkOption {
type = attrs;
default = { };
};
};
});
};
proxies = mkOption {
default = [ ];
type = listOf (submodule {
@ -80,6 +112,7 @@ in
virtualHosts = mkMerge [
defaultSink
proxyPasses
pages
];
};
};