Compare commits
4 commits
e347273e5b
...
df14a9a513
Author | SHA1 | Date | |
---|---|---|---|
df14a9a513 | |||
d59abfb678 | |||
a285c57d5b | |||
415fd7f076 |
4 changed files with 47 additions and 8 deletions
|
@ -32,7 +32,10 @@ in
|
||||||
owner = "acme";
|
owner = "acme";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
security.acme.acceptTerms = true;
|
||||||
|
security.acme.maxConcurrentRenewals = 0;
|
||||||
security.acme.defaults = {
|
security.acme.defaults = {
|
||||||
|
email = depot.lib.meta.adminEmail;
|
||||||
extraLegoFlags = lib.flatten [
|
extraLegoFlags = lib.flatten [
|
||||||
(map (x: [ "--dns.resolvers" x ]) authoritativeServers)
|
(map (x: [ "--dns.resolvers" x ]) authoritativeServers)
|
||||||
"--dns-timeout" "30"
|
"--dns-timeout" "30"
|
||||||
|
@ -42,4 +45,38 @@ in
|
||||||
EXEC_ENV_FILE=${config.age.secrets.acmeDnsApiKey.path}
|
EXEC_ENV_FILE=${config.age.secrets.acmeDnsApiKey.path}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.services = lib.mapAttrs' (name: value: {
|
||||||
|
name = "acme-${name}";
|
||||||
|
value = {
|
||||||
|
distributed.enable = value.dnsProvider != null;
|
||||||
|
preStart = let
|
||||||
|
serverList = lib.pipe authoritativeServers [
|
||||||
|
(map (x: "@${x}"))
|
||||||
|
(map (lib.replaceStrings [":53"] [""]))
|
||||||
|
lib.escapeShellArgs
|
||||||
|
];
|
||||||
|
domainList = lib.pipe ([ value.domain ] ++ value.extraDomainNames) [
|
||||||
|
(map (x: "${x}."))
|
||||||
|
(map (lib.replaceStrings ["*"] ["x"]))
|
||||||
|
lib.unique
|
||||||
|
lib.escapeShellArgs
|
||||||
|
];
|
||||||
|
in ''
|
||||||
|
echo Testing availability of authoritative DNS servers
|
||||||
|
for i in {1..60}; do
|
||||||
|
${pkgs.dig}/bin/dig +short ${serverList} ${domainList} >/dev/null && break
|
||||||
|
echo Retry [$i/60]
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
echo Available
|
||||||
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartMaxDelaySec = 30;
|
||||||
|
RestartStesp = 5;
|
||||||
|
RestartMode = "direct";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}) config.security.acme.certs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
{ config, depot, ... }:
|
{ config, ... }:
|
||||||
|
|
||||||
let
|
{
|
||||||
inherit (depot.lib.meta) adminEmail;
|
|
||||||
in {
|
|
||||||
security.acme.defaults.email = adminEmail;
|
|
||||||
security.acme.acceptTerms = true;
|
|
||||||
services.nginx = {
|
services.nginx = {
|
||||||
enable = true;
|
enable = true;
|
||||||
recommendedProxySettings = true;
|
recommendedProxySettings = true;
|
||||||
|
|
|
@ -69,11 +69,16 @@ in
|
||||||
{
|
{
|
||||||
source = let
|
source = let
|
||||||
upstreams = lib.mapAttrsToList (_: cfg: ''
|
upstreams = lib.mapAttrsToList (_: cfg: ''
|
||||||
|
{{ if ne (len (service "${cfg.consulService}~_agent")) 0 }}
|
||||||
|
# ${cfg.consulService}
|
||||||
upstream ${cfg.nginxUpstreamName} {
|
upstream ${cfg.nginxUpstreamName} {
|
||||||
{{ range $i, $e := service "${cfg.consulService}~_agent" -}}
|
{{ range $i, $e := service "${cfg.consulService}~_agent" -}}
|
||||||
server {{ .Address }}:{{ .Port }}{{ if ne $i 0 }} backup{{ end }};
|
server {{ .Address }}:{{ .Port }}{{ if ne $i 0 }} backup{{ end }};
|
||||||
{{end}}
|
{{ end }}
|
||||||
}
|
}
|
||||||
|
{{ else }}
|
||||||
|
# upstream ${cfg.nginxUpstreamName} (${cfg.consulService}): no servers available
|
||||||
|
{{ end }}
|
||||||
'') consulServiceWays;
|
'') consulServiceWays;
|
||||||
in pkgs.writeText "ways-upstreams.ctmpl" (lib.concatStringsSep "\n" (lib.unique upstreams));
|
in pkgs.writeText "ways-upstreams.ctmpl" (lib.concatStringsSep "\n" (lib.unique upstreams));
|
||||||
destination = "/run/consul-template/nginx-ways-upstreams.conf";
|
destination = "/run/consul-template/nginx-ways-upstreams.conf";
|
||||||
|
|
|
@ -36,7 +36,8 @@
|
||||||
|
|
||||||
proxyGhost = scheme: target: basic // {
|
proxyGhost = scheme: target: basic // {
|
||||||
locations."/".extraConfig = ''
|
locations."/".extraConfig = ''
|
||||||
proxy_pass ${scheme}://${target};
|
set $nix_proxy_ghost_target "${scheme}://${target}";
|
||||||
|
proxy_pass $nix_proxy_ghost_target;
|
||||||
proxy_set_header Host ${target};
|
proxy_set_header Host ${target};
|
||||||
proxy_set_header Referer ${scheme}://${target};
|
proxy_set_header Referer ${scheme}://${target};
|
||||||
proxy_cookie_domain ${target} domain.invalid;
|
proxy_cookie_domain ${target} domain.invalid;
|
||||||
|
|
Loading…
Reference in a new issue