summaryrefslogtreecommitdiff
path: root/sys/web/nginx.nix
blob: a971eb2f9603f7f92033d44bf1f9de2289e9c491 (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
{ config, lib, ... }:
with lib; let
  cfg = config.local.web;
  inherit (config.local) domains;
in
{
  options.local.web = {
    enable = mkEnableOption "web server";

    ownedCerts = mkOption {
      type = with lib.types; listOf str;
      default = [ ];
    };
  };

  config = mkIf cfg.enable {
    services.nginx = {
      enable = true;

      recommendedGzipSettings = true;
      recommendedOptimisation = true;
      recommendedProxySettings = true;
      recommendedTlsSettings = true;

      sslDhparam = config.security.dhparams.params.nginx.path;

      clientMaxBodySize = "42M";

      virtualHosts = { };
    };

    local.certs = listToAttrs (map
      (name: {
        inherit name;
        value.enable = true;
      })
      cfg.ownedCerts);

    networking.firewall.allowedTCPPorts = [ 80 443 ];

    security = {
      acme.certs = listToAttrs (map
        (name: {
          name = domains.${name}.main;
          value = {
            group = mkDefault config.services.nginx.group;
          };
        })
        cfg.ownedCerts);

      dhparams.params.nginx = { };
    };
  };
}