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

    proxyUrl = mkOption {
      type = types.str;
    };
  };

  config = mkIf cfg.enable {
    local.web = {
      enable = mkDefault true;
      ownedCerts = [ "home" ];
    };

    services.nginx.virtualHosts.${domains.home.main} = {
      forceSSL = true;
      useACMEHost = domains.home.main;

      extraConfig = ''
        ssl_verify_depth 2;
        ssl_verify_client on;
        ssl_client_certificate ${config.local.pki.ca.home.fullchain};

        if ($ssl_client_verify != "SUCCESS") {
          return 403;
        }
      '';

      locations."/".extraConfig = ''
        proxy_pass ${cfg.proxyUrl};
      '';
    };
  };
}