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