2022-04-10 20:57:56 +02:00
|
|
|
{ pkgs, lib, config, options, ... }:
|
2022-09-27 22:07:46 +02:00
|
|
|
with lib;
|
2022-04-10 20:57:56 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.personal.services.webserver;
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
2022-09-27 22:07:46 +02:00
|
|
|
options = {
|
2022-04-10 20:57:56 +02:00
|
|
|
personal = {
|
|
|
|
services = {
|
|
|
|
webserver = {
|
|
|
|
enable = mkEnableOption "Webserver";
|
|
|
|
|
|
|
|
hosts = mkOption {
|
|
|
|
description = ''
|
|
|
|
List of hosts to configure
|
|
|
|
'';
|
2022-09-28 13:54:01 +02:00
|
|
|
type = types.listOf (types.submodule {
|
|
|
|
options = {
|
|
|
|
domain = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Name of the domain";
|
|
|
|
};
|
|
|
|
domainOptions = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = { };
|
|
|
|
description = "Custom options for domain";
|
|
|
|
};
|
|
|
|
proxy = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "Optional proxy target";
|
|
|
|
};
|
|
|
|
proxyOptions = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
description = "Custom options for proxy";
|
|
|
|
};
|
2022-04-10 20:57:56 +02:00
|
|
|
};
|
2022-09-28 13:54:01 +02:00
|
|
|
});
|
|
|
|
default = [ ];
|
2022-04-10 20:57:56 +02:00
|
|
|
example = [{
|
2022-09-27 22:07:46 +02:00
|
|
|
domain = "dummy.boerger.ws";
|
2022-04-10 20:57:56 +02:00
|
|
|
proxy = "http://localhost:8080";
|
|
|
|
options = {
|
|
|
|
locations = {
|
|
|
|
"/".extraConfig = ''
|
|
|
|
autoindex on;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
acmeHost = mkOption {
|
|
|
|
description = ''
|
|
|
|
Use this acme certificate chain
|
|
|
|
'';
|
|
|
|
type = types.str;
|
2022-09-27 22:07:46 +02:00
|
|
|
default = "boerger.ws";
|
2022-04-10 20:57:56 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-09-27 22:07:46 +02:00
|
|
|
config = mkIf cfg.enable {
|
2024-07-17 16:05:33 +02:00
|
|
|
networking.firewall = {
|
|
|
|
allowedTCPPorts = [ 80 443 ];
|
|
|
|
};
|
|
|
|
|
2022-04-10 20:57:56 +02:00
|
|
|
services = {
|
|
|
|
nginx = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
recommendedTlsSettings = true;
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
|
|
|
|
virtualHosts = builtins.listToAttrs
|
|
|
|
(map
|
|
|
|
(elem: {
|
|
|
|
name = elem.domain;
|
|
|
|
value = {
|
|
|
|
useACMEHost = cfg.acmeHost;
|
|
|
|
forceSSL = true;
|
|
|
|
locations = {
|
|
|
|
"/" = mkIf (builtins.hasAttr "proxy" elem) {
|
|
|
|
proxyPass = elem.proxy;
|
2022-10-25 09:53:40 +02:00
|
|
|
extraConfig = (
|
|
|
|
elem.proxyOptions or ''
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
|
|
proxy_set_header Connection $http_connection;
|
|
|
|
proxy_set_header X-Forwarded-Ssl on;
|
|
|
|
''
|
|
|
|
);
|
2022-04-10 20:57:56 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
} // (elem.domainOptions or { });
|
|
|
|
})
|
|
|
|
config.personal.services.webserver.hosts) // {
|
2022-10-25 09:53:40 +02:00
|
|
|
"boerger.ws" = {
|
2022-09-28 13:54:01 +02:00
|
|
|
useACMEHost = cfg.acmeHost;
|
|
|
|
addSSL = true;
|
|
|
|
forceSSL = false;
|
|
|
|
default = true;
|
2022-10-25 09:53:40 +02:00
|
|
|
root = "/var/empty";
|
2022-09-28 13:54:01 +02:00
|
|
|
};
|
|
|
|
};
|
2022-04-10 20:57:56 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users = {
|
|
|
|
users = {
|
|
|
|
nginx = {
|
|
|
|
extraGroups = [
|
|
|
|
"acme"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-17 16:05:33 +02:00
|
|
|
personal = {
|
|
|
|
services = {
|
|
|
|
acme = {
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
};
|
2022-04-10 20:57:56 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|