diff --git a/doc/build-helpers/testers.chapter.md b/doc/build-helpers/testers.chapter.md index a7741e96562b..632b11ab12ea 100644 --- a/doc/build-helpers/testers.chapter.md +++ b/doc/build-helpers/testers.chapter.md @@ -129,6 +129,13 @@ It has two modes: Example: `{ "include_verbatim" = true; }` +`extraArgs` (list of strings, optional) {#tester-lycheeLinkCheck-param-extraArgs} + +: Extra command line arguments to pass to the `lychee` invocation. + These are passed in both the offline (build) and [`online`](#tester-lycheeLinkCheck-return) modes. + + Example: `[ "--format" "json" ]` + `lychee` (derivation, optional) {#tester-lycheeLinkCheck-param-lychee} : The `lychee` package to use. diff --git a/pkgs/build-support/testers/lychee.nix b/pkgs/build-support/testers/lychee.nix index 1976b6eb959f..493ef3e880f9 100644 --- a/pkgs/build-support/testers/lychee.nix +++ b/pkgs/build-support/testers/lychee.nix @@ -37,6 +37,7 @@ let remap ? { }, lychee ? deps.lychee, extraConfig ? { }, + extraArgs ? [ ], }: stdenv.mkDerivation (finalAttrs: { name = "lychee-link-check"; @@ -47,6 +48,7 @@ let cacert ]; configFile = (formats.toml { }).generate "lychee.toml" finalAttrs.passthru.config; + inherit extraArgs; # These can be overridden with overrideAttrs if needed. passthru = { @@ -69,13 +71,13 @@ let site=${finalAttrs.site} configFile=${finalAttrs.configFile} echo Checking links on $site - exec lychee --config $configFile $site "$@" + exec lychee --config $configFile ${lib.escapeShellArgs extraArgs} $site "$@" ''; }; }; buildCommand = '' echo Checking internal links on $site - lychee --offline --config $configFile $site + lychee --offline --config $configFile "''${extraArgs[@]}" $site touch $out ''; }); diff --git a/pkgs/by-name/ly/lychee/tests/network.nix b/pkgs/by-name/ly/lychee/tests/network.nix index dcaebe7450d5..80345dc840e1 100644 --- a/pkgs/by-name/ly/lychee/tests/network.nix +++ b/pkgs/by-name/ly/lychee/tests/network.nix @@ -14,10 +14,21 @@ let check = config.node.pkgs.testers.lycheeLinkCheck { site = sitePkg; }; + checkJson = config.node.pkgs.testers.lycheeLinkCheck { + site = sitePkg; + extraArgs = [ + "--format" + "json" + ]; + }; in { name = "testers-lychee-link-check-run"; - nodes.client = { ... }: { }; + nodes.client = + { pkgs, ... }: + { + environment.systemPackages = [ pkgs.jq ]; + }; nodes.example = { networking.firewall.allowedTCPPorts = [ 80 ]; services.nginx = { @@ -67,5 +78,13 @@ in client.succeed(""" ${lib.getExe check.online} """) + + # EXTRA ARGS CASE: verify extraArgs are passed through to online wrapper + + with subtest("extraArgs are passed to the online wrapper"): + client.succeed(""" + ${lib.getExe checkJson.online} --output /tmp/lychee.json + jq -e .total /tmp/lychee.json + """) ''; }