summaryrefslogtreecommitdiff
path: root/modules/test_endpoint.nix
blob: 701bce81945788edb95a32d4d7d5facb55a9595c (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
{ lib, config, ... }:
let
  cfg = config.wilkuu.services.test_endpoint;
in
{
  options.wilkuu.services.test_endpoint = with lib; {
    enable = mkOption {
      type = types.bool;
      default = config.services.nginx.enable;
      description = "Whenever to ssl-terminate a small test-endpoint";
      example = true;
    };
    port = mkOption {
      type = types.port;
      default = 6767;
      description = "The port to forward traffic to";
      example = 6969;
    };
    domain = mkOption {
      type = types.str;
      default = "test.${config.networking.hostName}.wilkuu.xyz";
      description = "The domain to show";
      example = "test.example.com";
    };
    doACME = mkOption {
      type = types.bool;
      default = !config.addons.virtualisation.isTestVM;
      description = "Whenever to enable SSL or not.";
      example = false;
    };
  };
  config = lib.mkIf cfg.enable {
    services.nginx.virtualHosts.${cfg.domain} = {
      addSSL = cfg.doACME;
      enableACME = cfg.doACME;
      locations."/" = {
        proxyPass = "http://localhost:${toString cfg.port}";
        proxyWebsockets = true;
        recommendedProxySettings = true;
      };
    };

  };
}