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,12 +28,7 @@ in {
}; };
}; };
services.caddy = { caddyServers.calibre = {
enable = true;
adapter = "''"; # Required to enable JSON
configFile = pkgs.writeText "Caddyfile" (builtins.toJSON {
apps.http.servers = {
calibre = {
listen = [ ":443" ]; listen = [ ":443" ];
routes = [{ routes = [{
match = [{ host = [ config.bookServer ]; }]; match = [{ host = [ config.bookServer ]; }];
@ -42,10 +39,6 @@ in {
}]; }];
}]; }];
}; };
};
});
};
networking.firewall.interfaces.calibre = { allowedTCPPorts = [ 80 443 ]; }; networking.firewall.interfaces.calibre = { allowedTCPPorts = [ 80 443 ]; };