mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 15:11:34 +01:00
caddy: Add file-server capabilities
This commit is contained in:
parent
8c138d274f
commit
dfeb11dfbd
1 changed files with 25 additions and 6 deletions
|
|
@ -20,13 +20,23 @@ let
|
||||||
];
|
];
|
||||||
|
|
||||||
mkVirtualHost =
|
mkVirtualHost =
|
||||||
{ domain, port, ... }:
|
{
|
||||||
|
domain,
|
||||||
|
port,
|
||||||
|
files,
|
||||||
|
...
|
||||||
|
}:
|
||||||
lib.nameValuePair domain {
|
lib.nameValuePair domain {
|
||||||
logFormat = "output file ${config.services.caddy.logDir}/${domain}.log { mode 640 }";
|
logFormat = "output file ${config.services.caddy.logDir}/${domain}.log { mode 640 }";
|
||||||
extraConfig = ''
|
extraConfig = lib.concatLines [
|
||||||
${lib.optionalString (lib'.isTailscaleDomain domain) "bind tailscale/${lib'.subdomainOf domain}"}
|
(lib.optionalString (lib'.isTailscaleDomain domain) "bind tailscale/${lib'.subdomainOf domain}")
|
||||||
reverse_proxy localhost:${toString port}
|
(lib.optionalString (port != null) "reverse_proxy localhost:${toString port}")
|
||||||
'';
|
(lib.optionalString (files != null) ''
|
||||||
|
root * ${files}
|
||||||
|
encode
|
||||||
|
file_server
|
||||||
|
'')
|
||||||
|
];
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
@ -49,7 +59,11 @@ in
|
||||||
default = name;
|
default = name;
|
||||||
};
|
};
|
||||||
port = lib.mkOption {
|
port = lib.mkOption {
|
||||||
type = lib.types.port;
|
type = lib.types.nullOr lib.types.port;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
files = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.path;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -63,6 +77,11 @@ in
|
||||||
config = lib.mkIf (virtualHosts != [ ]) (
|
config = lib.mkIf (virtualHosts != [ ]) (
|
||||||
lib.mkMerge [
|
lib.mkMerge [
|
||||||
{
|
{
|
||||||
|
assertions = lib.singleton {
|
||||||
|
assertion = virtualHosts |> lib.all ({ port, files, ... }: lib.xor (port != null) (files != null));
|
||||||
|
message = "Each caddy virtual host must set exactly one of `port` or `files`";
|
||||||
|
};
|
||||||
|
|
||||||
meta.ports.tcp.list = [ cfg.metricsPort ];
|
meta.ports.tcp.list = [ cfg.metricsPort ];
|
||||||
|
|
||||||
services.caddy = {
|
services.caddy = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue