dotfiles/modules/services/caddy.nix

36 lines
834 B
Nix
Raw Permalink Normal View History

2022-10-13 23:40:30 +00:00
{ config, pkgs, lib, ... }: {
2022-10-02 15:24:25 +00:00
options = {
caddyRoutes = lib.mkOption {
type = lib.types.listOf lib.types.attrs;
description = "Caddy JSON routes for http servers";
2022-10-02 15:24:25 +00:00
};
2022-10-15 19:00:37 +00:00
caddyBlocks = lib.mkOption {
type = lib.types.listOf lib.types.attrs;
description = "Caddy JSON error blocks for http servers";
default = [ ];
};
2022-10-02 15:24:25 +00:00
};
config = {
services.caddy = {
enable = true;
adapter = "''"; # Required to enable JSON
configFile = pkgs.writeText "Caddyfile" (builtins.toJSON {
apps.http.servers.main = {
listen = [ ":443" ];
routes = config.caddyRoutes;
2022-10-15 19:00:37 +00:00
errors.routes = config.caddyBlocks;
};
});
2022-10-02 15:24:25 +00:00
};
2022-10-03 12:19:29 +00:00
networking.firewall.allowedTCPPorts = [ 80 443 ];
networking.firewall.allowedUDPPorts = [ 443 ];
2022-10-02 15:24:25 +00:00
};
}