summaryrefslogtreecommitdiff
path: root/hosts/surtr/http.nix
blob: 11441e2cb6196399aaec7ff30724f68b882a116a (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
67
68
69
{ config, lib, pkgs, ... }:
{
  config = {
    security.pam.services."webdav".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;
      '';
      additionalModules = with pkgs.nginxModules; [ dav pam ];
      virtualHosts = {
        "webdav.141.li" = {
          forceSSL = true;
          sslCertificate = "/run/credentials/nginx.service/webdav.141.li.pem";
          sslCertificateKey = "/run/credentials/nginx.service/webdav.141.li.key.pem";
          locations."/".extraConfig = ''
            root /srv/files/$remote_user;            

            auth_pam "WebDAV";
            auth_pam_service_name "webdav";
          '';
          extraConfig = ''
            dav_methods     PUT DELETE MKCOL COPY MOVE;
            dav_ext_methods PROPFIND OPTIONS;
            dav_access      user:rw;
            autoindex on;

            client_body_temp_path   /run/nginx-client-bodies;
            client_max_body_size    0;
            create_full_put_path    on;
          '';
        };
      };
    };
    users.users."nginx".extraGroups = [ "shadow" ];
    security.acme.domains."webdav.141.li" = {
      zone = "141.li";
      certCfg = {
        postRun = ''
          ${pkgs.systemd}/bin/systemctl try-restart nginx.service
        '';
      };
    };
    systemd.services.nginx = {
      preStart = lib.mkForce config.services.nginx.preStart;
      serviceConfig = {
        ExecReload = lib.mkForce "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
        LoadCredential = [
          "webdav.141.li.key.pem:${config.security.acme.certs."webdav.141.li".directory}/key.pem"
          "webdav.141.li.pem:${config.security.acme.certs."webdav.141.li".directory}/fullchain.pem"
        ];
        RuntimeDirectory = lib.mkForce [ "nginx" "nginx-client-bodies" ];
        RuntimeDirectoryMode = "0750";

        SystemCallFilter = lib.mkForce "";
        ReadWritePaths = [ "/srv/files" ];
      };
    };
  };
}