move caddy config into separate file

This commit is contained in:
Noah Masur 2022-10-02 15:24:25 +00:00
parent 90bc2ecd49
commit b4ba0706c0
2 changed files with 38 additions and 19 deletions

View File

@ -0,0 +1,26 @@
{ config, pkgs, lib, ... }:
let
in {
options = {
caddyServers = lib.mkOption {
type = lib.types.attrs;
description = "Caddy JSON configs for http servers";
};
};
config = {
services.caddy = {
enable = true;
adapter = "''"; # Required to enable JSON
configFile = pkgs.writeText "Caddyfile"
(builtins.toJSON { apps.http.servers = config.caddyServers; });
};
};
}

View File

@ -7,6 +7,8 @@ let
in {
imports = [ ./caddy.nix ];
options = {
bookServer = lib.mkOption {
type = lib.types.str;
@ -26,25 +28,16 @@ in {
};
};
services.caddy = {
enable = true;
adapter = "''"; # Required to enable JSON
configFile = pkgs.writeText "Caddyfile" (builtins.toJSON {
apps.http.servers = {
calibre = {
listen = [ ":443" ];
routes = [{
match = [{ host = [ config.bookServer ]; }];
handle = [{
handler = "reverse_proxy";
upstreams = [{ dial = "localhost:8083"; }];
headers.request.add."X-Script-Name" = [ "/calibre-web" ];
}];
}];
};
};
});
caddyServers.calibre = {
listen = [ ":443" ];
routes = [{
match = [{ host = [ config.bookServer ]; }];
handle = [{
handler = "reverse_proxy";
upstreams = [{ dial = "localhost:8083"; }];
headers.request.add."X-Script-Name" = [ "/calibre-web" ];
}];
}];
};
networking.firewall.interfaces.calibre = { allowedTCPPorts = [ 80 443 ]; };