aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/caddy.nix49
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/caddy.nix b/modules/caddy.nix
new file mode 100644
index 0000000..b8711c6
--- /dev/null
+++ b/modules/caddy.nix
@@ -0,0 +1,49 @@
+{
+ lib,
+ pkgs,
+ config,
+ ...
+}:
+with lib;
+let
+ cfg = config.services.neaCaddy;
+in
+{
+ options.services.neaCaddy = {
+ enable = mkEnableOption "Custom Caddy Service";
+ baseUrl = mkOption {
+ type = types.str;
+ description = "The default domain under which all service subdomains get registered";
+ example = "nea.moe";
+ };
+ reverseProxy = mkOption {
+ type = types.attrsOf (
+ types.submodule {
+ port = mkOption {
+ type = int;
+ description = "The local port of the reverse proxied service";
+ };
+ }
+ );
+ description = "List of reverse proxy hosts to enable";
+ };
+
+ };
+ config = mkIf cfg.enable {
+ services.caddy = (
+ {
+ enable = true;
+ }
+ // ({
+ virtualHosts = attrsets.mapAttrs' (
+ name: value:
+ attrsets.nameValuePair (name + "." + cfg.baseUrl) {
+ extraConfig = ''
+ reverse_proxy http://localhost:${value.port}/
+ '';
+ }
+ ) cfg.reverseProxy;
+ })
+ );
+ };
+}