1 deps@{ formats, lib, lychee, stdenv, writeShellApplication }:
3 inherit (lib) mapAttrsToList throwIf;
4 inherit (lib.strings) hasInfix hasPrefix escapeNixString;
8 in if hasPrefix builtins.storeDir s
9 then # lychee requires that paths on the file system are prefixed with file://
13 withCheckedName = name:
14 throwIf (hasInfix " " name) ''
15 lycheeLinkCheck: remap patterns must not contain spaces.
16 A space marks the end of the regex in lychee.toml.
18 Please change attribute name 'remap.${escapeNixString name}'
21 # See https://nixos.org/manual/nixpkgs/unstable/#tester-lycheeLinkCheck
22 # or doc/build-helpers/testers.chapter.md
29 stdenv.mkDerivation (finalAttrs: {
30 name = "lychee-link-check";
32 nativeBuildInputs = [ finalAttrs.passthru.lychee ];
33 configFile = (formats.toml {}).generate "lychee.toml" finalAttrs.passthru.config;
35 # These can be overriden with overrideAttrs if needed.
39 include_fragments = true;
40 } // lib.optionalAttrs (finalAttrs.passthru.remap != { }) {
43 (name: value: withCheckedName name "${name} ${toURL value}")
44 finalAttrs.passthru.remap;
46 online = writeShellApplication {
47 name = "run-lychee-online";
48 runtimeInputs = [ finalAttrs.passthru.lychee ];
49 # Comment out to run shellcheck:
52 site=${finalAttrs.site}
53 configFile=${finalAttrs.configFile}
54 echo Checking links on $site
55 exec lychee --config $configFile $site "$@"
60 echo Checking internal links on $site
61 lychee --offline --config $configFile $site
68 inherit lycheeLinkCheck;