Skip to content

Commit

Permalink
Merge pull request #272617 from NixOS/backport-272542-to-release-23.11
Browse files Browse the repository at this point in the history
[Backport release-23.11] nixos/caddy: use caddyfile adapter by default with explicit configFile
  • Loading branch information
flokli authored Dec 10, 2023
2 parents 77b82f9 + 70c3cde commit 1a2090c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions nixos/modules/services/web-servers/caddy/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ in
default = configFile;
defaultText = "A Caddyfile automatically generated by values from services.caddy.*";
example = literalExpression ''
pkgs.writeTextDir "Caddyfile" '''
pkgs.writeText "Caddyfile" '''
example.com
root * /var/www/wordpress
Expand All @@ -171,9 +171,9 @@ in
};

adapter = mkOption {
default = if (builtins.baseNameOf cfg.configFile) == "Caddyfile" then "caddyfile" else null;
default = if ((cfg.configFile != configFile) || (builtins.baseNameOf cfg.configFile) == "Caddyfile") then "caddyfile" else null;
defaultText = literalExpression ''
if (builtins.baseNameOf cfg.configFile) == "Caddyfile" then "caddyfile" else null
if ((cfg.configFile != configFile) || (builtins.baseNameOf cfg.configFile) == "Caddyfile") then "caddyfile" else null
'';
example = literalExpression "nginx";
type = with types; nullOr str;
Expand Down
15 changes: 15 additions & 0 deletions nixos/tests/caddy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ import ./make-test-python.nix ({ pkgs, ... }: {
};
};
};
specialisation.explicit-config-file.configuration = {
services.caddy.configFile = pkgs.writeText "Caddyfile" ''
localhost:80
respond "hello world"
'';
};
};
};

testScript = { nodes, ... }:
let
explicitConfigFile = "${nodes.webserver.system.build.toplevel}/specialisation/explicit-config-file";
justReloadSystem = "${nodes.webserver.system.build.toplevel}/specialisation/config-reload";
multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs";
rfc42Config = "${nodes.webserver.system.build.toplevel}/specialisation/rfc42";
Expand Down Expand Up @@ -84,5 +92,12 @@ import ./make-test-python.nix ({ pkgs, ... }: {
)
webserver.wait_for_open_port(80)
webserver.succeed("curl http://localhost | grep hello")
with subtest("explicit configFile"):
webserver.succeed(
"${explicitConfigFile}/bin/switch-to-configuration test >&2"
)
webserver.wait_for_open_port(80)
webserver.succeed("curl http://localhost | grep hello")
'';
})

0 comments on commit 1a2090c

Please sign in to comment.