nixos/caddy: ensure vhosts come after user-specified cfg.extraConfig

This solves an issue, where loading the nixos-unstable module in
nixos-stable using `disabledModules` and `imports` resulted in the
following Caddyfile:

```
<globalConfig>

<vhosts>

<extraConfig>
```

instead of

```
<globalConfig>

<extraConfig>

<vhosts>
```

This is important in cases where `cfg.extraConfig` contains so called
Caddyfile snippets.

See https://caddyserver.com/docs/caddyfile/concepts#structure

Co-authored-by: Lin Jian <me@linj.tech>
This commit is contained in:
emilylange 2023-09-18 11:12:19 +02:00
parent f6401f26d0
commit fcdcccaed6
No known key found for this signature in database
GPG Key ID: 0AD773CE46FD0F87

View File

@ -36,6 +36,7 @@ let
${cfg.globalConfig}
}
${cfg.extraConfig}
${concatMapStringsSep "\n" mkVHostConf virtualHosts}
'';
Caddyfile-formatted = pkgs.runCommand "Caddyfile-formatted" { nativeBuildInputs = [ cfg.package ]; } ''
@ -340,7 +341,6 @@ in
groups = config.users.groups;
}) acmeHosts;
services.caddy.extraConfig = concatMapStringsSep "\n" mkVHostConf virtualHosts;
services.caddy.globalConfig = ''
${optionalString (cfg.email != null) "email ${cfg.email}"}
${optionalString (cfg.acmeCA != null) "acme_ca ${cfg.acmeCA}"}