summaryrefslogtreecommitdiff
path: root/hosts/surtr/http.nix
blob: fae1e690978769c22b46686094d40bfaddf8187b (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
{ config, ... }:
{
  config = {
    services.webdav-server-rs = {
      enable = true;
      settings = {
        server.listen = [ "/run/webdav-server-rs/webdav-server-rs.sock" ];
        accounts = {
          auth-type = "pam";
          acct-type = "unix";
        };
        pam = {
          service = "webdav-server-rs";
        };
        location = [
          {
            route = [ "/*path" ];
            methods = [ "all" ];
            auth = "true";
            handler = "virtroot";
            setuid = true;
            directory = "/srv/files";
          }
        ];
      };
    };
    systemd.services.webdav-server-rs = {
      serviceConfig = {
        RuntimeDirectory = "webdav-server-rs";
        RuntimeDirectoryMode = "0755";
      };
    };
    security.pam.services."webdav-server-rs".text = ''
      auth requisite  pam_succeed_if.so user ingroup webdav
      auth required   pam_unix.so audit likeauth nullok nodelay
      account sufficient pam_unix.so
    '';
    users.groups."webdav" = {};
    
    services.nginx = {
      enable = true;
      recommendedGzipSettings = true;
      recommendedProxySettings = true;
      recommendedTlsSettings = true;
      commonHttpConfig = ''
        ssl_ecdh_curve X25519:prime256v1:secp521r1:secp384r1;
      '';
      upstreams.webdav = {
        servers = { "unix:/run/webdav-server-rs/webdav-server-rs.sock" = {}; };
      };
      virtualHosts = {
        "webdav.141.li" = {
          forceSSL = true;
          sslCertificate = "${config.security.acme.certs."webdav.141.li".directory}/fullchain.pem";
          sslCertificateKey = "${config.security.acme.certs."webdav.141.li".directory}/key.pem";
          locations."/" = {
            proxyPass = "http://webdav/";
          };
        };
      };
    };
    security.acme.domains."webdav.141.li" = {};
  };
}