Make Caddy the default web server

This commit is contained in:
Martin Puppe 2021-02-20 03:21:26 +01:00
parent 98ab6e58f1
commit e71e35cb55

View file

@ -13,20 +13,46 @@ in
hostName = mkOption { hostName = mkOption {
type = types.str; type = types.str;
description = '' description = ''
Name for the nginx virtual host. Name for the virtual host for the web server.
''; '';
example = "example.org"; example = "example.org";
}; };
server = mkOption {
type = types.enum [ "nginx" "caddy" ];
description = ''
The web server to be used for serving Financier. Either "nginx"
or "caddy".
'';
default = "caddy";
example = "example.org";
};
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = [ 80 443 ]; networking.firewall.allowedTCPPorts = [ 80 443 ];
services.nginx.virtualHosts."${cfg.hostName}" = { services.nginx = mkIf (cfg.server == "nginx") {
enable = true;
virtualHosts."${cfg.hostName}" = {
forceSSL = true; forceSSL = true;
enableACME = true; enableACME = true;
root = financier-dist; root = financier-dist;
locations."/".tryFiles = "$uri $uri/ /index.html"; locations."/".tryFiles = "$uri $uri/ /index.html";
}; };
}; };
services.caddy = mkIf (cfg.server == "caddy") {
enable = true;
config = ''
${cfg.hostName} {
root * ${financier-dist}
file_server
try_files {path} {path}/ /index.html
}
'';
};
};
} }