summary refs log tree commit diff
path: root/fleet/modules/web.nix
blob: 709b1e49566cf00b10c912535070e6bd6a7a52b4 (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
# SPDX-FileCopyrightText: V <v@unfathomable.blue>
# SPDX-License-Identifier: OSL-3.0

{ lib, pkgs, ... }:

{
  services.caddy = {
    enable = true;

    # Snippets must be defined before they are used, so the mkBefore ensures they come first.
    config = lib.mkBefore ''
      (all) {
        log {
          output file /var/log/caddy/access.log
        }
        header -Server
      }

      http:// {
        import all
        redir https://{host}{uri} 308
      }

      (common) {
        import all

        encode zstd gzip

        header {
          Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
          Content-Security-Policy "script-src 'none'; object-src 'none'"
          Permissions-Policy "interest-cohort=()"
          X-Clacks-Overhead "GNU Terry Pratchett"
        }

        handle_errors {
          respond "{http.error.status_code} {http.error.status_text}"
        }
      }
    '';
  };

  systemd.services.caddy.serviceConfig.LogsDirectory = "caddy";

  networking.firewall.interfaces.ens3.allowedTCPPorts = [ 80 443 ];
}