From 8567fac5050b10dda3ce192a1eb531fdc9994d95 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 24 Mar 2024 20:49:31 +0100 Subject: [PATCH] testers.lycheeLinkCheck: Add online attribute for nix run (cherry picked from commit c2ebd3ea6028c4f364638eec942fab24db8eaa04) --- doc/build-helpers/testers.chapter.md | 8 +++++++- pkgs/build-support/testers/lychee.nix | 14 +++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/build-helpers/testers.chapter.md b/doc/build-helpers/testers.chapter.md index 6b93531d8000..e664d12341d2 100644 --- a/doc/build-helpers/testers.chapter.md +++ b/doc/build-helpers/testers.chapter.md @@ -44,7 +44,13 @@ If the `moduleNames` argument is omitted, `hasPkgConfigModules` will use `meta.p Check that internal hyperlinks are correct, using the [`lychee` package](https://search.nixos.org/packages?show=lychee&type=packages&query=lychee). -Only an offline check is performed, so that network access is not required. +When building the check, only an offline check is performed, so that network access is not required. + +If you'd like to run the check with network access, the returned attribute `online` can be invoked with [`nix run`](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-run) ([experimental](https://nixos.org/manual/nix/stable/contributing/experimental-features#xp-feature-nix-command)). For example: + +```shell +nix run nixpkgs#lychee.tests.ok.online +``` :::{.example #ex-lycheelinkcheck} diff --git a/pkgs/build-support/testers/lychee.nix b/pkgs/build-support/testers/lychee.nix index 1aa7db1584f6..7de375c2f45c 100644 --- a/pkgs/build-support/testers/lychee.nix +++ b/pkgs/build-support/testers/lychee.nix @@ -1,4 +1,4 @@ -deps@{ formats, lib, lychee, stdenv }: +deps@{ formats, lib, lychee, stdenv, writeShellApplication }: let # See https://nixos.org/manual/nixpkgs/unstable/#tester-lycheeLinkCheck @@ -23,6 +23,18 @@ let } // lib.optionalAttrs (finalAttrs.passthru.remapUrl != null) { remap = [ "${remapUrl} file://${finalAttrs.site}" ]; } // extraConfig; + online = writeShellApplication { + name = "run-lychee-online"; + runtimeInputs = [ finalAttrs.passthru.lychee ]; + # Comment out to run shellcheck: + checkPhase = ""; + text = '' + site=${finalAttrs.site} + configFile=${finalAttrs.configFile} + echo Checking links on $site + exec lychee --config $configFile $site "$@" + ''; + }; }; buildCommand = '' echo Checking internal links on $site