From 3b6df044821946df7fc1d202a171a18d867f30d8 Mon Sep 17 00:00:00 2001 From: Yifei Sun Date: Wed, 27 May 2026 16:00:20 +0200 Subject: [PATCH 1/3] nixos/tests/caddy: drop `withPlugins` test path --- nixos/tests/caddy.nix | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/nixos/tests/caddy.nix b/nixos/tests/caddy.nix index c719a1b233b1..d7f2b72ef6de 100644 --- a/nixos/tests/caddy.nix +++ b/nixos/tests/caddy.nix @@ -1,11 +1,11 @@ -{ pkgs, ... }: +{ lib, ... }: + { name = "caddy"; - meta = with pkgs.lib.maintainers; { - maintainers = [ - stepbrobd - ]; - }; + + meta.maintainers = with lib.maintainers; [ + stepbrobd + ]; nodes = { webserver = @@ -69,24 +69,6 @@ respond "hello world" ''; }; - specialisation.with-plugins.configuration = { - services.caddy = { - package = pkgs.caddy.withPlugins { - plugins = [ "github.com/caddyserver/replace-response@v0.0.0-20250618171559-80962887e4c6" ]; - hash = "sha256-0N/bQAM5yT6g9UAteWsfxofGcelmU/NDTroS2oL43Gs="; - }; - configFile = pkgs.writeText "Caddyfile" '' - { - order replace after encode - } - - localhost:80 { - respond "hello world" - replace world caddy - } - ''; - }; - }; }; }; @@ -98,7 +80,6 @@ multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs"; multipleHostnames = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-hostnames"; rfc42Config = "${nodes.webserver.system.build.toplevel}/specialisation/rfc42"; - withPluginsConfig = "${nodes.webserver.system.build.toplevel}/specialisation/with-plugins"; in '' url = "http://localhost/example.html" @@ -141,12 +122,5 @@ ) webserver.wait_for_open_port(80) webserver.succeed("curl http://localhost | grep hello") - - with subtest("plugins are correctled installed and configurable"): - webserver.succeed( - "${withPluginsConfig}/bin/switch-to-configuration test >&2" - ) - webserver.wait_for_open_port(80) - webserver.succeed("curl http://localhost | grep caddy") ''; } From dc8e7f0fed23e34e8779ecb52c345685ac3cfcc8 Mon Sep 17 00:00:00 2001 From: Yifei Sun Date: Fri, 3 Jul 2026 14:35:22 +0200 Subject: [PATCH 2/3] caddy: move `dist` to passthru and cleanup --- pkgs/by-name/ca/caddy/package.nix | 42 ++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/pkgs/by-name/ca/caddy/package.nix b/pkgs/by-name/ca/caddy/package.nix index 029ace9f9d28..01b098dfd59a 100644 --- a/pkgs/by-name/ca/caddy/package.nix +++ b/pkgs/by-name/ca/caddy/package.nix @@ -10,18 +10,12 @@ writableTmpDirAsHomeHook, versionCheckHook, }: -let - version = "2.11.4"; - dist = fetchFromGitHub { - owner = "caddyserver"; - repo = "dist"; - tag = "v${version}"; - hash = "sha256-oRQfQH1GKjAjVMj+dZo1f1+HOaOdJIyEfod0iGLYcc8="; - }; -in + buildGoModule (finalAttrs: { pname = "caddy"; - inherit version; + version = "2.11.4"; + + __structuredAttrs = true; src = fetchFromGitHub { owner = "caddyserver"; @@ -52,7 +46,7 @@ buildGoModule (finalAttrs: { __darwinAllowLocalNetworking = true; postInstall = '' - install -Dm644 ${dist}/init/caddy.service ${dist}/init/caddy-api.service -t $out/lib/systemd/system + install -Dm644 ${finalAttrs.passthru.dist}/init/caddy.service ${finalAttrs.passthru.dist}/init/caddy-api.service -t $out/lib/systemd/system substituteInPlace $out/lib/systemd/system/caddy.service \ --replace-fail "/usr/bin/caddy" "$out/bin/caddy" @@ -72,20 +66,28 @@ buildGoModule (finalAttrs: { --zsh <($out/bin/caddy completion zsh) ''; - passthru = { - tests = { - inherit (nixosTests) caddy; - acme-integration = nixosTests.acme.caddy; - }; - withPlugins = callPackage ./plugins.nix { inherit caddy; }; - }; - + doInstallCheck = true; nativeInstallCheckInputs = [ writableTmpDirAsHomeHook versionCheckHook ]; versionCheckKeepEnvironment = [ "HOME" ]; - doInstallCheck = true; + + passthru = { + withPlugins = callPackage ./plugins.nix { inherit caddy; }; + + dist = fetchFromGitHub { + owner = "caddyserver"; + repo = "dist"; + tag = "v${finalAttrs.version}"; + hash = "sha256-oRQfQH1GKjAjVMj+dZo1f1+HOaOdJIyEfod0iGLYcc8="; + }; + + tests = { + inherit (nixosTests) caddy; + acme-integration = nixosTests.acme.caddy; + }; + }; meta = { homepage = "https://caddyserver.com"; From c35ba24ba1b35e211edf4bdc920f3ae4b0a5a550 Mon Sep 17 00:00:00 2001 From: Yifei Sun Date: Fri, 3 Jul 2026 14:44:59 +0200 Subject: [PATCH 3/3] caddy: init `caddy.withPlugins` passthru test --- pkgs/by-name/ca/caddy/package.nix | 3 +++ pkgs/by-name/ca/caddy/plugins.test.nix | 36 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 pkgs/by-name/ca/caddy/plugins.test.nix diff --git a/pkgs/by-name/ca/caddy/package.nix b/pkgs/by-name/ca/caddy/package.nix index 01b098dfd59a..0f544a4b22e9 100644 --- a/pkgs/by-name/ca/caddy/package.nix +++ b/pkgs/by-name/ca/caddy/package.nix @@ -3,6 +3,7 @@ buildGoModule, callPackage, fetchFromGitHub, + testers, nixosTests, caddy, installShellFiles, @@ -21,6 +22,7 @@ buildGoModule (finalAttrs: { owner = "caddyserver"; repo = "caddy"; tag = "v${finalAttrs.version}"; + # remember to update hashes for `dist` and `plugins` test! hash = "sha256-wzk8KRZfDCbbjRlBwkoKAoMjOhV4xF3yuXUueqtl1xM="; }; @@ -85,6 +87,7 @@ buildGoModule (finalAttrs: { tests = { inherit (nixosTests) caddy; + plugins = testers.runNixOSTest ./plugins.test.nix; acme-integration = nixosTests.acme.caddy; }; }; diff --git a/pkgs/by-name/ca/caddy/plugins.test.nix b/pkgs/by-name/ca/caddy/plugins.test.nix new file mode 100644 index 000000000000..7c223c860436 --- /dev/null +++ b/pkgs/by-name/ca/caddy/plugins.test.nix @@ -0,0 +1,36 @@ +{ lib, ... }: + +{ + name = "caddy-plugins"; + meta.maintainers = with lib.maintainers; [ + stepbrobd + ]; + + nodes.machine = + { pkgs, ... }: + { + services.caddy = { + enable = true; + + package = pkgs.caddy.withPlugins { + plugins = [ "github.com/caddyserver/replace-response@v0.0.0-20250618171559-80962887e4c6" ]; + hash = "sha256-oj0IpspxslpNZbJFsexh0W2Sja19XRUsbShoCuY6qkQ="; + }; + + globalConfig = '' + order replace after encode + ''; + + virtualHosts."localhost:80".extraConfig = '' + respond "hello world" + replace world nixos + ''; + }; + }; + + testScript = '' + machine.wait_for_unit("caddy") + machine.wait_for_open_port(80) + machine.succeed("curl http://localhost | grep nixos") + ''; +}