refactor(haproxy): consolidate ACME configuration
build_systems / build-rhapsody-in-green (pull_request) Failing after 7m11s
build_systems / build-jeeves (pull_request) Failing after 7m19s
test ebook search / test-ebook-search (pull_request) Failing after 7m18s
build_systems / build-brain (pull_request) Failing after 7m19s
build_systems / build-bob (pull_request) Failing after 7m23s
treefmt / nix fmt (pull_request) Failing after 7m21s
pytest / pytest (pull_request) Failing after 7m26s
build_systems / build-rhapsody-in-green (pull_request) Failing after 7m11s
build_systems / build-jeeves (pull_request) Failing after 7m19s
test ebook search / test-ebook-search (pull_request) Failing after 7m18s
build_systems / build-brain (pull_request) Failing after 7m19s
build_systems / build-bob (pull_request) Failing after 7m23s
treefmt / nix fmt (pull_request) Failing after 7m21s
pytest / pytest (pull_request) Failing after 7m26s
Merge the ACME module into the HAProxy configuration and start HAProxy only after certificates and Tailscale connectivity are available.
This commit is contained in:
@@ -1,72 +0,0 @@
|
|||||||
let
|
|
||||||
domains = [
|
|
||||||
"audiobookshelf"
|
|
||||||
"cache"
|
|
||||||
"gitea"
|
|
||||||
"gems"
|
|
||||||
"jellyfin"
|
|
||||||
"share"
|
|
||||||
];
|
|
||||||
extraDomains = [ "www.norn-sight.com" ];
|
|
||||||
|
|
||||||
makeCert = name: {
|
|
||||||
name = "${name}.tmmworkshop.com";
|
|
||||||
value = {
|
|
||||||
webroot = "/var/lib/acme/.challenges";
|
|
||||||
group = "acme";
|
|
||||||
reloadServices = [ "haproxy.service" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
makeExtraCert = name: {
|
|
||||||
inherit name;
|
|
||||||
value = {
|
|
||||||
webroot = "/var/lib/acme/.challenges";
|
|
||||||
group = "acme";
|
|
||||||
reloadServices = [ "haproxy.service" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
acmeServices =
|
|
||||||
map (domain: "acme-${domain}.tmmworkshop.com.service") domains
|
|
||||||
++ map (domain: "acme-${domain}.service") extraDomains;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
security.acme = {
|
|
||||||
acceptTerms = true;
|
|
||||||
defaults.email = "Richie@tmmworkshop.com";
|
|
||||||
certs = builtins.listToAttrs ((map makeCert domains) ++ (map makeExtraCert extraDomains));
|
|
||||||
};
|
|
||||||
|
|
||||||
services.nginx = {
|
|
||||||
enable = true;
|
|
||||||
virtualHosts."acme-challenge" = {
|
|
||||||
listen = [
|
|
||||||
{
|
|
||||||
addr = "127.0.0.1";
|
|
||||||
port = 8402;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
locations."/.well-known/acme-challenge/" = {
|
|
||||||
root = "/var/lib/acme/.challenges";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [
|
|
||||||
"d /var/lib/acme/.challenges 0750 acme acme - -"
|
|
||||||
"d /var/lib/acme/.challenges/.well-known 0750 acme acme - -"
|
|
||||||
"d /var/lib/acme/.challenges/.well-known/acme-challenge 0750 acme acme - -"
|
|
||||||
];
|
|
||||||
|
|
||||||
users.users = {
|
|
||||||
haproxy.extraGroups = [ "acme" ];
|
|
||||||
nginx.extraGroups = [ "acme" ];
|
|
||||||
};
|
|
||||||
|
|
||||||
# HAProxy needs the initial certificates before it can bind to port 443.
|
|
||||||
systemd.services.haproxy = {
|
|
||||||
after = acmeServices;
|
|
||||||
wants = acmeServices;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,37 @@
|
|||||||
{ ... }:
|
let
|
||||||
{
|
domains = [
|
||||||
imports = [ ./acme.nix ];
|
"audiobookshelf"
|
||||||
|
"cache"
|
||||||
|
"gitea"
|
||||||
|
"gems"
|
||||||
|
"jellyfin"
|
||||||
|
"share"
|
||||||
|
];
|
||||||
|
extraDomains = [ "www.norn-sight.com" ];
|
||||||
|
|
||||||
|
makeCert = name: {
|
||||||
|
name = "${name}.tmmworkshop.com";
|
||||||
|
value = {
|
||||||
|
webroot = "/var/lib/acme/.challenges";
|
||||||
|
group = "acme";
|
||||||
|
reloadServices = [ "haproxy.service" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
makeExtraCert = name: {
|
||||||
|
inherit name;
|
||||||
|
value = {
|
||||||
|
webroot = "/var/lib/acme/.challenges";
|
||||||
|
group = "acme";
|
||||||
|
reloadServices = [ "haproxy.service" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
acmeServices =
|
||||||
|
map (domain: "acme-${domain}.tmmworkshop.com.service") domains
|
||||||
|
++ map (domain: "acme-${domain}.service") extraDomains;
|
||||||
|
in
|
||||||
|
{
|
||||||
networking.firewall.allowedTCPPorts = [
|
networking.firewall.allowedTCPPorts = [
|
||||||
80
|
80
|
||||||
443
|
443
|
||||||
@@ -10,8 +40,49 @@
|
|||||||
# Global robots.txt served by HAProxy for every vhost (see haproxy.cfg).
|
# Global robots.txt served by HAProxy for every vhost (see haproxy.cfg).
|
||||||
environment.etc."haproxy/robots.txt".source = ./robots.txt;
|
environment.etc."haproxy/robots.txt".source = ./robots.txt;
|
||||||
|
|
||||||
services.haproxy = {
|
services = {
|
||||||
enable = true;
|
haproxy = {
|
||||||
config = builtins.readFile ./haproxy.cfg;
|
enable = true;
|
||||||
|
config = builtins.readFile ./haproxy.cfg;
|
||||||
|
};
|
||||||
|
nginx = {
|
||||||
|
enable = true;
|
||||||
|
virtualHosts."acme-challenge" = {
|
||||||
|
listen = [
|
||||||
|
{
|
||||||
|
addr = "127.0.0.1";
|
||||||
|
port = 8402;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
locations."/.well-known/acme-challenge/" = {
|
||||||
|
root = "/var/lib/acme/.challenges";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
security.acme = {
|
||||||
|
acceptTerms = true;
|
||||||
|
defaults.email = "Richie@tmmworkshop.com";
|
||||||
|
certs = builtins.listToAttrs ((map makeCert domains) ++ (map makeExtraCert extraDomains));
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd = {
|
||||||
|
services.haproxy = {
|
||||||
|
# HAProxy needs the initial certificates and Tailscale connectivity before
|
||||||
|
# it can serve requests to its backends.
|
||||||
|
after = acmeServices ++ [ "tailscaled-autoconnect.service" ];
|
||||||
|
wants = acmeServices ++ [ "tailscaled-autoconnect.service" ];
|
||||||
|
};
|
||||||
|
tmpfiles.rules = [
|
||||||
|
"d /var/lib/acme/.challenges 0750 acme acme - -"
|
||||||
|
"d /var/lib/acme/.challenges/.well-known 0750 acme acme - -"
|
||||||
|
"d /var/lib/acme/.challenges/.well-known/acme-challenge 0750 acme acme - -"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
users.users = {
|
||||||
|
haproxy.extraGroups = [ "acme" ];
|
||||||
|
nginx.extraGroups = [ "acme" ];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user