about summary refs log blame commit diff
path: root/ops/modules/www/self-redirect.nix
blob: 5bf1627be99a6f09c27daec3b89fcd59631fecf8 (plain) (tree)


























                                                                                              
# 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};
      }
    '';
  };
}