2022-10-13 23:42:42 +02:00
|
|
|
{ pkgs, config, secrets, inputs, ... }:
|
|
|
|
let
|
|
|
|
# TODO: fix lib
|
|
|
|
lib = pkgs.lib;
|
|
|
|
|
|
|
|
inherit (secrets) ips ports;
|
|
|
|
in
|
|
|
|
{
|
2023-03-08 14:32:39 +01:00
|
|
|
sops.secrets."cloudflare/api-key" = {};
|
2022-10-13 23:42:42 +02:00
|
|
|
|
2023-03-08 14:32:39 +01:00
|
|
|
security.acme = {
|
|
|
|
acceptTerms = true;
|
|
|
|
defaults = {
|
|
|
|
email = "h7x4@nani.wtf";
|
|
|
|
dnsProvider = "cloudflare";
|
|
|
|
credentialsFile = config.sops.secrets."cloudflare/api-key".path;
|
|
|
|
dnsPropagationCheck = true;
|
|
|
|
};
|
|
|
|
certs."nani.wtf" = {
|
|
|
|
extraDomainNames = [ "*.nani.wtf" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.${config.security.acme.certs."nani.wtf".group}.members = [ "nginx" ];
|
2022-10-13 23:42:42 +02:00
|
|
|
|
|
|
|
services.nginx = let
|
|
|
|
generateServerAliases =
|
|
|
|
domains: subdomains:
|
|
|
|
lib.lists.flatten (map (s: map (d: "${s}.${d}") domains) subdomains);
|
|
|
|
|
|
|
|
s = toString;
|
|
|
|
in {
|
|
|
|
enable = true;
|
|
|
|
enableReload = true;
|
|
|
|
|
|
|
|
statusPage = true;
|
|
|
|
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
recommendedTlsSettings = true;
|
|
|
|
|
|
|
|
virtualHosts = let
|
|
|
|
inherit (lib.attrsets) nameValuePair listToAttrs recursiveUpdate;
|
|
|
|
inherit (lib.lists) head drop;
|
|
|
|
inherit (secrets) domains keys;
|
|
|
|
|
|
|
|
cloudflare-origin-pull-ca = builtins.fetchurl {
|
|
|
|
url = "https://developers.cloudflare.com/ssl/static/authenticated_origin_pull_ca.pem";
|
|
|
|
sha256 = "0hxqszqfzsbmgksfm6k0gp0hsx9k1gqx24gakxqv0391wl6fsky1";
|
|
|
|
};
|
|
|
|
|
|
|
|
host =
|
|
|
|
subdomains: extraSettings: let
|
|
|
|
settings = with keys.certificates; {
|
|
|
|
serverAliases = drop 1 (generateServerAliases domains subdomains);
|
2023-03-08 14:32:39 +01:00
|
|
|
useACMEHost = "nani.wtf";
|
|
|
|
forceSSL = true;
|
2022-10-13 23:42:42 +02:00
|
|
|
|
|
|
|
extraConfig = ''
|
|
|
|
ssl_client_certificate ${cloudflare-origin-pull-ca};
|
|
|
|
ssl_verify_client on;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
nameValuePair "${head subdomains}.${head domains}" (recursiveUpdate settings extraSettings);
|
|
|
|
|
|
|
|
proxy =
|
|
|
|
subdomains: url: extraSettings:
|
|
|
|
host subdomains (recursiveUpdate { locations."/".proxyPass = url; } extraSettings);
|
|
|
|
|
2023-01-03 22:45:41 +01:00
|
|
|
in (listToAttrs ([
|
2022-10-13 23:42:42 +02:00
|
|
|
{
|
|
|
|
name = "nani.wtf";
|
|
|
|
value = {
|
|
|
|
locations = {
|
2022-11-08 14:28:59 +01:00
|
|
|
"= /".return = "301 https://www.nani.wtf/";
|
2022-10-13 23:42:42 +02:00
|
|
|
"/.well-known/".alias = "${./well-known}/";
|
|
|
|
"/.well-known/openpgpkey/hu/" = {
|
|
|
|
alias = "${./well-known/openpgpkey/hu}/";
|
|
|
|
extraConfig = ''
|
|
|
|
default_type application/octet-stream;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-03-08 14:32:39 +01:00
|
|
|
useACMEHost = "nani.wtf";
|
|
|
|
forceSSL = true;
|
2022-10-13 23:42:42 +02:00
|
|
|
|
|
|
|
extraConfig = ''
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
|
|
|
default_type text/plain;
|
2023-03-08 14:32:39 +01:00
|
|
|
ssl_client_certificate ${cloudflare-origin-pull-ca};
|
|
|
|
ssl_verify_client on;
|
2022-10-13 23:42:42 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
(proxy ["plex"] "http://localhost:${s ports.plex}" {})
|
2022-11-08 14:28:59 +01:00
|
|
|
(host ["www"] { root = "${inputs.website.packages.${pkgs.system}.default}/"; })
|
2023-03-08 14:32:39 +01:00
|
|
|
(host ["matrix"] {
|
|
|
|
enableACME = lib.mkForce false;
|
|
|
|
locations."/_synapse".proxyPass = "http://$synapse_backend";
|
|
|
|
})
|
2022-10-13 23:42:42 +02:00
|
|
|
(host ["madmin"] { root = "${pkgs.synapse-admin}/"; })
|
2023-01-03 22:52:24 +01:00
|
|
|
# (host ["cache"] { root = "/var/lib/nix-cache"; })
|
2022-10-13 23:42:42 +02:00
|
|
|
(proxy ["git"] "http://localhost:${s ports.gitea}" {})
|
|
|
|
(proxy ["px1"] "https://${ips.px1}:${s ports.proxmox}" {
|
|
|
|
locations."/".proxyWebsockets = true;
|
|
|
|
})
|
|
|
|
(proxy ["idrac"] "https://${ips.idrac}" {})
|
|
|
|
(proxy ["log"] "http://localhost:${s ports.grafana}" {
|
|
|
|
locations."/".proxyWebsockets = true;
|
|
|
|
})
|
|
|
|
(proxy ["pg"] "http://localhost:${s ports.pgadmin}" {})
|
2022-11-08 14:28:59 +01:00
|
|
|
(proxy ["py"] "http://localhost:${s ports.jupyterhub}" {
|
|
|
|
locations."/".proxyWebsockets = true;
|
|
|
|
})
|
2023-03-07 23:14:10 +01:00
|
|
|
(proxy ["docs"] "http://localhost:${s config.services.hedgedoc.settings.port}" {})
|
|
|
|
(proxy ["map"] "http://localhost:${s ports.minecraft.dynmap}" {})
|
2023-05-08 01:51:02 +02:00
|
|
|
(proxy ["yt"] "http://localhost:${s config.services.invidious.port}" {})
|
2023-01-04 14:32:11 +01:00
|
|
|
(proxy ["osu"] "http://localhost:${s ports.osuchan}" {})
|
2023-03-06 21:12:14 +01:00
|
|
|
(proxy ["auth"] "https://localhost:8300" {
|
|
|
|
extraConfig = ''
|
|
|
|
proxy_ssl_verify off;
|
|
|
|
'';
|
|
|
|
})
|
2022-10-13 23:42:42 +02:00
|
|
|
(proxy ["hydra"] "http://localhost:${s ports.hydra}" {})
|
2023-01-03 22:45:41 +01:00
|
|
|
] ++ (let
|
|
|
|
stickerpickers = pkgs.callPackage ../matrix/maunium-stickerpicker.nix {
|
2023-01-16 16:10:12 +01:00
|
|
|
inherit (inputs) maunium-stickerpicker secrets;
|
2023-01-03 22:52:24 +01:00
|
|
|
};
|
2023-01-03 22:45:41 +01:00
|
|
|
in [
|
|
|
|
(host ["stickers-pingu"] { root = "${stickerpickers.stickers-pingu}/"; })
|
|
|
|
(host ["stickers-h7x4"] { root = "${stickerpickers.stickers-h7x4}/"; })
|
|
|
|
])));
|
2022-10-13 23:42:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
80
|
|
|
|
443
|
|
|
|
];
|
|
|
|
}
|