From f1324f15ed3d0e407e13772ae2d0b745666f0b4e Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Thu, 5 Jun 2025 16:23:32 +0800 Subject: [PATCH] refactor(nginx): add proxies option --- modules/nixos/server/web-servers/default.nix | 59 +++++++++++--------- systems/x86_64-linux/apollo/default.nix | 10 ++++ 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/modules/nixos/server/web-servers/default.nix b/modules/nixos/server/web-servers/default.nix index b66a34f..55a63d8 100644 --- a/modules/nixos/server/web-servers/default.nix +++ b/modules/nixos/server/web-servers/default.nix @@ -6,6 +6,29 @@ in options.server.web-servers = { nginx = { enable = lib.mkEnableOption "the Nginx server"; + proxies = lib.mkOption { + type = + with lib.types; + listOf (submodule { + options = { + source = lib.pantheon.mkStrOption; + target = lib.pantheon.mkStrOption; + extraConfig = lib.mkOption { + type = attrs; + default = { }; + description = "Will be added to locations.\"/\""; + }; + }; + }); + default = [ ]; + example = [ + { + source = "chat.bwfiq.com"; + target = "http://helios:3080"; + extraConfig = { }; + } + ]; + }; }; }; config = lib.mkMerge [ @@ -22,32 +45,18 @@ in ]; services.nginx = { enable = true; - virtualHosts = { - "chat.bwfiq.com" = { - forceSSL = true; - enableACME = true; - locations."/" = { - proxyPass = "http://helios:3080"; + virtualHosts = builtins.listToAttrs ( + builtins.map (proxy: { + name = proxy.source; + value = { + forceSSL = true; + enableACME = true; + locations."/" = { + proxyPass = proxy.target; + } // proxy.extraConfig; }; - }; - "il.bwfiq.com" = { - forceSSL = true; - enableACME = true; - locations."/" = { - proxyPass = "http://helios:2283"; - }; - }; - ${config.system.hostname} = { - forceSSL = true; - enableACME = true; - locations."/" = { - return = "200 'It works!