chore: clean up caddy module
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-12-29 05:11:00 -05:00
parent 98833bdc6f
commit 628109e47e

View file

@ -4,18 +4,16 @@ self: {
pkgs, pkgs,
... ...
}: let }: let
inherit (self.lib) capitalise;
inherit (lib) types; inherit (lib) types;
inherit (lib.attrsets) attrValues; inherit (lib.attrsets) attrValues;
inherit (lib.modules) mkIf mkOverride; inherit (lib.modules) mkIf mkOverride;
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.strings) concatMapStringsSep concatStringsSep optionalString stringLength substring toUpper; inherit (lib.strings) concatMapStringsSep concatStringsSep optionalString;
cfg = config.services.caddy; cfg = config.services.caddy;
capitalize = str:
toUpper (substring 0 1 str)
+ substring 1 (stringLength str) str;
mkSubDirConf = subOpts: mkSubDirConf = subOpts:
optionalString (subOpts.reverseProxy != null) ( optionalString (subOpts.reverseProxy != null) (
if subOpts.experimental if subOpts.experimental
@ -27,7 +25,7 @@ self: {
uri strip_prefix ${subOpts.subDirName} uri strip_prefix ${subOpts.subDirName}
reverse_proxy ${subOpts.reverseProxy} { reverse_proxy ${subOpts.reverseProxy} {
header_up X-Real-IP {remote} header_up X-Real-IP {remote}
header_up X-${capitalize (subOpts.subDirName)}-Base "/${subOpts.subDirName}" header_up X-${capitalise subOpts.subDirName}-Base "/${subOpts.subDirName}"
} }
} }
'' ''
@ -97,8 +95,10 @@ in {
type = types.attrsOf (types.submodule (import ./vhost-options.nix {inherit cfg;})); type = types.attrsOf (types.submodule (import ./vhost-options.nix {inherit cfg;}));
}; };
# implementation
config = mkIf cfg.enable { config = mkIf cfg.enable {
services.caddy.configFile = mkOverride 80 configFile; services.caddy.configFile = mkOverride 80 configFile;
}; };
# For accurate stack trace
_file = ./default.nix;
} }