about summary refs log tree commit diff
path: root/ops/modules/www/self-redirect.nix
blob: 5bf1627be99a6f09c27daec3b89fcd59631fecf8 (plain) (blame)
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
# Redirect the hostname of a machine to its configuration in a web
# browser.
#
# Works by convention, assuming that the machine has its configuration
# at //ops/machines/${hostname}.
{ config, ... }:

let
  host = "${config.networking.hostName}.${config.networking.domain}";
in
{
  imports = [
    ./base.nix
  ];

  config.services.nginx.virtualHosts."${host}" = {
    serverName = host;
    addSSL = true; # SSL is not forced on these redirects
    enableACME = true;

    extraConfig = ''
      location = / {
        return 302 https://at.tvl.fyi/?q=%2F%2Fops%2Fmachines%2F${config.networking.hostName};
      }
    '';
  };
}