also refactor nixos modules
This commit is contained in:
parent
2471562583
commit
b37c5c0cbd
44 changed files with 10 additions and 2 deletions
42
modules/nixos/services/networking/caddy.nix
Normal file
42
modules/nixos/services/networking/caddy.nix
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) length;
|
||||
inherit (lib) mkIf mkEnableOption mkOption types attrNames mapAttrs;
|
||||
|
||||
cfg = config.sneeuwvlok.services.networking.caddy;
|
||||
hasHosts = (cfg.hosts |> attrNames |> length) > 0;
|
||||
caddyPackage = pkgs.caddy.withPlugins {
|
||||
plugins = ["github.com/corazawaf/coraza-caddy/v2@v2.1.0"];
|
||||
hash = "sha256-pSXjLaZoRtKV3eFl2ySRSjl3yxi514G1Cb7pfrpxxtE=";
|
||||
};
|
||||
in {
|
||||
options.sneeuwvlok.services.networking.caddy = {
|
||||
enable = mkEnableOption "enable caddy" // {default = true;};
|
||||
|
||||
hosts = mkOption {
|
||||
type = types.attrsOf types.str;
|
||||
default = {};
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf hasHosts {
|
||||
services.caddy = {
|
||||
enable = cfg.enable;
|
||||
|
||||
package = caddyPackage;
|
||||
|
||||
virtualHosts =
|
||||
cfg.hosts
|
||||
|> mapAttrs (host: extraConfig: {inherit extraConfig;});
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue