summaryrefslogtreecommitdiffstats
path: root/krebs/3modules/krebs-pages.nix
blob: face9e3a0d362796970fb7f7f5372823a0e160ec (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
{ config, modulesPath, pkgs, lib, ... }: let
  cfg = config.krebs.pages;
  extraTypes.nginx-vhost = lib.types.submodule (
    lib.recursiveUpdate
      (import (modulesPath + "/services/web-servers/nginx/vhost-options.nix")
              { inherit config lib; })
      {}
  );
in {
  options.krebs.pages = {
    enable = lib.mkEnableOption "krebs-pages";
    domain = lib.mkOption {
      type = pkgs.stockholm.lib.types.hostname;
      default = "krebsco.de";
    };
    nginx = lib.mkOption {
      type = extraTypes.nginx-vhost;
      default = {};
      example = lib.literalExpression /* nix */ ''
        {
          # To enable encryption and let let's encrypt take care of certificate
          enableACME = true;
          forceSSL = true;
        }
      '';
      description = lib.mkDoc ''
        With this option, you can customize the nginx virtualHost settings.
      '';
    };
    package = lib.mkOption {
      type = lib.types.package;
      default = pkgs.krebs-pages;
    };
  };
  config = lib.mkIf cfg.enable {
    services.nginx = {
      enable = lib.mkDefault true;
      virtualHosts.${cfg.domain} = lib.mkMerge [ cfg.nginx {
        root = lib.mkForce cfg.package;
        locations."= /ip".return = "200 $remote_addr";
        locations."= /redirect".return = "301 /redirect";
      }];
    };
  };
}