Use null instead of empty string.

Per @aanderse in 7556fd7.
This commit is contained in:
David Warde-Farley 2022-09-26 02:23:45 +01:00 committed by Yt
parent 0d5a365f61
commit c3e75d4931

View File

@ -26,7 +26,7 @@ let
configFile =
let
Caddyfile = pkgs.writeText "Caddyfile" ''
Caddyfile = pkgs.writeTextDir "Caddyfile" ''
{
${cfg.globalConfig}
}
@ -34,10 +34,11 @@ let
'';
Caddyfile-formatted = pkgs.runCommand "Caddyfile-formatted" { nativeBuildInputs = [ cfg.package ]; } ''
${cfg.package}/bin/caddy fmt ${Caddyfile} > $out
mkdir -p $out
${cfg.package}/bin/caddy fmt ${Caddyfile}/Caddyfile > $out/Caddyfile
'';
in
if pkgs.stdenv.buildPlatform == pkgs.stdenv.hostPlatform then Caddyfile-formatted else Caddyfile;
"${if pkgs.stdenv.buildPlatform == pkgs.stdenv.hostPlatform then Caddyfile-formatted else Caddyfile}/Caddyfile";
acmeHosts = unique (catAttrs "useACMEHost" acmeVHosts);
@ -142,7 +143,7 @@ in
default = configFile;
defaultText = "A Caddyfile automatically generated by values from services.caddy.*";
example = literalExpression ''
pkgs.writeText "Caddyfile" '''
pkgs.writeTextDir "Caddyfile" '''
example.com
root * /var/www/wordpress
@ -157,15 +158,15 @@ in
};
adapter = mkOption {
default = "caddyfile";
default = null;
example = "nginx";
type = types.str;
description = lib.mdDoc ''
type = with types; nullOr str;
description = ''
Name of the config adapter to use.
See <https://caddyserver.com/docs/config-adapters>
for the full list.
If the empty string is specified, the <literal>--adapter</literal>
If <literal>null</literal> is specified, the <literal>--adapter</literal>
argument is omitted when starting or restarting Caddy. Notably, this
allows specification of a configuration file in Caddy's native JSON
format, as long as the filename does not start with
@ -175,8 +176,8 @@ in
for details.
<note><para>
Any value other than <literal>caddyfile</literal> is only valid when
providing your own <option>configFile</option>.
Any value other than <literal>null</literal> or <literal>caddyfile</literal>
is only valid when providing your own <option>configFile</option>.
</para></note>
'';
};
@ -273,8 +274,8 @@ in
config = mkIf cfg.enable {
assertions = [
{ assertion = cfg.adapter != "caddyfile" -> cfg.configFile != configFile;
message = "Any value other than 'caddyfile' is only valid when providing your own `services.caddy.configFile`";
{ assertion = cfg.configFile == configFile -> cfg.adapter == "caddyfile" || cfg.adapter == null;
message = "To specify an adapter other than 'caddyfile' please provide your own configuration via `services.caddy.configFile`";
}
] ++ map (name: mkCertOwnershipAssertion {
inherit (cfg) group user;
@ -304,9 +305,9 @@ in
serviceConfig = {
# https://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStart=
# If the empty string is assigned to this option, the list of commands to start is reset, prior assignments of this option will have no effect.
ExecStart = [ "" ''${cfg.package}/bin/caddy run --config ${cfg.configFile} ${optionalString (cfg.adapter != "") "--adapter ${cfg.adapter}"} ${optionalString cfg.resume "--resume"}'' ];
ExecReload = [ "" ''${cfg.package}/bin/caddy reload --config ${cfg.configFile} ${optionalString (cfg.adapter != "") "--adapter ${cfg.adapter}"} --force'' ];
ExecStartPre = ''${cfg.package}/bin/caddy validate --config ${cfg.configFile} ${optionalString (cfg.adapter != "") "--adapter ${cfg.adapter}"}'';
ExecStart = [ "" ''${cfg.package}/bin/caddy run --config ${cfg.configFile} ${optionalString (cfg.adapter != null) "--adapter ${cfg.adapter}"} ${optionalString cfg.resume "--resume"}'' ];
ExecReload = [ "" ''${cfg.package}/bin/caddy reload --config ${cfg.configFile} ${optionalString (cfg.adapter != null) "--adapter ${cfg.adapter}"} --force'' ];
ExecStartPre = ''${cfg.package}/bin/caddy validate --config ${cfg.configFile} ${optionalString (cfg.adapter != null) "--adapter ${cfg.adapter}"}'';
User = cfg.user;
Group = cfg.group;
ReadWriteDirectories = cfg.dataDir;