blob: 82b7a3b1373b1723842393958e8f9a0ac791bf19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
{
lib,
pkgs,
config,
...
}:
with lib;
let
cfg = config.services.neaCaddy;
in
{
options.services.neaCaddy = {
enable = mkEnableOption "Custom Caddy Service";
baseUrl = mkOption {
type = types.str;
description = "The default domain under which all service subdomains get registered";
example = "nea.moe";
};
reverseProxy = mkOption {
type = types.attrsOf (
types.submodule {
options = {
port = mkOption {
type = types.int;
description = "The local port of the reverse proxied service";
};
};
}
);
description = "List of reverse proxy hosts to enable";
};
};
config = mkIf cfg.enable {
services.caddy = (
{
enable = true;
}
// ({
virtualHosts = attrsets.mapAttrs' (
name: value:
attrsets.nameValuePair (name + "." + cfg.baseUrl) {
extraConfig = ''
reverse_proxy http://localhost:${toString value.port}
'';
}
) cfg.reverseProxy;
})
);
};
}
|