From 5f7cfd5d247478b62058e4519c2d442739cd778b Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Sun, 22 Jun 2025 19:28:55 +0800 Subject: [PATCH] feat(nixos/nginx): add pages option to nginx module --- .../server/web-servers/nginx/default.nix | 35 ++++++++++++++++++- systems/x86_64-linux/apollo/default.nix | 6 ++++ systems/x86_64-linux/apollo/root/index.html | 9 +++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 systems/x86_64-linux/apollo/root/index.html diff --git a/modules/nixos/server/web-servers/nginx/default.nix b/modules/nixos/server/web-servers/nginx/default.nix index 4272d3a..d0d6cc8 100644 --- a/modules/nixos/server/web-servers/nginx/default.nix +++ b/modules/nixos/server/web-servers/nginx/default.nix @@ -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 ]; }; }; diff --git a/systems/x86_64-linux/apollo/default.nix b/systems/x86_64-linux/apollo/default.nix index 8a7ca24..f13b5ca 100644 --- a/systems/x86_64-linux/apollo/default.nix +++ b/systems/x86_64-linux/apollo/default.nix @@ -42,6 +42,12 @@ enableSSL = true; nginx = { enable = true; + pages = [ + { + domain = "rrv.sh"; + root = ./root; + } + ]; proxies = [ { source = "aenyrathia.wiki"; diff --git a/systems/x86_64-linux/apollo/root/index.html b/systems/x86_64-linux/apollo/root/index.html new file mode 100644 index 0000000..e33b981 --- /dev/null +++ b/systems/x86_64-linux/apollo/root/index.html @@ -0,0 +1,9 @@ + + + + rrv.sh + + +

TEST

+ +