at 25.11-pre 3.5 kB view raw
1# Generates the documentation for library functions via nixdoc. 2# To build this derivation, run `nix-build -A nixpkgs-manual.lib-docs` 3{ 4 lib, 5 stdenvNoCC, 6 nixdoc, 7 nix, 8 nixpkgs ? { }, 9 libsets ? [ 10 { 11 name = "asserts"; 12 description = "assertion functions"; 13 } 14 { 15 name = "attrsets"; 16 description = "attribute set functions"; 17 } 18 { 19 name = "strings"; 20 description = "string manipulation functions"; 21 } 22 { 23 name = "versions"; 24 description = "version string functions"; 25 } 26 { 27 name = "trivial"; 28 description = "miscellaneous functions"; 29 } 30 { 31 name = "fixedPoints"; 32 baseName = "fixed-points"; 33 description = "explicit recursion functions"; 34 } 35 { 36 name = "lists"; 37 description = "list manipulation functions"; 38 } 39 { 40 name = "debug"; 41 description = "debugging functions"; 42 } 43 { 44 name = "options"; 45 description = "NixOS / nixpkgs option handling"; 46 } 47 { 48 name = "path"; 49 description = "path functions"; 50 } 51 { 52 name = "fetchers"; 53 description = "functions which can be reused across fetchers"; 54 } 55 { 56 name = "filesystem"; 57 description = "filesystem functions"; 58 } 59 { 60 name = "fileset"; 61 description = "file set functions"; 62 } 63 { 64 name = "sources"; 65 description = "source filtering functions"; 66 } 67 { 68 name = "cli"; 69 description = "command-line serialization functions"; 70 } 71 { 72 name = "generators"; 73 description = "functions that create file formats from nix data structures"; 74 } 75 { 76 name = "gvariant"; 77 description = "GVariant formatted string serialization functions"; 78 } 79 { 80 name = "customisation"; 81 description = "Functions to customise (derivation-related) functions, derivations, or attribute sets"; 82 } 83 { 84 name = "meta"; 85 description = "functions for derivation metadata"; 86 } 87 { 88 name = "derivations"; 89 description = "miscellaneous derivation-specific functions"; 90 } 91 ], 92}: 93 94stdenvNoCC.mkDerivation { 95 name = "nixpkgs-lib-docs"; 96 97 src = ../../lib; 98 99 nativeBuildInputs = [ 100 nixdoc 101 nix 102 ]; 103 104 installPhase = '' 105 cd .. 106 107 export NIX_STATE_DIR=$(mktemp -d) 108 nix-instantiate --eval --strict --json ${./lib-function-locations.nix} \ 109 --arg nixpkgsPath "./." \ 110 --argstr revision ${nixpkgs.rev or "master"} \ 111 --argstr libsetsJSON ${lib.escapeShellArg (builtins.toJSON libsets)} \ 112 --store $(mktemp -d) \ 113 > locations.json 114 115 function docgen { 116 name=$1 117 baseName=$2 118 description=$3 119 # TODO: wrap lib.$name in <literal>, make nixdoc not escape it 120 if [[ -e "lib/$baseName.nix" ]]; then 121 nixdoc -c "$name" -d "lib.$name: $description" -l locations.json -f "lib/$baseName.nix" > "$out/$name.md" 122 else 123 nixdoc -c "$name" -d "lib.$name: $description" -l locations.json -f "lib/$baseName/default.nix" > "$out/$name.md" 124 fi 125 echo "$out/$name.md" >> "$out/index.md" 126 } 127 128 mkdir -p "$out" 129 130 cat > "$out/index.md" << 'EOF' 131 ```{=include=} sections auto-id-prefix=auto-generated 132 EOF 133 134 ${lib.concatMapStrings ( 135 { 136 name, 137 baseName ? name, 138 description, 139 }: 140 '' 141 docgen ${name} ${baseName} ${lib.escapeShellArg description} 142 '' 143 ) libsets} 144 145 echo '```' >> "$out/index.md" 146 ''; 147}