nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 81 lines 2.2 kB view raw
1deps@{ 2 formats, 3 lib, 4 lychee, 5 stdenv, 6 writeShellApplication, 7}: 8let 9 inherit (lib) mapAttrsToList throwIf; 10 inherit (lib.strings) hasInfix hasPrefix escapeNixString; 11 12 toURL = 13 v: 14 let 15 s = "${v}"; 16 in 17 if hasPrefix builtins.storeDir s then # lychee requires that paths on the file system are prefixed with file:// 18 "file://${s}" 19 else 20 s; 21 22 withCheckedName = 23 name: 24 throwIf (hasInfix " " name) '' 25 lycheeLinkCheck: remap patterns must not contain spaces. 26 A space marks the end of the regex in lychee.toml. 27 28 Please change attribute name 'remap.${escapeNixString name}' 29 ''; 30 31 # See https://nixos.org/manual/nixpkgs/unstable/#tester-lycheeLinkCheck 32 # or doc/build-helpers/testers.chapter.md 33 lycheeLinkCheck = 34 { 35 site, 36 remap ? { }, 37 lychee ? deps.lychee, 38 extraConfig ? { }, 39 }: 40 stdenv.mkDerivation (finalAttrs: { 41 name = "lychee-link-check"; 42 inherit site; 43 nativeBuildInputs = [ finalAttrs.passthru.lychee ]; 44 configFile = (formats.toml { }).generate "lychee.toml" finalAttrs.passthru.config; 45 46 # These can be overridden with overrideAttrs if needed. 47 passthru = { 48 inherit lychee remap; 49 config = { 50 include_fragments = true; 51 } 52 // lib.optionalAttrs (finalAttrs.passthru.remap != { }) { 53 remap = mapAttrsToList ( 54 name: value: withCheckedName name "${name} ${toURL value}" 55 ) finalAttrs.passthru.remap; 56 } 57 // extraConfig; 58 online = writeShellApplication { 59 name = "run-lychee-online"; 60 runtimeInputs = [ finalAttrs.passthru.lychee ]; 61 # Comment out to run shellcheck: 62 checkPhase = ""; 63 text = '' 64 site=${finalAttrs.site} 65 configFile=${finalAttrs.configFile} 66 echo Checking links on $site 67 exec lychee --config $configFile $site "$@" 68 ''; 69 }; 70 }; 71 buildCommand = '' 72 echo Checking internal links on $site 73 lychee --offline --config $configFile $site 74 touch $out 75 ''; 76 }); 77 78in 79{ 80 inherit lycheeLinkCheck; 81}