summaryrefslogtreecommitdiff
path: root/lib/nginx.nix
blob: 5cf829b1e4a08971357822eb84a1d0bf7e9e6529 (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
52
53
54
55
56
57
58
59
60
61
{ lib, ... }:

{
  /**
    Create an NGINX virtualHost submodule proxying a local port

    # Example

    ```nix
    mkProxy "/" "3000"
    => {
      proxyPass = "http://localhost:3000";
      proxyWebsockets = true;
    }
    ```

    # Type

    ```
    mkProxy :: String -> Number -> AttrSet
    ```

    # Arguments

    - [endpoint] virtualHost endpoint that `port` will be proxied towards
    - [port] Port to be proxied
  */
  mkProxy = endpoint: port: {
    "${endpoint}" = {
      proxyPass = "http://localhost:${toString port}";
      proxyWebsockets = true;
    };
  };

  /**
    Transform the names of an attribute set of nginx virtualHosts into a full subdomain

    # Example

    ```nix
    toVHosts "example.com" {
      subdomain = { };
    }
    => {
    	"subdomain.example.com" = { };
    }
    ```

    # Type

    ```
    toVHosts :: String -> AttrSet -> AttrSet
    ```

    # Arguments

    - [domain] Root domain used
    - [subdomainMap] A name value pair of subdomains and their virtualHost options
  */
  toVHosts = domain: lib.mapAttrs' (name: lib.nameValuePair "${name}.${domain}");
}