summaryrefslogtreecommitdiff
path: root/hosts/surtr/immich.nix
blob: 61a55e77bb16f9874190cf20539fa6e71c180cee (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
62
63
64
65
66
{ config, ... }:

{
  config = {
    security.acme.rfc2136Domains = {
      "immich.yggdrasil.li" = {
        restartUnits = ["nginx.service"];
      };
    };

    services.nginx = {
      upstreams."immich" = {
        servers = {
          "[2a03:4000:52:ada:4:1::]:2283" = {};
        };
        extraConfig = ''
          keepalive 8;
        '';
      };
      virtualHosts = {
        "immich.yggdrasil.li" = {
          kTLS = true;
          http3 = true;
          forceSSL = true;
          sslCertificate = "/run/credentials/nginx.service/immich.yggdrasil.li.pem";
          sslCertificateKey = "/run/credentials/nginx.service/immich.yggdrasil.li.key.pem";
          sslTrustedCertificate = "/run/credentials/nginx.service/immich.yggdrasil.li.chain.pem";
          extraConfig = ''
            charset utf-8;
          '';

          locations = {
            "/".extraConfig = ''
              proxy_pass http://immich;

              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection "upgrade";

              proxy_redirect off;
              proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Forwarded-Host $server_name;
              proxy_set_header X-Forwarded-Proto $scheme;

              client_max_body_size 0;
              proxy_request_buffering off;
              proxy_buffering off;
            '';
          };
        };
      };
    };

    systemd.services.nginx = {
      serviceConfig = {
        LoadCredential = [
          "immich.yggdrasil.li.key.pem:${config.security.acme.certs."immich.yggdrasil.li".directory}/key.pem"
          "immich.yggdrasil.li.pem:${config.security.acme.certs."immich.yggdrasil.li".directory}/fullchain.pem"
          "immich.yggdrasil.li.chain.pem:${config.security.acme.certs."immich.yggdrasil.li".directory}/chain.pem"
        ];
      };
    };
  };
}