about summary refs log tree commit diff
path: root/modules/services/userweb.nix
blob: 1477f5985a2ed2eef6f55728e3f6dce489f0a226 (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
{ config, lib, ... }:

with lib;
let
  cfg = config.modules.services.userweb;
in
{
  options.modules.services.userweb = {
    enable = mkEnableOption "serve user web contents";
    domain = mkOption { type = types.str; };
  };

  config = mkIf cfg.enable {
    modules.services.nginx.enable = true;

    services.nginx.virtualHosts.${cfg.domain} = {
      forceSSL = true;
      useACMEHost = cfg.domain;

      serverName = "${cfg.domain} www.${cfg.domain}";

      locations."~ ^/(~u/)(?<user>[\w-]+)(?<user_uri>/.*)?$" = {
        alias = "/home/$user/public_html$user_uri";
        index = "index.html index.php index.cgi index.py index.sh index.pl index.lua";

        extraConfig = ''
          error_page 404 /~$user/404.html;
        '';
      };

      extraConfig = ''
        error_log /var/log/nginx/${cfg.domain}-error.log crit;
      '';
    };
  };
}